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 <rep...@bugs.python.org> <http://bugs.python.org/issue21718> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com