summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-03-28 08:32:09 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2008-03-28 08:32:09 (GMT)
commitb9803421d231fc66489eafb45f6ae440010cacfc (patch)
treec934cab8654aef8bc092f4a70d3fddfc9e34fa51 /Modules/_sqlite
parent621cd262539cd6bea59bb1c3cfc35b9d37a26d98 (diff)
downloadcpython-b9803421d231fc66489eafb45f6ae440010cacfc.zip
cpython-b9803421d231fc66489eafb45f6ae440010cacfc.tar.gz
cpython-b9803421d231fc66489eafb45f6ae440010cacfc.tar.bz2
Accept patch issue2426 by Paul Kippes (kippesp).
Adds sqlite3.Connection.iterdump to allow dumping of databases.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/connection.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 92c6a24..8269e0b 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -1199,6 +1199,52 @@ finally:
return retval;
}
+/* Function author: Paul Kippes <kippesp@gmail.com>
+ * Class method of Connection to call the Python function _iterdump
+ * of the sqlite3 module.
+ */
+static PyObject *
+pysqlite_connection_iterdump(pysqlite_Connection* self, PyObject* args)
+{
+ PyObject* retval = NULL;
+ PyObject* module = NULL;
+ PyObject* module_dict;
+ PyObject* pyfn_iterdump;
+
+ if (!pysqlite_check_connection(self)) {
+ goto finally;
+ }
+
+ module = PyImport_ImportModule(MODULE_NAME ".dump");
+ if (!module) {
+ goto finally;
+ }
+
+ module_dict = PyModule_GetDict(module);
+ if (!module_dict) {
+ goto finally;
+ }
+
+ pyfn_iterdump = PyDict_GetItemString(module_dict, "_iterdump");
+ if (!pyfn_iterdump) {
+ PyErr_SetString(pysqlite_OperationalError, "Failed to obtain _iterdump() reference");
+ goto finally;
+ }
+
+ args = PyTuple_New(1);
+ if (!args) {
+ goto finally;
+ }
+ Py_INCREF(self);
+ PyTuple_SetItem(args, 0, (PyObject*)self);
+ retval = PyObject_CallObject(pyfn_iterdump, args);
+
+finally:
+ Py_XDECREF(args);
+ Py_XDECREF(module);
+ return retval;
+}
+
static PyObject *
pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
{
@@ -1344,6 +1390,8 @@ static PyMethodDef connection_methods[] = {
PyDoc_STR("Creates a collation function. Non-standard.")},
{"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS,
PyDoc_STR("Abort any pending database operation. Non-standard.")},
+ {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS,
+ PyDoc_STR("Returns iterator to the dump of the database in an SQL text format.")},
{"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS,
PyDoc_STR("For context manager. Non-standard.")},
{"__exit__", (PyCFunction)pysqlite_connection_exit, METH_VARARGS,