Skip to content

bpo-39652: returning entire sqlite column names #18533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doc/includes/sqlite3/pysqlite_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
row = cur.fetchone()
print("current_date", row[0], type(row[0]))
print("current_timestamp", row[1], type(row[1]))
print(cur.description)

con.close()
2 changes: 1 addition & 1 deletion Lib/sqlite3/test/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def CheckStatementReset(self):
def CheckColumnNameWithSpaces(self):
cur = self.con.cursor()
cur.execute('select 1 as "foo bar [datetime]"')
self.assertEqual(cur.description[0][0], "foo bar")
self.assertEqual(cur.description[0][0], "foo bar [datetime]")

cur.execute('select 1 as "foo baz"')
self.assertEqual(cur.description[0][0], "foo baz")
Expand Down
2 changes: 1 addition & 1 deletion Lib/sqlite3/test/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def CheckColName(self):

# Check if the stripping of colnames works. Everything after the first
# whitespace should be stripped.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is now outdated 🙂

self.assertEqual(self.cur.description[0][0], "x")
self.assertEqual(self.cur.description[0][0], "x [bar]")

def CheckCaseInConverterName(self):
self.cur.execute("select 'other' as \"x [b1b1]\"")
Expand Down
5 changes: 1 addition & 4 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ _pysqlite_build_column_name(const char* colname)
}

for (pos = colname;; pos++) {
if (*pos == 0 || *pos == '[') {
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
pos--;
}
if (*pos == '\0') {
return PyUnicode_FromStringAndSize(colname, pos - colname);
}
}
Expand Down