Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit f3d452f

Browse files
author
gh
committed
Make sure column names with spaces in them end up in cursor.description.
1 parent 0edd820 commit f3d452f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pysqlite2/test/regression.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def CheckStatementReset(self):
6161

6262
con.rollback()
6363

64+
def CheckColumnNameWithSpaces(self):
65+
cur = self.con.cursor()
66+
cur.execute('select 1 as "foo bar [datetime]"')
67+
self.failUnlessEqual(cur.description[0][0], "foo bar")
68+
69+
cur.execute('select 1 as "foo baz"')
70+
self.failUnlessEqual(cur.description[0][0], "foo baz")
71+
6472
def suite():
6573
regression_suite = unittest.makeSuite(RegressionTests, "Check")
6674
return unittest.TestSuite((regression_suite,))

src/cursor.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ PyObject* _build_column_name(const char* colname)
224224
}
225225

226226
for (pos = colname;; pos++) {
227-
if (*pos == 0 || *pos == ' ') {
227+
if (*pos == 0 || *pos == '[') {
228+
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
229+
pos--;
230+
}
228231
return PyString_FromStringAndSize(colname, pos - colname);
229232
}
230233
}

0 commit comments

Comments
 (0)