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
sqlite3 module gives SQL logic error only in transactions #49245
Comments
when I use transactions I got errors I won't get with sqlite3 cli [alsadi@pc1 ~]$ python
Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> cn=sqlite3.connect(':memory:')
>>> c=cn.cursor()
>>> c.execute('BEGIN TRANSACTION')
<sqlite3.Cursor object at 0xb7efada0>
>>> c.execute('create temp table tmp_main (id integer, b text)')
<sqlite3.Cursor object at 0xb7efada0>
>>> c.execute('insert into tmp_main (id) values (10);')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.OperationalError: SQL logic error or missing database
>>> [alsadi@pc1 ~]$ sqlite3 ':memory:' and if the transaction line removed I get no error [alsadi@pc1 ~]$ python
Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> cn=sqlite3.connect(':memory:')
>>> c=cn.cursor()
>>> c.execute('create temp table tmp_main (id integer, b text)')
<sqlite3.Cursor object at 0xb7ff6da0>
>>> c.execute('insert into tmp_main (id) values (10);')
<sqlite3.Cursor object at 0xb7ff6da0>
>>> |
What if you commit before the insert? |
same thing [alsadi@pc1 ~]$ python
Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> cn=sqlite3.connect(':memory:')
>>> c=cn.cursor()
>>> c.execute('BEGIN TRANSACTION')
<sqlite3.Cursor object at 0xb7f99da0>
>>> c.execute('create temp table tmp_main (id integer, b text)')
<sqlite3.Cursor object at 0xb7f99da0>
>>> cn.commit()
>>> c.execute('insert into tmp_main (id) values (10);')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.OperationalError: SQL logic error or missing database
>>> to make it easy for you to try it yourself import sqlite3
cn=sqlite3.connect(':memory:')
c=cn.cursor()
c.execute('BEGIN TRANSACTION')
c.execute('create temp table tmp_main (id integer, b text)')
cn.commit() # this was added on your request
c.execute('insert into tmp_main (id) values (10);') |
Ok, I've just tried. While it fails in Python 2.5.2, it works in 2.6.1 |
can you please tell me how to detect the version so that my application which of these values should I use that are different in your python 2.6 |
Well I'm no sqlite expert, but here are the values I get on the 2.6 branch: >>> sqlite3.apilevel
'2.0'
>>> sqlite3.sqlite_version
'3.6.1'
>>> sqlite3.sqlite_version_info
(3, 6, 1)
>>> sqlite3.version
'2.4.1'
>>> sqlite3.version_info
(2, 4, 1) |
a fedora-devel fellow gave me a solution cn=sqlite3.connect(':memory:', isolation_level=None) and it worked $ python
Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> cn=sqlite3.connect(':memory:', isolation_level=None)
>>> c=cn.cursor()
>>> c.execute('BEGIN TRANSACTION')
<sqlite3.Cursor object at 0x9cb9c20>
>>> c.execute('create temp table tmp_main (id integer, b text)')
<sqlite3.Cursor object at 0x9cb9c20>
>>> c.execute('insert into tmp_main (id) values (10);')
<sqlite3.Cursor object at 0x9cb9c20>
>>> c.execute('END TRANSACTION')
<sqlite3.Cursor object at 0x9cb9c20>
>>> |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: