summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/_sqlite/module.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-04-18 12:39:32 +0300
committershadchin <[email protected]>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Modules/_sqlite/module.c
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Modules/_sqlite/module.c')
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/module.c459
1 files changed, 213 insertions, 246 deletions
diff --git a/contrib/tools/python3/src/Modules/_sqlite/module.c b/contrib/tools/python3/src/Modules/_sqlite/module.c
index 98909369e75..8cff4e224d5 100644
--- a/contrib/tools/python3/src/Modules/_sqlite/module.c
+++ b/contrib/tools/python3/src/Modules/_sqlite/module.c
@@ -29,10 +29,16 @@
#include "microprotocols.h"
#include "row.h"
-#if SQLITE_VERSION_NUMBER >= 3003003
-#define HAVE_SHARED_CACHE
+#if SQLITE_VERSION_NUMBER < 3007015
+#error "SQLite 3.7.15 or higher required"
#endif
+#include "clinic/module.c.h"
+/*[clinic input]
+module _sqlite3
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
+
/* static objects at module-level */
PyObject *pysqlite_Error = NULL;
@@ -80,7 +86,7 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
}
if (factory == NULL) {
- factory = (PyObject*)&pysqlite_ConnectionType;
+ factory = (PyObject*)pysqlite_ConnectionType;
}
return PyObject_Call(factory, args, kwargs);
@@ -94,48 +100,44 @@ Opens a connection to the SQLite database file *database*. You can use\n\
\":memory:\" to open a database connection to a database that resides in\n\
RAM instead of on disk.");
-static PyObject* module_complete(PyObject* self, PyObject* args, PyObject*
- kwargs)
-{
- static char *kwlist[] = {"statement", NULL};
- char* statement;
+/*[clinic input]
+_sqlite3.complete_statement as pysqlite_complete_statement
- PyObject* result;
+ statement: str
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &statement))
- {
- return NULL;
- }
+Checks if a string contains a complete SQL statement.
+[clinic start generated code]*/
+static PyObject *
+pysqlite_complete_statement_impl(PyObject *module, const char *statement)
+/*[clinic end generated code: output=e55f1ff1952df558 input=ac45d257375bb828]*/
+{
if (sqlite3_complete(statement)) {
- result = Py_True;
+ return Py_NewRef(Py_True);
} else {
- result = Py_False;
+ return Py_NewRef(Py_False);
}
+}
- Py_INCREF(result);
+/*[clinic input]
+_sqlite3.enable_shared_cache as pysqlite_enable_shared_cache
- return result;
-}
+ do_enable: int
-PyDoc_STRVAR(module_complete_doc,
-"complete_statement(sql)\n\
-\n\
-Checks if a string contains a complete SQL statement.");
+Enable or disable shared cache mode for the calling thread.
-#ifdef HAVE_SHARED_CACHE
-static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyObject*
- kwargs)
+This method is deprecated and will be removed in Python 3.12.
+Shared cache is strongly discouraged by the SQLite 3 documentation.
+If shared cache must be used, open the database in URI mode using
+the cache=shared query parameter.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_enable_shared_cache_impl(PyObject *module, int do_enable)
+/*[clinic end generated code: output=259c74eedee1516b input=26e40d5971d3487d]*/
{
- static char *kwlist[] = {"do_enable", NULL};
- int do_enable;
int rc;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &do_enable))
- {
- return NULL;
- }
-
rc = sqlite3_enable_shared_cache(do_enable);
if (rc != SQLITE_OK) {
@@ -146,22 +148,23 @@ static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyOb
}
}
-PyDoc_STRVAR(module_enable_shared_cache_doc,
-"enable_shared_cache(do_enable)\n\
-\n\
-Enable or disable shared cache mode for the calling thread.");
-#endif /* HAVE_SHARED_CACHE */
+/*[clinic input]
+_sqlite3.register_adapter as pysqlite_register_adapter
+
+ type: object(type='PyTypeObject *')
+ caster: object
+ /
+
+Registers an adapter with sqlite3's adapter registry.
+[clinic start generated code]*/
-static PyObject* module_register_adapter(PyObject* self, PyObject* args)
+static PyObject *
+pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
+ PyObject *caster)
+/*[clinic end generated code: output=a287e8db18e8af23 input=b4bd87afcadc535d]*/
{
- PyTypeObject* type;
- PyObject* caster;
int rc;
- if (!PyArg_ParseTuple(args, "OO", &type, &caster)) {
- return NULL;
- }
-
/* a basic type is adapted; there's a performance optimization if that's not the case
* (99 % of all usages) */
if (type == &PyLong_Type || type == &PyFloat_Type
@@ -169,30 +172,32 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args)
pysqlite_BaseTypeAdapted = 1;
}
- rc = pysqlite_microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster);
+ rc = pysqlite_microprotocols_add(type, (PyObject*)pysqlite_PrepareProtocolType, caster);
if (rc == -1)
return NULL;
Py_RETURN_NONE;
}
-PyDoc_STRVAR(module_register_adapter_doc,
-"register_adapter(type, callable)\n\
-\n\
-Registers an adapter with sqlite3's adapter registry.");
+/*[clinic input]
+_sqlite3.register_converter as pysqlite_register_converter
+
+ name as orig_name: unicode
+ converter as callable: object
+ /
+
+Registers a converter with sqlite3.
+[clinic start generated code]*/
-static PyObject* module_register_converter(PyObject* self, PyObject* args)
+static PyObject *
+pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
+ PyObject *callable)
+/*[clinic end generated code: output=a2f2bfeed7230062 input=90f645419425d6c4]*/
{
- PyObject* orig_name;
PyObject* name = NULL;
- PyObject* callable;
PyObject* retval = NULL;
_Py_IDENTIFIER(upper);
- if (!PyArg_ParseTuple(args, "UO", &orig_name, &callable)) {
- return NULL;
- }
-
/* convert the name to upper case */
name = _PyObject_CallMethodIdNoArgs(orig_name, &PyId_upper);
if (!name) {
@@ -203,127 +208,127 @@ static PyObject* module_register_converter(PyObject* self, PyObject* args)
goto error;
}
- Py_INCREF(Py_None);
- retval = Py_None;
+ retval = Py_NewRef(Py_None);
error:
Py_XDECREF(name);
return retval;
}
-PyDoc_STRVAR(module_register_converter_doc,
-"register_converter(typename, callable)\n\
-\n\
-Registers a converter with sqlite3.");
+/*[clinic input]
+_sqlite3.enable_callback_tracebacks as pysqlite_enable_callback_trace
-static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args)
+ enable: int
+ /
+
+Enable or disable callback functions throwing errors to stderr.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_enable_callback_trace_impl(PyObject *module, int enable)
+/*[clinic end generated code: output=4ff1d051c698f194 input=cb79d3581eb77c40]*/
{
- if (!PyArg_ParseTuple(args, "i", &_pysqlite_enable_callback_tracebacks)) {
- return NULL;
- }
+ _pysqlite_enable_callback_tracebacks = enable;
Py_RETURN_NONE;
}
-PyDoc_STRVAR(enable_callback_tracebacks_doc,
-"enable_callback_tracebacks(flag)\n\
-\n\
-Enable or disable callback functions throwing errors to stderr.");
+/*[clinic input]
+_sqlite3.adapt as pysqlite_adapt
+
+ obj: object
+ proto: object(c_default='(PyObject*)pysqlite_PrepareProtocolType') = PrepareProtocolType
+ alt: object = NULL
+ /
-static void converters_init(PyObject* dict)
+Adapt given object to given protocol.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
+ PyObject *alt)
+/*[clinic end generated code: output=0c3927c5fcd23dd9 input=46ca9564710ba48a]*/
+{
+ return pysqlite_microprotocols_adapt(obj, proto, alt);
+}
+
+static int converters_init(PyObject* module)
{
_pysqlite_converters = PyDict_New();
if (!_pysqlite_converters) {
- return;
+ return -1;
}
- PyDict_SetItemString(dict, "converters", _pysqlite_converters);
+ int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters);
+ Py_DECREF(_pysqlite_converters);
+
+ return res;
}
static PyMethodDef module_methods[] = {
{"connect", (PyCFunction)(void(*)(void))module_connect,
METH_VARARGS | METH_KEYWORDS, module_connect_doc},
- {"complete_statement", (PyCFunction)(void(*)(void))module_complete,
- METH_VARARGS | METH_KEYWORDS, module_complete_doc},
-#ifdef HAVE_SHARED_CACHE
- {"enable_shared_cache", (PyCFunction)(void(*)(void))module_enable_shared_cache,
- METH_VARARGS | METH_KEYWORDS, module_enable_shared_cache_doc},
-#endif
- {"register_adapter", (PyCFunction)module_register_adapter,
- METH_VARARGS, module_register_adapter_doc},
- {"register_converter", (PyCFunction)module_register_converter,
- METH_VARARGS, module_register_converter_doc},
- {"adapt", (PyCFunction)pysqlite_adapt, METH_VARARGS,
- pysqlite_adapt_doc},
- {"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks,
- METH_VARARGS, enable_callback_tracebacks_doc},
+ PYSQLITE_ADAPT_METHODDEF
+ PYSQLITE_COMPLETE_STATEMENT_METHODDEF
+ PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
+ PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF
+ PYSQLITE_REGISTER_ADAPTER_METHODDEF
+ PYSQLITE_REGISTER_CONVERTER_METHODDEF
{NULL, NULL}
};
-struct _IntConstantPair {
- const char *constant_name;
- int constant_value;
-};
-
-typedef struct _IntConstantPair IntConstantPair;
-
-static const IntConstantPair _int_constants[] = {
- {"PARSE_DECLTYPES", PARSE_DECLTYPES},
- {"PARSE_COLNAMES", PARSE_COLNAMES},
+static int
+add_integer_constants(PyObject *module) {
+#define ADD_INT(ival) \
+ do { \
+ if (PyModule_AddIntConstant(module, #ival, ival) < 0) { \
+ return -1; \
+ } \
+ } while (0); \
- {"SQLITE_OK", SQLITE_OK},
- {"SQLITE_DENY", SQLITE_DENY},
- {"SQLITE_IGNORE", SQLITE_IGNORE},
- {"SQLITE_CREATE_INDEX", SQLITE_CREATE_INDEX},
- {"SQLITE_CREATE_TABLE", SQLITE_CREATE_TABLE},
- {"SQLITE_CREATE_TEMP_INDEX", SQLITE_CREATE_TEMP_INDEX},
- {"SQLITE_CREATE_TEMP_TABLE", SQLITE_CREATE_TEMP_TABLE},
- {"SQLITE_CREATE_TEMP_TRIGGER", SQLITE_CREATE_TEMP_TRIGGER},
- {"SQLITE_CREATE_TEMP_VIEW", SQLITE_CREATE_TEMP_VIEW},
- {"SQLITE_CREATE_TRIGGER", SQLITE_CREATE_TRIGGER},
- {"SQLITE_CREATE_VIEW", SQLITE_CREATE_VIEW},
- {"SQLITE_DELETE", SQLITE_DELETE},
- {"SQLITE_DROP_INDEX", SQLITE_DROP_INDEX},
- {"SQLITE_DROP_TABLE", SQLITE_DROP_TABLE},
- {"SQLITE_DROP_TEMP_INDEX", SQLITE_DROP_TEMP_INDEX},
- {"SQLITE_DROP_TEMP_TABLE", SQLITE_DROP_TEMP_TABLE},
- {"SQLITE_DROP_TEMP_TRIGGER", SQLITE_DROP_TEMP_TRIGGER},
- {"SQLITE_DROP_TEMP_VIEW", SQLITE_DROP_TEMP_VIEW},
- {"SQLITE_DROP_TRIGGER", SQLITE_DROP_TRIGGER},
- {"SQLITE_DROP_VIEW", SQLITE_DROP_VIEW},
- {"SQLITE_INSERT", SQLITE_INSERT},
- {"SQLITE_PRAGMA", SQLITE_PRAGMA},
- {"SQLITE_READ", SQLITE_READ},
- {"SQLITE_SELECT", SQLITE_SELECT},
- {"SQLITE_TRANSACTION", SQLITE_TRANSACTION},
- {"SQLITE_UPDATE", SQLITE_UPDATE},
- {"SQLITE_ATTACH", SQLITE_ATTACH},
- {"SQLITE_DETACH", SQLITE_DETACH},
-#if SQLITE_VERSION_NUMBER >= 3002001
- {"SQLITE_ALTER_TABLE", SQLITE_ALTER_TABLE},
- {"SQLITE_REINDEX", SQLITE_REINDEX},
-#endif
-#if SQLITE_VERSION_NUMBER >= 3003000
- {"SQLITE_ANALYZE", SQLITE_ANALYZE},
-#endif
-#if SQLITE_VERSION_NUMBER >= 3003007
- {"SQLITE_CREATE_VTABLE", SQLITE_CREATE_VTABLE},
- {"SQLITE_DROP_VTABLE", SQLITE_DROP_VTABLE},
-#endif
-#if SQLITE_VERSION_NUMBER >= 3003008
- {"SQLITE_FUNCTION", SQLITE_FUNCTION},
-#endif
-#if SQLITE_VERSION_NUMBER >= 3006008
- {"SQLITE_SAVEPOINT", SQLITE_SAVEPOINT},
-#endif
+ ADD_INT(PARSE_DECLTYPES);
+ ADD_INT(PARSE_COLNAMES);
+ ADD_INT(SQLITE_OK);
+ ADD_INT(SQLITE_DENY);
+ ADD_INT(SQLITE_IGNORE);
+ ADD_INT(SQLITE_CREATE_INDEX);
+ ADD_INT(SQLITE_CREATE_TABLE);
+ ADD_INT(SQLITE_CREATE_TEMP_INDEX);
+ ADD_INT(SQLITE_CREATE_TEMP_TABLE);
+ ADD_INT(SQLITE_CREATE_TEMP_TRIGGER);
+ ADD_INT(SQLITE_CREATE_TEMP_VIEW);
+ ADD_INT(SQLITE_CREATE_TRIGGER);
+ ADD_INT(SQLITE_CREATE_VIEW);
+ ADD_INT(SQLITE_DELETE);
+ ADD_INT(SQLITE_DROP_INDEX);
+ ADD_INT(SQLITE_DROP_TABLE);
+ ADD_INT(SQLITE_DROP_TEMP_INDEX);
+ ADD_INT(SQLITE_DROP_TEMP_TABLE);
+ ADD_INT(SQLITE_DROP_TEMP_TRIGGER);
+ ADD_INT(SQLITE_DROP_TEMP_VIEW);
+ ADD_INT(SQLITE_DROP_TRIGGER);
+ ADD_INT(SQLITE_DROP_VIEW);
+ ADD_INT(SQLITE_INSERT);
+ ADD_INT(SQLITE_PRAGMA);
+ ADD_INT(SQLITE_READ);
+ ADD_INT(SQLITE_SELECT);
+ ADD_INT(SQLITE_TRANSACTION);
+ ADD_INT(SQLITE_UPDATE);
+ ADD_INT(SQLITE_ATTACH);
+ ADD_INT(SQLITE_DETACH);
+ ADD_INT(SQLITE_ALTER_TABLE);
+ ADD_INT(SQLITE_REINDEX);
+ ADD_INT(SQLITE_ANALYZE);
+ ADD_INT(SQLITE_CREATE_VTABLE);
+ ADD_INT(SQLITE_DROP_VTABLE);
+ ADD_INT(SQLITE_FUNCTION);
+ ADD_INT(SQLITE_SAVEPOINT);
#if SQLITE_VERSION_NUMBER >= 3008003
- {"SQLITE_RECURSIVE", SQLITE_RECURSIVE},
-#endif
-#if SQLITE_VERSION_NUMBER >= 3006011
- {"SQLITE_DONE", SQLITE_DONE},
+ ADD_INT(SQLITE_RECURSIVE);
#endif
- {(char*)NULL, 0}
-};
-
+ ADD_INT(SQLITE_DONE);
+#undef ADD_INT
+ return 0;
+}
static struct PyModuleDef _sqlite3module = {
PyModuleDef_HEAD_INIT,
@@ -340,138 +345,100 @@ static struct PyModuleDef _sqlite3module = {
#define ADD_TYPE(module, type) \
do { \
if (PyModule_AddType(module, &type) < 0) { \
- Py_DECREF(module); \
- return NULL; \
+ goto error; \
} \
} while (0)
+#define ADD_EXCEPTION(module, name, exc, base) \
+do { \
+ exc = PyErr_NewException(MODULE_NAME "." name, base, NULL); \
+ if (!exc) { \
+ goto error; \
+ } \
+ int res = PyModule_AddObjectRef(module, name, exc); \
+ Py_DECREF(exc); \
+ if (res < 0) { \
+ goto error; \
+ } \
+} while (0)
+
PyMODINIT_FUNC PyInit__sqlite3(void)
{
- PyObject *module, *dict;
- PyObject *tmp_obj;
- int i;
-
- module = PyModule_Create(&_sqlite3module);
+ PyObject *module;
- if (!module ||
- (pysqlite_row_setup_types() < 0) ||
- (pysqlite_cursor_setup_types() < 0) ||
- (pysqlite_connection_setup_types() < 0) ||
- (pysqlite_cache_setup_types() < 0) ||
- (pysqlite_statement_setup_types() < 0) ||
- (pysqlite_prepare_protocol_setup_types() < 0)
- ) {
- Py_XDECREF(module);
+ if (sqlite3_libversion_number() < 3007015) {
+ PyErr_SetString(PyExc_ImportError, MODULE_NAME ": SQLite 3.7.15 or higher required");
return NULL;
}
- ADD_TYPE(module, pysqlite_ConnectionType);
- ADD_TYPE(module, pysqlite_CursorType);
- ADD_TYPE(module, pysqlite_PrepareProtocolType);
- ADD_TYPE(module, pysqlite_RowType);
-
- if (!(dict = PyModule_GetDict(module))) {
- goto error;
+ int rc = sqlite3_initialize();
+ if (rc != SQLITE_OK) {
+ PyErr_SetString(PyExc_ImportError, sqlite3_errstr(rc));
+ return NULL;
}
- /*** Create DB-API Exception hierarchy */
-
- if (!(pysqlite_Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_Exception, NULL))) {
- goto error;
- }
- PyDict_SetItemString(dict, "Error", pysqlite_Error);
+ module = PyModule_Create(&_sqlite3module);
- if (!(pysqlite_Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_Exception, NULL))) {
+ if (!module ||
+ (pysqlite_row_setup_types(module) < 0) ||
+ (pysqlite_cursor_setup_types(module) < 0) ||
+ (pysqlite_connection_setup_types(module) < 0) ||
+ (pysqlite_cache_setup_types(module) < 0) ||
+ (pysqlite_statement_setup_types(module) < 0) ||
+ (pysqlite_prepare_protocol_setup_types(module) < 0)
+ ) {
goto error;
}
- PyDict_SetItemString(dict, "Warning", pysqlite_Warning);
- /* Error subclasses */
+ ADD_TYPE(module, *pysqlite_ConnectionType);
+ ADD_TYPE(module, *pysqlite_CursorType);
+ ADD_TYPE(module, *pysqlite_PrepareProtocolType);
+ ADD_TYPE(module, *pysqlite_RowType);
- if (!(pysqlite_InterfaceError = PyErr_NewException(MODULE_NAME ".InterfaceError", pysqlite_Error, NULL))) {
- goto error;
- }
- PyDict_SetItemString(dict, "InterfaceError", pysqlite_InterfaceError);
+ /*** Create DB-API Exception hierarchy */
+ ADD_EXCEPTION(module, "Error", pysqlite_Error, PyExc_Exception);
+ ADD_EXCEPTION(module, "Warning", pysqlite_Warning, PyExc_Exception);
- if (!(pysqlite_DatabaseError = PyErr_NewException(MODULE_NAME ".DatabaseError", pysqlite_Error, NULL))) {
- goto error;
- }
- PyDict_SetItemString(dict, "DatabaseError", pysqlite_DatabaseError);
+ /* Error subclasses */
+ ADD_EXCEPTION(module, "InterfaceError", pysqlite_InterfaceError, pysqlite_Error);
+ ADD_EXCEPTION(module, "DatabaseError", pysqlite_DatabaseError, pysqlite_Error);
/* pysqlite_DatabaseError subclasses */
+ ADD_EXCEPTION(module, "InternalError", pysqlite_InternalError, pysqlite_DatabaseError);
+ ADD_EXCEPTION(module, "OperationalError", pysqlite_OperationalError, pysqlite_DatabaseError);
+ ADD_EXCEPTION(module, "ProgrammingError", pysqlite_ProgrammingError, pysqlite_DatabaseError);
+ ADD_EXCEPTION(module, "IntegrityError", pysqlite_IntegrityError, pysqlite_DatabaseError);
+ ADD_EXCEPTION(module, "DataError", pysqlite_DataError, pysqlite_DatabaseError);
+ ADD_EXCEPTION(module, "NotSupportedError", pysqlite_NotSupportedError, pysqlite_DatabaseError);
- if (!(pysqlite_InternalError = PyErr_NewException(MODULE_NAME ".InternalError", pysqlite_DatabaseError, NULL))) {
- goto error;
- }
- PyDict_SetItemString(dict, "InternalError", pysqlite_InternalError);
-
- if (!(pysqlite_OperationalError = PyErr_NewException(MODULE_NAME ".OperationalError", pysqlite_DatabaseError, NULL))) {
- goto error;
- }
- PyDict_SetItemString(dict, "OperationalError", pysqlite_OperationalError);
-
- if (!(pysqlite_ProgrammingError = PyErr_NewException(MODULE_NAME ".ProgrammingError", pysqlite_DatabaseError, NULL))) {
- goto error;
- }
- PyDict_SetItemString(dict, "ProgrammingError", pysqlite_ProgrammingError);
-
- if (!(pysqlite_IntegrityError = PyErr_NewException(MODULE_NAME ".IntegrityError", pysqlite_DatabaseError,NULL))) {
+ /* Set integer constants */
+ if (add_integer_constants(module) < 0) {
goto error;
}
- PyDict_SetItemString(dict, "IntegrityError", pysqlite_IntegrityError);
- if (!(pysqlite_DataError = PyErr_NewException(MODULE_NAME ".DataError", pysqlite_DatabaseError, NULL))) {
+ if (PyModule_AddStringConstant(module, "version", PYSQLITE_VERSION) < 0) {
goto error;
}
- PyDict_SetItemString(dict, "DataError", pysqlite_DataError);
- if (!(pysqlite_NotSupportedError = PyErr_NewException(MODULE_NAME ".NotSupportedError", pysqlite_DatabaseError, NULL))) {
+ if (PyModule_AddStringConstant(module, "sqlite_version", sqlite3_libversion())) {
goto error;
}
- PyDict_SetItemString(dict, "NotSupportedError", pysqlite_NotSupportedError);
-
- /* In Python 2.x, setting Connection.text_factory to
- OptimizedUnicode caused Unicode objects to be returned for
- non-ASCII data and bytestrings to be returned for ASCII data.
- Now OptimizedUnicode is an alias for str, so it has no
- effect. */
- Py_INCREF((PyObject*)&PyUnicode_Type);
- PyDict_SetItemString(dict, "OptimizedUnicode", (PyObject*)&PyUnicode_Type);
- /* Set integer constants */
- for (i = 0; _int_constants[i].constant_name != NULL; i++) {
- tmp_obj = PyLong_FromLong(_int_constants[i].constant_value);
- if (!tmp_obj) {
- goto error;
- }
- PyDict_SetItemString(dict, _int_constants[i].constant_name, tmp_obj);
- Py_DECREF(tmp_obj);
- }
-
- if (!(tmp_obj = PyUnicode_FromString(PYSQLITE_VERSION))) {
+ /* initialize microprotocols layer */
+ if (pysqlite_microprotocols_init(module) < 0) {
goto error;
}
- PyDict_SetItemString(dict, "version", tmp_obj);
- Py_DECREF(tmp_obj);
- if (!(tmp_obj = PyUnicode_FromString(sqlite3_libversion()))) {
+ /* initialize the default converters */
+ if (converters_init(module) < 0) {
goto error;
}
- PyDict_SetItemString(dict, "sqlite_version", tmp_obj);
- Py_DECREF(tmp_obj);
-
- /* initialize microprotocols layer */
- pysqlite_microprotocols_init(dict);
- /* initialize the default converters */
- converters_init(dict);
+ return module;
error:
- if (PyErr_Occurred())
- {
- PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
- Py_DECREF(module);
- module = NULL;
- }
- return module;
+ sqlite3_shutdown();
+ PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
+ Py_XDECREF(module);
+ return NULL;
}