mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00

svn+ssh://pythondev@svn.python.org/python/trunk ........ r53304 | vinay.sajip | 2007-01-09 15:50:28 +0100 (Tue, 09 Jan 2007) | 1 line Bug #1627575: Added _open() method to FileHandler which can be used to reopen files. The FileHandler instance now saves the encoding (which can be None) in an attribute called "encoding". ........ r53305 | vinay.sajip | 2007-01-09 15:51:36 +0100 (Tue, 09 Jan 2007) | 1 line Added entry about addition of _open() method to logging.FileHandler. ........ r53306 | vinay.sajip | 2007-01-09 15:54:56 +0100 (Tue, 09 Jan 2007) | 1 line Added a docstring ........ r53316 | thomas.heller | 2007-01-09 20:19:33 +0100 (Tue, 09 Jan 2007) | 4 lines Verify the sizes of the basic ctypes data types against the struct module. Will backport to release25-maint. ........ r53340 | gustavo.niemeyer | 2007-01-10 17:13:40 +0100 (Wed, 10 Jan 2007) | 3 lines Mention in the int() docstring that a base zero has meaning, as stated in http://docs.python.org/lib/built-in-funcs.html as well. ........ r53341 | gustavo.niemeyer | 2007-01-10 17:15:48 +0100 (Wed, 10 Jan 2007) | 2 lines Minor change in int() docstring for proper spacing. ........ r53358 | thomas.heller | 2007-01-10 21:12:13 +0100 (Wed, 10 Jan 2007) | 1 line Change the ctypes version number to "1.1.0". ........ r53361 | thomas.heller | 2007-01-10 21:51:19 +0100 (Wed, 10 Jan 2007) | 1 line Must change the version number in the _ctypes extension as well. ........ r53362 | guido.van.rossum | 2007-01-11 00:12:56 +0100 (Thu, 11 Jan 2007) | 3 lines Fix the signature of log_error(). (A subclass that did the right thing was getting complaints from pychecker.) ........ r53370 | matthias.klose | 2007-01-11 11:26:31 +0100 (Thu, 11 Jan 2007) | 2 lines - Make the documentation match the code and the docstring ........ r53375 | matthias.klose | 2007-01-11 12:44:04 +0100 (Thu, 11 Jan 2007) | 2 lines - idle: Honor the "Cancel" action in the save dialog (Debian bug #299092). ........ r53381 | raymond.hettinger | 2007-01-11 19:22:55 +0100 (Thu, 11 Jan 2007) | 1 line SF #1486663 -- Allow keyword args in subclasses of set() and frozenset(). ........ r53388 | thomas.heller | 2007-01-11 22:18:56 +0100 (Thu, 11 Jan 2007) | 4 lines Fixes for 64-bit Windows: In ctypes.wintypes, correct the definitions of HANDLE, WPARAM, LPARAM data types. Make parameterless foreign function calls work. ........ r53390 | thomas.heller | 2007-01-11 22:23:12 +0100 (Thu, 11 Jan 2007) | 2 lines Correct the comments: the code is right. ........ r53393 | brett.cannon | 2007-01-12 08:27:52 +0100 (Fri, 12 Jan 2007) | 3 lines Fix error where the end of a funcdesc environment was accidentally moved too far down. ........ r53397 | anthony.baxter | 2007-01-12 10:35:56 +0100 (Fri, 12 Jan 2007) | 3 lines add parsetok.h as a dependency - previously, changing this file doesn't cause the right files to be rebuilt. ........ r53401 | thomas.heller | 2007-01-12 21:08:19 +0100 (Fri, 12 Jan 2007) | 3 lines Avoid warnings in the test suite because ctypes.wintypes cannot be imported on non-windows systems. ........ r53402 | thomas.heller | 2007-01-12 21:17:34 +0100 (Fri, 12 Jan 2007) | 6 lines patch #1610795: BSD version of ctypes.util.find_library, by Martin Kammerhofer. release25-maint backport candidate, but the release manager has to decide. ........ r53403 | thomas.heller | 2007-01-12 21:21:53 +0100 (Fri, 12 Jan 2007) | 3 lines patch #1610795: BSD version of ctypes.util.find_library, by Martin Kammerhofer. ........ r53406 | brett.cannon | 2007-01-13 01:29:49 +0100 (Sat, 13 Jan 2007) | 2 lines Deprecate the sets module. ........ r53407 | georg.brandl | 2007-01-13 13:31:51 +0100 (Sat, 13 Jan 2007) | 3 lines Fix typo. ........ r53409 | marc-andre.lemburg | 2007-01-13 22:00:08 +0100 (Sat, 13 Jan 2007) | 16 lines Bump version number and change copyright year. Add new API linux_distribution() which supports reading the full distribution name and also knows how to parse LSB-style release files. Redirect the old dist() API to the new API (using the short distribution name taken from the release file filename). Add branch and revision to _sys_version(). Add work-around for Cygwin to libc_ver(). Add support for IronPython (thanks for Anthony Baxter) and make Jython support more robust. ........ r53410 | neal.norwitz | 2007-01-13 22:22:37 +0100 (Sat, 13 Jan 2007) | 1 line Fix grammar in docstrings ........ r53411 | marc-andre.lemburg | 2007-01-13 23:32:21 +0100 (Sat, 13 Jan 2007) | 9 lines Add parameter sys_version to _sys_version(). Change the cache for _sys_version() to take the parameter into account. Add support for parsing the IronPython 1.0.1 sys.version value - even though it still returns '1.0.0'; the version string no longer includes the patch level. ........ r53412 | peter.astrand | 2007-01-13 23:35:35 +0100 (Sat, 13 Jan 2007) | 1 line Fix for bug #1634343: allow specifying empty arguments on Windows ........ r53414 | marc-andre.lemburg | 2007-01-13 23:59:36 +0100 (Sat, 13 Jan 2007) | 14 lines Add Python implementation to the machine details. Pretty-print the Python version used for running PyBench. Let the user know when calibration has finished. [ 1563844 ] pybench support for IronPython: Simplify Unicode version detection. Make garbage collection and check interval settings optional if the Python implementation doesn't support thess (e.g. IronPython). ........ r53415 | marc-andre.lemburg | 2007-01-14 00:13:54 +0100 (Sun, 14 Jan 2007) | 5 lines Use defaults if sys.executable isn't set (e.g. on Jython). This change allows running PyBench under Jython. ........ r53416 | marc-andre.lemburg | 2007-01-14 00:15:33 +0100 (Sun, 14 Jan 2007) | 3 lines Jython doesn't have sys.setcheckinterval() - ignore it in that case. ........ r53420 | gerhard.haering | 2007-01-14 02:43:50 +0100 (Sun, 14 Jan 2007) | 29 lines Merged changes from standalone version 2.3.3. This should probably all be merged into the 2.5 maintenance branch: - self->statement was not checked while fetching data, which could lead to crashes if you used the pysqlite API in unusual ways. Closing the cursor and continuing to fetch data was enough. - Converters are stored in a converters dictionary. The converter name is uppercased first. The old upper-casing algorithm was wrong and was replaced by a simple call to the Python string's upper() method instead. -Applied patch by Glyph Lefkowitz that fixes the problem with subsequent SQLITE_SCHEMA errors. - Improvement to the row type: rows can now be iterated over and have a keys() method. This improves compatibility with both tuple and dict a lot. - A bugfix for the subsecond resolution in timestamps. - Corrected the way the flags PARSE_DECLTYPES and PARSE_COLNAMES are checked for. Now they work as documented. - gcc on Linux sucks. It exports all symbols by default in shared libraries, so if symbols are not unique it can lead to problems with symbol lookup. pysqlite used to crash under Apache when mod_cache was enabled because both modules had the symbol cache_init. I fixed this by applying the prefix pysqlite_ almost everywhere. Sigh. ........ r53423 | guido.van.rossum | 2007-01-14 04:46:33 +0100 (Sun, 14 Jan 2007) | 2 lines Remove a dependency of this test on $COLUMNS. ........ r53425 | ka-ping.yee | 2007-01-14 05:25:15 +0100 (Sun, 14 Jan 2007) | 3 lines Handle old-style instances more gracefully (display documentation on the relevant class instead of documentation on <type 'instance'>). ........ r53440 | vinay.sajip | 2007-01-14 22:49:59 +0100 (Sun, 14 Jan 2007) | 1 line Added WatchedFileHandler (based on SF patch #1598415) ........ r53441 | vinay.sajip | 2007-01-14 22:50:50 +0100 (Sun, 14 Jan 2007) | 1 line Added documentation for WatchedFileHandler (based on SF patch #1598415) ........ r53442 | guido.van.rossum | 2007-01-15 01:02:35 +0100 (Mon, 15 Jan 2007) | 2 lines Doc patch matching r53434 (htonl etc. now always take/return positive ints). ........
402 lines
14 KiB
C
402 lines
14 KiB
C
/* module.c - the module itself
|
|
*
|
|
* Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de>
|
|
*
|
|
* This file is part of pysqlite.
|
|
*
|
|
* This software is provided 'as-is', without any express or implied
|
|
* warranty. In no event will the authors be held liable for any damages
|
|
* arising from the use of this software.
|
|
*
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
* including commercial applications, and to alter it and redistribute it
|
|
* freely, subject to the following restrictions:
|
|
*
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
* claim that you wrote the original software. If you use this software
|
|
* in a product, an acknowledgment in the product documentation would be
|
|
* appreciated but is not required.
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
* misrepresented as being the original software.
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
*/
|
|
|
|
#include "connection.h"
|
|
#include "statement.h"
|
|
#include "cursor.h"
|
|
#include "cache.h"
|
|
#include "prepare_protocol.h"
|
|
#include "microprotocols.h"
|
|
#include "row.h"
|
|
|
|
#if SQLITE_VERSION_NUMBER >= 3003003
|
|
#define HAVE_SHARED_CACHE
|
|
#endif
|
|
|
|
/* static objects at module-level */
|
|
|
|
PyObject* pysqlite_Error, *pysqlite_Warning, *pysqlite_InterfaceError, *pysqlite_DatabaseError,
|
|
*pysqlite_InternalError, *pysqlite_OperationalError, *pysqlite_ProgrammingError,
|
|
*pysqlite_IntegrityError, *pysqlite_DataError, *pysqlite_NotSupportedError, *pysqlite_OptimizedUnicode;
|
|
|
|
PyObject* converters;
|
|
int _enable_callback_tracebacks;
|
|
|
|
static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
|
|
kwargs)
|
|
{
|
|
/* Python seems to have no way of extracting a single keyword-arg at
|
|
* C-level, so this code is redundant with the one in connection_init in
|
|
* connection.c and must always be copied from there ... */
|
|
|
|
static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL};
|
|
char* database;
|
|
int detect_types = 0;
|
|
PyObject* isolation_level;
|
|
PyObject* factory = NULL;
|
|
int check_same_thread = 1;
|
|
int cached_statements;
|
|
double timeout = 5.0;
|
|
|
|
PyObject* result;
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist,
|
|
&database, &timeout, &detect_types, &isolation_level, &check_same_thread, &factory, &cached_statements))
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
if (factory == NULL) {
|
|
factory = (PyObject*)&pysqlite_ConnectionType;
|
|
}
|
|
|
|
result = PyObject_Call(factory, args, kwargs);
|
|
|
|
return result;
|
|
}
|
|
|
|
static PyObject* module_complete(PyObject* self, PyObject* args, PyObject*
|
|
kwargs)
|
|
{
|
|
static char *kwlist[] = {"statement", NULL, NULL};
|
|
char* statement;
|
|
|
|
PyObject* result;
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &statement))
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
if (sqlite3_complete(statement)) {
|
|
result = Py_True;
|
|
} else {
|
|
result = Py_False;
|
|
}
|
|
|
|
Py_INCREF(result);
|
|
|
|
return result;
|
|
}
|
|
|
|
#ifdef HAVE_SHARED_CACHE
|
|
static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyObject*
|
|
kwargs)
|
|
{
|
|
static char *kwlist[] = {"do_enable", NULL, 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) {
|
|
PyErr_SetString(pysqlite_OperationalError, "Changing the shared_cache flag failed");
|
|
return NULL;
|
|
} else {
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
}
|
|
#endif /* HAVE_SHARED_CACHE */
|
|
|
|
static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObject* kwargs)
|
|
{
|
|
PyTypeObject* type;
|
|
PyObject* caster;
|
|
|
|
if (!PyArg_ParseTuple(args, "OO", &type, &caster)) {
|
|
return NULL;
|
|
}
|
|
|
|
microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster);
|
|
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
|
|
static PyObject* module_register_converter(PyObject* self, PyObject* args, PyObject* kwargs)
|
|
{
|
|
PyObject* orig_name;
|
|
PyObject* name = NULL;
|
|
PyObject* callable;
|
|
PyObject* retval = NULL;
|
|
|
|
if (!PyArg_ParseTuple(args, "SO", &orig_name, &callable)) {
|
|
return NULL;
|
|
}
|
|
|
|
/* convert the name to upper case */
|
|
name = PyObject_CallMethod(orig_name, "upper", "");
|
|
if (!name) {
|
|
goto error;
|
|
}
|
|
|
|
if (PyDict_SetItem(converters, name, callable) != 0) {
|
|
goto error;
|
|
}
|
|
|
|
Py_INCREF(Py_None);
|
|
retval = Py_None;
|
|
error:
|
|
Py_XDECREF(name);
|
|
return retval;
|
|
}
|
|
|
|
static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args, PyObject* kwargs)
|
|
{
|
|
if (!PyArg_ParseTuple(args, "i", &_enable_callback_tracebacks)) {
|
|
return NULL;
|
|
}
|
|
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
|
|
static void converters_init(PyObject* dict)
|
|
{
|
|
converters = PyDict_New();
|
|
if (!converters) {
|
|
return;
|
|
}
|
|
|
|
PyDict_SetItemString(dict, "converters", converters);
|
|
}
|
|
|
|
static PyMethodDef module_methods[] = {
|
|
{"connect", (PyCFunction)module_connect, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Creates a connection.")},
|
|
{"complete_statement", (PyCFunction)module_complete, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Checks if a string contains a complete SQL statement. Non-standard.")},
|
|
#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. Experimental/Non-standard.")},
|
|
#endif
|
|
{"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with pysqlite's adapter registry. Non-standard.")},
|
|
{"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with pysqlite. Non-standard.")},
|
|
{"adapt", (PyCFunction)psyco_microprotocols_adapt, METH_VARARGS, psyco_microprotocols_adapt_doc},
|
|
{"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks, METH_VARARGS, PyDoc_STR("Enable or disable callback functions throwing errors to stderr.")},
|
|
{NULL, NULL}
|
|
};
|
|
|
|
struct _IntConstantPair {
|
|
char* constant_name;
|
|
int constant_value;
|
|
};
|
|
|
|
typedef struct _IntConstantPair IntConstantPair;
|
|
|
|
static IntConstantPair _int_constants[] = {
|
|
{"PARSE_DECLTYPES", PARSE_DECLTYPES},
|
|
{"PARSE_COLNAMES", PARSE_COLNAMES},
|
|
|
|
{"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
|
|
{(char*)NULL, 0}
|
|
};
|
|
|
|
PyMODINIT_FUNC init_sqlite3(void)
|
|
{
|
|
PyObject *module, *dict;
|
|
PyObject *tmp_obj;
|
|
int i;
|
|
|
|
module = Py_InitModule("_sqlite3", module_methods);
|
|
|
|
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)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
Py_INCREF(&pysqlite_ConnectionType);
|
|
PyModule_AddObject(module, "Connection", (PyObject*) &pysqlite_ConnectionType);
|
|
Py_INCREF(&pysqlite_CursorType);
|
|
PyModule_AddObject(module, "Cursor", (PyObject*) &pysqlite_CursorType);
|
|
Py_INCREF(&pysqlite_CacheType);
|
|
PyModule_AddObject(module, "Statement", (PyObject*)&pysqlite_StatementType);
|
|
Py_INCREF(&pysqlite_StatementType);
|
|
PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheType);
|
|
Py_INCREF(&pysqlite_PrepareProtocolType);
|
|
PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pysqlite_PrepareProtocolType);
|
|
Py_INCREF(&pysqlite_RowType);
|
|
PyModule_AddObject(module, "Row", (PyObject*) &pysqlite_RowType);
|
|
|
|
if (!(dict = PyModule_GetDict(module))) {
|
|
goto error;
|
|
}
|
|
|
|
/*** Create DB-API Exception hierarchy */
|
|
|
|
if (!(pysqlite_Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_StandardError, NULL))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "Error", pysqlite_Error);
|
|
|
|
if (!(pysqlite_Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_StandardError, NULL))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "Warning", pysqlite_Warning);
|
|
|
|
/* Error subclasses */
|
|
|
|
if (!(pysqlite_InterfaceError = PyErr_NewException(MODULE_NAME ".InterfaceError", pysqlite_Error, NULL))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "InterfaceError", pysqlite_InterfaceError);
|
|
|
|
if (!(pysqlite_DatabaseError = PyErr_NewException(MODULE_NAME ".DatabaseError", pysqlite_Error, NULL))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "DatabaseError", pysqlite_DatabaseError);
|
|
|
|
/* pysqlite_DatabaseError subclasses */
|
|
|
|
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))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "IntegrityError", pysqlite_IntegrityError);
|
|
|
|
if (!(pysqlite_DataError = PyErr_NewException(MODULE_NAME ".DataError", pysqlite_DatabaseError, NULL))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "DataError", pysqlite_DataError);
|
|
|
|
if (!(pysqlite_NotSupportedError = PyErr_NewException(MODULE_NAME ".NotSupportedError", pysqlite_DatabaseError, NULL))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "NotSupportedError", pysqlite_NotSupportedError);
|
|
|
|
/* We just need "something" unique for pysqlite_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);
|
|
pysqlite_OptimizedUnicode = (PyObject*)&PyCell_Type;
|
|
PyDict_SetItemString(dict, "OptimizedUnicode", pysqlite_OptimizedUnicode);
|
|
|
|
/* Set integer constants */
|
|
for (i = 0; _int_constants[i].constant_name != 0; i++) {
|
|
tmp_obj = PyInt_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 = PyString_FromString(PYSQLITE_VERSION))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "version", tmp_obj);
|
|
Py_DECREF(tmp_obj);
|
|
|
|
if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) {
|
|
goto error;
|
|
}
|
|
PyDict_SetItemString(dict, "sqlite_version", tmp_obj);
|
|
Py_DECREF(tmp_obj);
|
|
|
|
/* initialize microprotocols layer */
|
|
microprotocols_init(dict);
|
|
|
|
/* initialize the default converters */
|
|
converters_init(dict);
|
|
|
|
_enable_callback_tracebacks = 0;
|
|
|
|
/* Original comment form _bsddb.c in the Python core. This is also still
|
|
* needed nowadays for Python 2.3/2.4.
|
|
*
|
|
* PyEval_InitThreads is called here due to a quirk in python 1.5
|
|
* - 2.2.1 (at least) according to Russell Williamson <merel@wt.net>:
|
|
* The global interepreter lock is not initialized until the first
|
|
* thread is created using thread.start_new_thread() or fork() is
|
|
* called. that would cause the ALLOW_THREADS here to segfault due
|
|
* to a null pointer reference if no threads or child processes
|
|
* have been created. This works around that and is a no-op if
|
|
* threads have already been initialized.
|
|
* (see pybsddb-users mailing list post on 2002-08-07)
|
|
*/
|
|
PyEval_InitThreads();
|
|
|
|
error:
|
|
if (PyErr_Occurred())
|
|
{
|
|
PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
|
|
}
|
|
}
|