diff -r fe72160ea2a3 Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst Sat Mar 26 19:59:02 2011 +0100 +++ b/Doc/library/sqlite3.rst Sat Mar 26 22:52:15 2011 -0500 @@ -565,11 +565,15 @@ .. attribute:: Cursor.description - This read-only attribute provides the column names of the last query. To - remain compatible with the Python DB API, it returns a 7-tuple for each - column where the last six items of each tuple are :const:`None`. + This read-only attribute provides the column names and types of the last query. + To remain compatible with the Python DB API, it returns a 7-tuple for each + column where the last 6 items of each tuple are :const:`None`. - It is set for ``SELECT`` statements without any matching rows as well. + Column name and type is set for ``SELECT`` statements without any matching rows + as well. + + Column type will return ``SQLITE_NULL``, type code 5, for all the columns if the + table is empty. .. _sqlite3-row-objects: diff -r fe72160ea2a3 Lib/sqlite3/dbapi2.py --- a/Lib/sqlite3/dbapi2.py Sat Mar 26 19:59:02 2011 +0100 +++ b/Lib/sqlite3/dbapi2.py Sat Mar 26 22:52:15 2011 -0500 @@ -52,6 +52,22 @@ Binary = buffer +class _DBTypeSet(): + def __init__(self, type_codes): + self._codes = type_codes + + def __eq__(self, other): + return other in self._codes + + def __ne__(self, other): + return other not in self._codes + +STRING = _DBTypeSet([SQLITE3_TEXT,]) +BINARY = _DBTypeSet([SQLITE_BLOB,]) +NUMBER = _DBTypeSet([SQLITE_INTEGER, SQLITE_FLOAT,]) +DATETIME = _DBTypeSet([]) +ROWID = _DBTypeSet([]) + def register_adapters_and_converters(): def adapt_date(val): return val.isoformat() diff -r fe72160ea2a3 Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c Sat Mar 26 19:59:02 2011 +0100 +++ b/Modules/_sqlite/cursor.c Sat Mar 26 22:52:15 2011 -0500 @@ -268,6 +268,11 @@ } } +PyObject* _pysqlite_build_column_type(int coltype) +{ + return PyInt_FromLong((long)coltype); +} + PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize) { const char* check; @@ -703,7 +708,7 @@ goto error; } PyTuple_SetItem(descriptor, 0, _pysqlite_build_column_name(sqlite3_column_name(self->statement->st, i))); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None); + PyTuple_SetItem(descriptor, 1, _pysqlite_build_column_type(sqlite3_column_type(self->statement->st, i))); Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None); Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None); Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None); diff -r fe72160ea2a3 Modules/_sqlite/module.c --- a/Modules/_sqlite/module.c Sat Mar 26 19:59:02 2011 +0100 +++ b/Modules/_sqlite/module.c Sat Mar 26 22:52:15 2011 -0500 @@ -262,6 +262,12 @@ {"PARSE_DECLTYPES", PARSE_DECLTYPES}, {"PARSE_COLNAMES", PARSE_COLNAMES}, + {"SQLITE_INTEGER", SQLITE_INTEGER}, + {"SQLITE_FLOAT", SQLITE_FLOAT}, + {"SQLITE_BLOB", SQLITE_BLOB}, + {"SQLITE_NULL", SQLITE_NULL}, + {"SQLITE3_TEXT", SQLITE3_TEXT}, + {"SQLITE_OK", SQLITE_OK}, {"SQLITE_DENY", SQLITE_DENY}, {"SQLITE_IGNORE", SQLITE_IGNORE},