Skip to content

Commit a0026e3

Browse files
committed
split implementation of execute() and executemany()
1 parent d1bb010 commit a0026e3

File tree

2 files changed

+410
-270
lines changed

2 files changed

+410
-270
lines changed

Modules/_sqlite/connection.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ static void free_callback_context(callback_context *ctx);
149149
static void set_callback_context(callback_context **ctx_pp,
150150
callback_context *ctx);
151151
static int connection_close(pysqlite_Connection *self);
152-
PyObject *_pysqlite_query_execute(pysqlite_Cursor *, int, PyObject *, PyObject *);
152+
153+
extern int _pysqlite_query_execute(pysqlite_Cursor *, PyObject *, PyObject *);
154+
extern int _pysqlite_query_executemany(pysqlite_Cursor *, PyObject *, PyObject *);
153155

154156
static PyObject *
155157
new_statement_cache(pysqlite_Connection *self, pysqlite_state *state,
@@ -1853,21 +1855,15 @@ pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
18531855
PyObject *parameters)
18541856
/*[clinic end generated code: output=5be05ae01ee17ee4 input=27aa7792681ddba2]*/
18551857
{
1856-
PyObject* result = 0;
1857-
18581858
PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
1859-
if (!cursor) {
1860-
goto error;
1859+
if (cursor == NULL) {
1860+
return NULL;
18611861
}
1862-
1863-
result = _pysqlite_query_execute((pysqlite_Cursor *)cursor, 0, sql, parameters);
1864-
if (!result) {
1865-
Py_CLEAR(cursor);
1862+
int rc = _pysqlite_query_execute((pysqlite_Cursor *)cursor, sql, parameters);
1863+
if (rc < 0) {
1864+
Py_DECREF(cursor);
1865+
return NULL;
18661866
}
1867-
1868-
error:
1869-
Py_XDECREF(result);
1870-
18711867
return cursor;
18721868
}
18731869

@@ -1886,21 +1882,15 @@ pysqlite_connection_executemany_impl(pysqlite_Connection *self,
18861882
PyObject *sql, PyObject *parameters)
18871883
/*[clinic end generated code: output=776cd2fd20bfe71f input=495be76551d525db]*/
18881884
{
1889-
PyObject* result = 0;
1890-
18911885
PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
1892-
if (!cursor) {
1893-
goto error;
1886+
if (cursor == NULL) {
1887+
return NULL;
18941888
}
1895-
1896-
result = _pysqlite_query_execute((pysqlite_Cursor *)cursor, 1, sql, parameters);
1897-
if (!result) {
1898-
Py_CLEAR(cursor);
1889+
int rc = _pysqlite_query_executemany((pysqlite_Cursor *)cursor, sql, parameters);
1890+
if (rc < 0) {
1891+
Py_DECREF(cursor);
1892+
return NULL;
18991893
}
1900-
1901-
error:
1902-
Py_XDECREF(result);
1903-
19041894
return cursor;
19051895
}
19061896

0 commit comments

Comments
 (0)