classification
Title: sqlite3 Cursor.description can't return column types
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: sqlite3 Cursor.description doesn't set type_code
View: 11691
Assigned To: Nosy List: ZackerySpytz, berker.peksag, ghaering, kyoshidajp, lemburg
Priority: normal Keywords:

Created on 2017-11-20 13:08 by kyoshidajp, last changed 2018-07-26 14:25 by berker.peksag. This issue is now closed.

Messages (4)
msg306539 - (view) Author: Katsuhiko YOSHIDA (kyoshidajp) * Date: 2017-11-20 13:08
My schema of sqlite3 table is the following.

--- schema check start ---
% sqlite3 sample.db
SQLite version 3.16.0 2016-11-04 19:09:39
Enter ".help" for usage hints.
sqlite> PRAGMA table_info(Employees);
0|EmployeeID|int|1||1
1|LastName|varchar(20)|1||0
2|FirstName|varchar(10)|1||0

(ommiting)

sqlite>
--- schema check end ---

Then, I tried to output column types by calling Cursor.description. Like this.

--- sample code start ---
import sqlite3

con = sqlite3.connect("sample.db", detect_types=sqlite3.PARSE_DECLTYPES)
cursor = con.cursor()
cursor.execute("select LastName, FirstName from Employees limit 1;")
print cursor.description
cursor.close()
con.close()
--- sample code end ---

The output is the following.

(('LastName', None, None, None, None, None, None), ('FirstName', None, None, None, None, None, None))

When changing detect_types parameter to

detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES

the result is same.

I expect to output a column type in second element. Could you tell me why?
msg306541 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-11-20 13:55
Thank you for your report. According to https://github.com/python/cpython/blob/04dee2720851ec39e831beaa3edc0c59f228f461/Modules/_sqlite/cursor.c#L573 we always set the 'type_code' field described in PEP 249 to None. Setting it would be a new feature so it can only go into Python 3.7.
msg322421 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2018-07-26 13:35
This seems to be a duplicate of #11691.
msg322432 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-07-26 14:25
Good catch, Zackery, thanks! This is indeed a duplicate of issue 11691.
History
Date User Action Args
2018-07-26 14:25:51berker.peksagsetstatus: open -> closed
superseder: sqlite3 Cursor.description doesn't set type_code
messages: + msg322432

resolution: duplicate
stage: needs patch -> resolved
2018-07-26 13:35:28ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg322421
2017-11-20 13:55:03berker.peksagsetversions: + Python 3.7, - Python 2.7, Python 3.6
nosy: + ghaering, berker.peksag, lemburg

messages: + msg306541

type: behavior -> enhancement
stage: needs patch
2017-11-20 13:08:43kyoshidajpcreate