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

wrong detection of IncompleteExecutionError in fetchone() #376

Closed
hofmandl1 opened this issue Oct 18, 2022 · 3 comments
Closed

wrong detection of IncompleteExecutionError in fetchone() #376

hofmandl1 opened this issue Oct 18, 2022 · 3 comments
Assignees

Comments

@hofmandl1
Copy link

hofmandl1 commented Oct 18, 2022

the following snippet demonstrates a bug that we did not experience with 3.36.0 but started to experience when upgrading to 3.39.4.0 (3.39.3.0 is also affected, but I guess this is not very relevant):

import apsw

connection = apsw.Connection(":memory:")
cursor = connection.cursor()
cursor.execute('SELECT 1;\n').fetchone()
cursor.execute('SELECT 2;').fetchone()

Error is

Traceback (most recent call last):
  File "C:\Users\hofmandl\apsw_bug.py", line 6, in <module>
    cursor.execute('SELECT 2;').fetchone()
  File "apsw\src\cursor.c", line 229, in resetcursor
    AddTraceBackHere(__FILE__, __LINE__, "resetcursor", "{s: i}", "res", res);
apsw.IncompleteExecutionError: Error: there are still remaining sql statements to execute

Changing either the first fetchone to fetchall or removing the newline character at the end of the statement or removing the semicolon makes the exception go away.

Note that this may be easier to produce than one might think. In our case we also didn't use the newline literal, but had a multiline-string:

cursor.execute('''
      SELECT A, B, C
           FROM FOO
      WHERE BAR = 1;
''').fetchone()
@rogerbinns rogerbinns self-assigned this Oct 18, 2022
@rogerbinns
Copy link
Owner

Thank you for finding and reporting this. The root cause was that the statement cache was significantly simplified (a quarter of the code) in 3.38.1-r1. However I missed that the previous implementation scanned and ignored whitespace after the end of a regular query, which is why it now falls over that same whitespace.

rogerbinns added a commit that referenced this issue Oct 19, 2022
That fixes makes whitespace belong to end of previous query not
beginning of next
@rogerbinns
Copy link
Owner

This is now tested and fixed in git and will be part of the next release. Thanks for helping make APSW better!

@hofmandl1
Copy link
Author

Thanks for making APSW in the first place!

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