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

sqlite3 cursor.description varies across Linux (3.3.1), Win32 (3.3.2), when selecting from a view. #63366

Closed
mpb mannequin opened this issue Oct 4, 2013 · 8 comments
Closed
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@mpb
Copy link
Mannequin

mpb mannequin commented Oct 4, 2013

BPO 19167
Nosy @bitdancer, @zware, @kushaldas, @vajrasky

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:

assignee = None
closed_at = <Date 2013-12-14.16:50:47.459>
created_at = <Date 2013-10-04.20:53:03.512>
labels = ['type-bug', 'library']
title = 'sqlite3 cursor.description varies across Linux (3.3.1), Win32 (3.3.2), when selecting from a view.'
updated_at = <Date 2013-12-15.17:16:11.945>
user = 'https://bugs.python.org/mpb'

bugs.python.org fields:

activity = <Date 2013-12-15.17:16:11.945>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2013-12-14.16:50:47.459>
closer = 'r.david.murray'
components = ['Library (Lib)']
creation = <Date 2013-10-04.20:53:03.512>
creator = 'mpb'
dependencies = []
files = []
hgrepos = []
issue_num = 19167
keywords = []
message_count = 8.0
messages = ['198964', '199215', '199224', '199236', '206187', '206193', '206231', '206243']
nosy_count = 5.0
nosy_names = ['r.david.murray', 'zach.ware', 'kushal.das', 'vajrasky', 'mpb']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue19167'
versions = ['Python 3.3']

@mpb
Copy link
Mannequin Author

mpb mannequin commented Oct 4, 2013

On Win32, when I select from an SQLite view, and enclose the column name in double quotes in the select query, the cursor description (erroneously?) contains the double quotes.

On Linux (or on Win32 when selecting from a table rather than a view) the cursor description does not contain the double quotes. I expect the Linux behavior, not the Win32 behavior.

The following code demonstrates the problem.
----

import sqlite3, sys

print (sys.platform)
print (sys.version)

conn = sqlite3.connect (':memory:')
cur  = conn.cursor ()

cur.execute ('create table Foo ( foo_id integer primary key ) ;')
cur.execute ('create view Foo_View as select * from Foo ;')

cur.execute ('select foo_id from Foo;')
print (cur.description[0][0])
cur.execute ('select "foo_id" from Foo;')
print (cur.description[0][0])
cur.execute ('select foo_id from Foo_View;')
print (cur.description[0][0])
cur.execute ('select "foo_id" from Foo_View;')
print (cur.description[0][0])
----

Sample output on Linux and Win32.
----
linux
3.3.1 (default, Apr 17 2013, 22:32:14)
[GCC 4.7.3]
foo_id
foo_id
foo_id
foo_id
----
win32
3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)]
foo_id
foo_id
foo_id
"foo_id"
----

Above, please note the (erroneous?) double quotes around the final foo_id.

@mpb mpb mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 4, 2013
@bitdancer
Copy link
Member

There is a decent chance this is a bug in sqlite. Have you checked?

@kushaldas
Copy link
Member

Looking at the code, it seems to be a sqlite issue.

@mpb
Copy link
Mannequin Author

mpb mannequin commented Oct 8, 2013

No, I have not checked to see if it is a bug in the Windows version of SQLite.

How would I even test that?

I just tried running the command line version of SQLite (version 3.8.0.2 2013-09-03) on Windows (XP SP2, in VirtualBox).

I manually ran the same statements from the Python script. I turned on headers (.headers ON). The headers did not contain the quotes around foo_id.

That's probably all the testing I can do easily, unless there is some other way to access the cursor description. I don't have a C development environment installed on Windows, nor have I ever written C code that calls SQLite.

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Dec 14, 2013

This is a bug from Sqlite. Sqlite 3.7 is afflicted. Solution: upgrade to sqlite 3.8.

http://sqlite.1065341.n5.nabble.com/sqlite3-column-name-contains-quotes-for-views-td65226.html
http://www.sqlite.org/src/info/5526e0aa3c

@bitdancer
Copy link
Member

Thanks for the confirmation, Vajrasky. It is apparently not hard to upgrade the sqlite3 that python uses even on Windows, so I'm going to close this issue. (We're currently up to sqlite3 3.8.1 on 3.4).

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Dec 15, 2013

Upgrading sqlite3 in Windows maybe easy but Python 2.7.6 and 3.3.3 on Windows were built with defected sqlite3. Maybe at least we can provide the correct sqlite3 version next time we release Windows version of Python 2.7 and 3.3? Python 3.3 comes with sqlite3 3.7.12. Python 2.7.6 comes with sqlite3 3.6.12.

Python 3.4 is not afflicted. It comes with sqlite3 3.8.1.

@bitdancer
Copy link
Member

That sqlite checkin is well before 3.7.12 was released, and 3.3.3 shipped with that version. Was the bug present in 3.6? If so I don't think we can do anything, since I believe we stay with the same minor version (ie: 3.6) of sqlite for the life of a minor version of Python (ie: 2.7).

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants