The following code returns 0 for print(s.count(item)) until the print(s) statement is executed, and then it returns the correct value for print(s.count(item))
import apsw
connection=apsw.Connection("dbfile")
cursor = connection.cursor()
def TESTCOUNT(s, item):
print(s.count(item))
print(s)
print(s.count(item))
return 'Done'
connection.createscalarfunction("TESTCOUNT", TESTCOUNT)
for row in cursor.execute("select TESTCOUNT('abcdb','b')"):
print(row)
OUTPUT:
This is windows 7, APSW 3.11.1-r1