Skip to content

Commit 43ca03d

Browse files
author
Erlend E. Aasland
committed
Revert "bpo-44041: Only call sqlite3_column_count() if needed"
This reverts commit f961c3f.
1 parent ef94c62 commit 43ca03d

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

Modules/_sqlite/cursor.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ pysqlite_build_row_cast_map(pysqlite_Cursor* self)
167167
return -1;
168168
}
169169

170-
int column_count = self->statement->column_count;
171-
for (i = 0; i < column_count; i++) {
170+
for (i = 0; i < sqlite3_column_count(self->statement->st); i++) {
172171
converter = NULL;
173172

174173
if (self->connection->detect_types & PARSE_COLNAMES) {
@@ -560,7 +559,9 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
560559
}
561560

562561
assert(rc == SQLITE_ROW || rc == SQLITE_DONE);
563-
numcols = self->statement->column_count;
562+
Py_BEGIN_ALLOW_THREADS
563+
numcols = sqlite3_column_count(self->statement->st);
564+
Py_END_ALLOW_THREADS
564565
if (self->description == Py_None && numcols > 0) {
565566
Py_SETREF(self->description, PyTuple_New(numcols));
566567
if (!self->description) {

Modules/_sqlite/statement.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
8989
self->sql = Py_NewRef(sql);
9090
self->in_use = 0;
9191
self->is_dml = 0;
92-
self->column_count = 0;
9392
self->in_weakreflist = NULL;
9493

9594
/* Determine if the statement is a DML statement.
@@ -133,13 +132,6 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
133132
goto error;
134133
}
135134

136-
/* Set column count just before returning, to minimise SQLite API calls */
137-
if (!self->is_dml) {
138-
Py_BEGIN_ALLOW_THREADS
139-
self->column_count = sqlite3_column_count(self->st);
140-
Py_END_ALLOW_THREADS
141-
}
142-
143135
return self;
144136

145137
error:

Modules/_sqlite/statement.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef struct
3737
PyObject* sql;
3838
int in_use;
3939
int is_dml;
40-
int column_count;
4140
PyObject* in_weakreflist; /* List of weak references */
4241
} pysqlite_Statement;
4342

0 commit comments

Comments
 (0)