source: vendor/python/2.5/Modules/_sqlite/module.c@ 3225

Last change on this file since 3225 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 13.2 KB
Line 
1 /* module.c - the module itself
2 *
3 * Copyright (C) 2004-2006 Gerhard Häring <[email protected]>
4 *
5 * This file is part of pysqlite.
6 *
7 * This software is provided 'as-is', without any express or implied
8 * warranty. In no event will the authors be held liable for any damages
9 * arising from the use of this software.
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software. If you use this software
17 * in a product, an acknowledgment in the product documentation would be
18 * appreciated but is not required.
19 * 2. Altered source versions must be plainly marked as such, and must not be
20 * misrepresented as being the original software.
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#include "connection.h"
25#include "statement.h"
26#include "cursor.h"
27#include "cache.h"
28#include "prepare_protocol.h"
29#include "microprotocols.h"
30#include "row.h"
31
32#if SQLITE_VERSION_NUMBER >= 3003003
33#define HAVE_SHARED_CACHE
34#endif
35
36/* static objects at module-level */
37
38PyObject* Error, *Warning, *InterfaceError, *DatabaseError, *InternalError,
39 *OperationalError, *ProgrammingError, *IntegrityError, *DataError,
40 *NotSupportedError, *OptimizedUnicode;
41
42PyObject* converters;
43int _enable_callback_tracebacks;
44
45static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
46 kwargs)
47{
48 /* Python seems to have no way of extracting a single keyword-arg at
49 * C-level, so this code is redundant with the one in connection_init in
50 * connection.c and must always be copied from there ... */
51
52 static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL};
53 char* database;
54 int detect_types = 0;
55 PyObject* isolation_level;
56 PyObject* factory = NULL;
57 int check_same_thread = 1;
58 int cached_statements;
59 double timeout = 5.0;
60
61 PyObject* result;
62
63 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist,
64 &database, &timeout, &detect_types, &isolation_level, &check_same_thread, &factory, &cached_statements))
65 {
66 return NULL;
67 }
68
69 if (factory == NULL) {
70 factory = (PyObject*)&ConnectionType;
71 }
72
73 result = PyObject_Call(factory, args, kwargs);
74
75 return result;
76}
77
78static PyObject* module_complete(PyObject* self, PyObject* args, PyObject*
79 kwargs)
80{
81 static char *kwlist[] = {"statement", NULL, NULL};
82 char* statement;
83
84 PyObject* result;
85
86 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &statement))
87 {
88 return NULL;
89 }
90
91 if (sqlite3_complete(statement)) {
92 result = Py_True;
93 } else {
94 result = Py_False;
95 }
96
97 Py_INCREF(result);
98
99 return result;
100}
101
102#ifdef HAVE_SHARED_CACHE
103static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyObject*
104 kwargs)
105{
106 static char *kwlist[] = {"do_enable", NULL, NULL};
107 int do_enable;
108 int rc;
109
110 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &do_enable))
111 {
112 return NULL;
113 }
114
115 rc = sqlite3_enable_shared_cache(do_enable);
116
117 if (rc != SQLITE_OK) {
118 PyErr_SetString(OperationalError, "Changing the shared_cache flag failed");
119 return NULL;
120 } else {
121 Py_INCREF(Py_None);
122 return Py_None;
123 }
124}
125#endif /* HAVE_SHARED_CACHE */
126
127static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObject* kwargs)
128{