summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/module.c
diff options
context:
space:
mode:
authorAnthony Baxter <anthonybaxter@gmail.com>2006-04-04 06:29:05 (GMT)
committerAnthony Baxter <anthonybaxter@gmail.com>2006-04-04 06:29:05 (GMT)
commit72289a616c90949f7a2d3b2af12cd1044e64717d (patch)
tree278f2963d2f72baad0859e6b5e9056b9daddd446 /Modules/_sqlite/module.c
parenta058836e969eba03142bc8f01418a28741f70dc3 (diff)
downloadcpython-72289a616c90949f7a2d3b2af12cd1044e64717d.zip
cpython-72289a616c90949f7a2d3b2af12cd1044e64717d.tar.gz
cpython-72289a616c90949f7a2d3b2af12cd1044e64717d.tar.bz2
Update to pysqlite 2.2.0
Diffstat (limited to 'Modules/_sqlite/module.c')
-rw-r--r--Modules/_sqlite/module.c91
1 files changed, 63 insertions, 28 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 70993d0..60d0d63 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -39,9 +39,6 @@ PyObject* Error, *Warning, *InterfaceError, *DatabaseError, *InternalError,
*OperationalError, *ProgrammingError, *IntegrityError, *DataError,
*NotSupportedError, *OptimizedUnicode;
-PyObject* time_time;
-PyObject* time_sleep;
-
PyObject* converters;
static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
@@ -150,7 +147,9 @@ static PyObject* module_register_converter(PyObject* self, PyObject* args, PyObj
return NULL;
}
- PyDict_SetItem(converters, name, callable);
+ if (PyDict_SetItem(converters, name, callable) != 0) {
+ return NULL;
+ }
Py_INCREF(Py_None);
return Py_None;
@@ -159,6 +158,9 @@ static PyObject* module_register_converter(PyObject* self, PyObject* args, PyObj
void converters_init(PyObject* dict)
{
converters = PyDict_New();
+ if (!converters) {
+ return;
+ }
PyDict_SetItemString(dict, "converters", converters);
}
@@ -169,8 +171,8 @@ static PyMethodDef module_methods[] = {
#ifdef HAVE_SHARED_CACHE
{"enable_shared_cache", (PyCFunction)module_enable_shared_cache, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Enable or disable shared cache mode for the calling thread.")},
#endif
- {"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with pysqlite's adapter registry.")},
- {"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with pysqlite.")},
+ {"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with sqlite's adapter registry.")},
+ {"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with sqlite.")},
{"adapt", (PyCFunction)psyco_microprotocols_adapt, METH_VARARGS, psyco_microprotocols_adapt_doc},
{NULL, NULL}
};
@@ -178,11 +180,11 @@ static PyMethodDef module_methods[] = {
PyMODINIT_FUNC init_sqlite3(void)
{
PyObject *module, *dict;
- PyObject* time_module;
+ PyObject *tmp_obj;
module = Py_InitModule("_sqlite3", module_methods);
- if (
+ if (!module ||
(row_setup_types() < 0) ||
(cursor_setup_types() < 0) ||
(connection_setup_types() < 0) ||
@@ -206,56 +208,93 @@ PyMODINIT_FUNC init_sqlite3(void)
Py_INCREF(&RowType);
PyModule_AddObject(module, "Row", (PyObject*) &RowType);
- if (!(dict = PyModule_GetDict(module)))
- {
+ if (!(dict = PyModule_GetDict(module))) {
goto error;
}
/*** Create DB-API Exception hierarchy */
- Error = PyErr_NewException("sqlite3.Error", PyExc_StandardError, NULL);
+ if (!(Error = PyErr_NewException("sqlite3.Error", PyExc_StandardError, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "Error", Error);
- Warning = PyErr_NewException("sqlite3.Warning", PyExc_StandardError, NULL);
+ if (!(Warning = PyErr_NewException("sqlite3.Warning", PyExc_StandardError, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "Warning", Warning);
/* Error subclasses */
- InterfaceError = PyErr_NewException("sqlite3.InterfaceError", Error, NULL);
+ if (!(InterfaceError = PyErr_NewException("sqlite3.InterfaceError", Error, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "InterfaceError", InterfaceError);
- DatabaseError = PyErr_NewException("sqlite3.DatabaseError", Error, NULL);
+ if (!(DatabaseError = PyErr_NewException("sqlite3.DatabaseError", Error, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "DatabaseError", DatabaseError);
/* DatabaseError subclasses */
- InternalError = PyErr_NewException("sqlite3.InternalError", DatabaseError, NULL);
+ if (!(InternalError = PyErr_NewException("sqlite3.InternalError", DatabaseError, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "InternalError", InternalError);
- OperationalError = PyErr_NewException("sqlite3.OperationalError", DatabaseError, NULL);
+ if (!(OperationalError = PyErr_NewException("sqlite3.OperationalError", DatabaseError, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "OperationalError", OperationalError);
- ProgrammingError = PyErr_NewException("sqlite3.ProgrammingError", DatabaseError, NULL);
+ if (!(ProgrammingError = PyErr_NewException("sqlite3.ProgrammingError", DatabaseError, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "ProgrammingError", ProgrammingError);
- IntegrityError = PyErr_NewException("sqlite3.IntegrityError", DatabaseError,NULL);
+ if (!(IntegrityError = PyErr_NewException("sqlite3.IntegrityError", DatabaseError,NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "IntegrityError", IntegrityError);
- DataError = PyErr_NewException("sqlite3.DataError", DatabaseError, NULL);
+ if (!(DataError = PyErr_NewException("sqlite3.DataError", DatabaseError, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "DataError", DataError);
- NotSupportedError = PyErr_NewException("sqlite3.NotSupportedError", DatabaseError, NULL);
+ if (!(NotSupportedError = PyErr_NewException("sqlite3.NotSupportedError", DatabaseError, NULL))) {
+ goto error;
+ }
PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
+ /* We just need "something" unique for OptimizedUnicode. It does not really
+ * need to be a string subclass. Just anything that can act as a special
+ * marker for us. So I pulled PyCell_Type out of my magic hat.
+ */
Py_INCREF((PyObject*)&PyCell_Type);
OptimizedUnicode = (PyObject*)&PyCell_Type;
PyDict_SetItemString(dict, "OptimizedUnicode", OptimizedUnicode);
- PyDict_SetItemString(dict, "PARSE_DECLTYPES", PyInt_FromLong(PARSE_DECLTYPES));
- PyDict_SetItemString(dict, "PARSE_COLNAMES", PyInt_FromLong(PARSE_COLNAMES));
+ if (!(tmp_obj = PyInt_FromLong(PARSE_DECLTYPES))) {
+ goto error;
+ }
+ PyDict_SetItemString(dict, "PARSE_DECLTYPES", tmp_obj);
- PyDict_SetItemString(dict, "version", PyString_FromString(PYSQLITE_VERSION));
- PyDict_SetItemString(dict, "sqlite_version", PyString_FromString(sqlite3_libversion()));
+ if (!(tmp_obj = PyInt_FromLong(PARSE_COLNAMES))) {
+ goto error;
+ }
+ PyDict_SetItemString(dict, "PARSE_COLNAMES", tmp_obj);
+
+ if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) {
+ goto error;
+ }
+ PyDict_SetItemString(dict, "version", tmp_obj);
+
+ if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) {
+ goto error;
+ }
+ PyDict_SetItemString(dict, "sqlite_version", tmp_obj);
/* initialize microprotocols layer */
microprotocols_init(dict);
@@ -263,10 +302,6 @@ PyMODINIT_FUNC init_sqlite3(void)
/* initialize the default converters */
converters_init(dict);
- time_module = PyImport_ImportModule("time");
- time_time = PyObject_GetAttrString(time_module, "time");
- time_sleep = PyObject_GetAttrString(time_module, "sleep");
-
/* Original comment form _bsddb.c in the Python core. This is also still
* needed nowadays for Python 2.3/2.4.
*