Skip to content

Python 3 string problem in user defined functions #208

@pdalloz

Description

@pdalloz

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:

0
abcdb
2
('Done',)

This is windows 7, APSW 3.11.1-r1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions