Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 string problem in user defined functions #208

Closed
pdalloz opened this issue Mar 23, 2016 · 3 comments
Closed

Python 3 string problem in user defined functions #208

pdalloz opened this issue Mar 23, 2016 · 3 comments

Comments

@pdalloz
Copy link

pdalloz commented Mar 23, 2016

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

@pdalloz
Copy link
Author

pdalloz commented Mar 23, 2016

Oops not 'virtual functions' .. should be 'user defined functions'

@rogerbinns rogerbinns changed the title Python 3 string problem in virtual functions Python 3 string problem in user defined functions Mar 23, 2016
@rogerbinns
Copy link
Owner

I can repeat this on Linux too. It doesn't happen with python 2.7 but does with 3.4. Investigating.

@rogerbinns
Copy link
Owner

I have found the root cause, and it does fix this. I need to do complete testing first to verify the completeness of the fix. It is to do with PyUnicode_READY and you can read more in #132 and #168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants