diff options
Diffstat (limited to 'Modules/_sqlite')
| -rw-r--r-- | Modules/_sqlite/connection.c | 20 | ||||
| -rw-r--r-- | Modules/_sqlite/connection.h | 2 | ||||
| -rw-r--r-- | Modules/_sqlite/cursor.c | 23 | ||||
| -rw-r--r-- | Modules/_sqlite/microprotocols.h | 2 | ||||
| -rw-r--r-- | Modules/_sqlite/module.h | 2 | ||||
| -rw-r--r-- | Modules/_sqlite/row.c | 5 |
6 files changed, 25 insertions, 29 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index d390328..6aa4764 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -164,6 +164,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject #ifdef WITH_THREAD self->thread_ident = PyThread_get_thread_ident(); #endif + if (!check_same_thread && sqlite3_libversion_number() < 3003001) { + PyErr_SetString(pysqlite_NotSupportedError, "shared connections not available"); + return -1; + } self->check_same_thread = check_same_thread; self->function_pinboard = PyDict_New(); @@ -204,8 +208,8 @@ void pysqlite_flush_statement_cache(pysqlite_Connection* self) node = node->next; } - Py_DECREF(self->statement_cache); - self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "O", self); + Py_SETREF(self->statement_cache, + (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; } @@ -318,9 +322,8 @@ PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, _pysqlite_drop_unused_cursor_references(self); if (cursor && self->row_factory != Py_None) { - Py_XDECREF(((pysqlite_Cursor*)cursor)->row_factory); Py_INCREF(self->row_factory); - ((pysqlite_Cursor*)cursor)->row_factory = self->row_factory; + Py_XSETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); } return cursor; @@ -795,8 +798,7 @@ static void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self } } - Py_DECREF(self->statements); - self->statements = new_list; + Py_SETREF(self->statements, new_list); } static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -827,8 +829,7 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) } } - Py_DECREF(self->cursors); - self->cursors = new_list; + Py_SETREF(self->cursors, new_list); } PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) @@ -1241,6 +1242,9 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py return NULL; } + if (!_PyArg_NoKeywords(MODULE_NAME ".Connection()", kwargs)) + return NULL; + if (!PyArg_ParseTuple(args, "O", &sql)) return NULL; diff --git a/Modules/_sqlite/connection.h b/Modules/_sqlite/connection.h index 0c9734c..fbd9063 100644 --- a/Modules/_sqlite/connection.h +++ b/Modules/_sqlite/connection.h @@ -52,7 +52,7 @@ typedef struct * first get called with count=0? */ double timeout_started; - /* None for autocommit, otherwise a PyString with the isolation level */ + /* None for autocommit, otherwise a PyUnicode with the isolation level */ PyObject* isolation_level; /* NULL for autocommit, otherwise a string with the BEGIN statement; will be diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index db96b02..300da28 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -46,7 +46,7 @@ static pysqlite_StatementKind detect_statement_type(const char* statement) dst = buf; *dst = 0; - while (Py_ISALPHA(*src) && dst - buf < sizeof(buf) - 2) { + while (Py_ISALPHA(*src) && (dst - buf) < ((Py_ssize_t)sizeof(buf) - 2)) { *dst++ = Py_TOLOWER(*src++); } @@ -170,8 +170,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self) return 0; } - Py_XDECREF(self->row_cast_map); - self->row_cast_map = PyList_New(0); + Py_XSETREF(self->row_cast_map, PyList_New(0)); for (i = 0; i < sqlite3_column_count(self->statement->st); i++) { converter = NULL; @@ -334,11 +333,7 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self) if (self->connection->text_factory == (PyObject*)&PyUnicode_Type) { converted = PyUnicode_FromStringAndSize(val_str, nbytes); if (!converted) { -#ifdef Py_DEBUG - /* in debug mode, type_call() fails with an assertion - error if an exception is set when it is called */ PyErr_Clear(); -#endif colname = sqlite3_column_name(self->statement->st, i); if (!colname) { colname = "<unknown column name>"; @@ -514,9 +509,8 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* goto error; /* reset description and rowcount */ - Py_DECREF(self->description); Py_INCREF(Py_None); - self->description = Py_None; + Py_SETREF(self->description, Py_None); self->rowcount = -1L; func_args = PyTuple_New(1); @@ -530,10 +524,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* if (self->statement) { (void)pysqlite_statement_reset(self->statement); - Py_DECREF(self->statement); } - self->statement = (pysqlite_Statement*)pysqlite_cache_get(self->connection->statement_cache, func_args); + Py_XSETREF(self->statement, + (pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args)); Py_DECREF(func_args); if (!self->statement) { @@ -541,8 +535,8 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* } if (self->statement->in_use) { - Py_DECREF(self->statement); - self->statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType); + Py_SETREF(self->statement, + PyObject_New(pysqlite_Statement, &pysqlite_StatementType)); if (!self->statement) { goto error; } @@ -658,8 +652,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS - Py_DECREF(self->description); - self->description = PyTuple_New(numcols); + Py_SETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; } diff --git a/Modules/_sqlite/microprotocols.h b/Modules/_sqlite/microprotocols.h index 3a9944f..6941716 100644 --- a/Modules/_sqlite/microprotocols.h +++ b/Modules/_sqlite/microprotocols.h @@ -48,7 +48,7 @@ extern PyObject *pysqlite_microprotocols_adapt( PyObject *obj, PyObject *proto, PyObject *alt); extern PyObject * - pysqlite_adapt(pysqlite_Cursor* self, PyObject *args); + pysqlite_adapt(pysqlite_Cursor* self, PyObject *args); #define pysqlite_adapt_doc \ "adapt(obj, protocol, alternate) -> adapt obj to given protocol. Non-standard." diff --git a/Modules/_sqlite/module.h b/Modules/_sqlite/module.h index b51724b..0fb5a55 100644 --- a/Modules/_sqlite/module.h +++ b/Modules/_sqlite/module.h @@ -42,7 +42,7 @@ extern PyObject* pysqlite_NotSupportedError; extern PyObject* time_time; extern PyObject* time_sleep; -/* A dictionary, mapping colum types (INTEGER, VARCHAR, etc.) to converter +/* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter * functions, that convert the SQL value to the appropriate Python value. * The key is uppercase. */ diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c index ee73446..07584e3 100644 --- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -142,8 +142,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx) return NULL; } else if (PySlice_Check(idx)) { - PyErr_SetString(PyExc_ValueError, "slices not implemented, yet"); - return NULL; + return PyObject_GetItem(self->data, idx); } else { PyErr_SetString(PyExc_IndexError, "Index must be int or string"); @@ -159,7 +158,7 @@ Py_ssize_t pysqlite_row_length(pysqlite_Row* self, PyObject* args, PyObject* kwa PyObject* pysqlite_row_keys(pysqlite_Row* self, PyObject* args, PyObject* kwargs) { PyObject* list; - int nitems, i; + Py_ssize_t nitems, i; list = PyList_New(0); if (!list) { |
