[New-bugs-announce] [issue21718] sqlite3 cursor.description seems to rely on incomplete statement parsing for detection

mike bayer report at bugs.python.org
Wed Jun 11 15:11:09 CEST 2014


New submission from mike bayer:

Per DBAPI and pysqlite docs, .description must be available for any SELECT statement regardless of whether or not rows are returned.  However, this fails for SELECT statements that aren't simple "SELECT"s, such as those that use CTEs and therefore start out with "WITH:":

import sqlite3
conn = sqlite3.connect(":memory:")

cursor = conn.cursor()
cursor.execute("""
    create table foo (id integer primary key, data varchar(20))
""")

cursor.execute("""
    insert into foo (id, data) values (10, 'ten')
""")

cursor.execute("""
    with bar as (select * from foo)
    select * from bar where id = 10
""")

assert cursor.description is not None


cursor.execute("""
    with bar as (select * from foo)
    select * from bar where id = 11
""")

assert cursor.description is not None


the second statement returns no rows and cursor.description is None.   Libraries like SQLAlchemy which rely on this to determine that the statement supports fetchone() and similar are blocked.

----------
components: Library (Lib)
messages: 220263
nosy: zzzeek
priority: normal
severity: normal
status: open
title: sqlite3 cursor.description seems to rely on incomplete statement parsing for detection
type: behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21718>
_______________________________________


More information about the New-bugs-announce mailing list