Sqlite3 and cursor.description

When using the sqlite3 module in python, all cursor.description elements except column names are None, so this tuple cannot be used to search for column types for the query result (unlike other modules compatible with DB-API), the only way to get column types to use pragma table_info(table_name).fetchall()to get a description of a table, store it in memory, and then map the column names to cursor.description with this general table description?

+5
source share
2 answers

No, this is not the only way. Alternatively, you can also get a single row, iterate over it, and check individual Python column objects and types. If the value is not None (in this case, the SQL field is NULL), this should give you a fairly accurate idea of ​​the type of database column.

sqlite3 uses only sqlite3_column_decltypeand sqlite3_column_typein one place, each, and none of them are available for a Python application, so they are not the "direct" way that you may have been looking for.

+5
source

I have not tried this in Python, but you could try something like

SELECT *
FROM sqlite_master
WHERE type = 'table';

DDL CREATE, . DDL, , . , SQLITE , .

+1

All Articles