annotate _mysql.c @ 35:e7bd07afbcb9 MySQLdb

Conflict-filled merge from 1.2br for 558:559 set and exception fixes
author kylev
date Thu, 12 Feb 2009 00:23:41 +0000
parents d301c95d8fd7
children 0da42144a012
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
1 #include "_mysql.h"
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
2
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
3 PyObject *_mysql_MySQLError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
4 PyObject *_mysql_Warning;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
5 PyObject *_mysql_Error;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
6 PyObject *_mysql_DatabaseError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
7 PyObject *_mysql_InterfaceError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
8 PyObject *_mysql_DataError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
9 PyObject *_mysql_OperationalError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
10 PyObject *_mysql_IntegrityError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
11 PyObject *_mysql_InternalError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
12 PyObject *_mysql_ProgrammingError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
13 PyObject *_mysql_NotSupportedError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
14 PyObject *_mysql_error_map;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
15
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
16 int _mysql_server_init_done = 0;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
17
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
18 PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
19 _mysql_Exception(_mysql_ConnectionObject *c)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
20 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
21 PyObject *t, *e;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
22 int merr;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
23
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
24 if (!(t = PyTuple_New(2))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
25 if (!_mysql_server_init_done) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
26 e = _mysql_InternalError;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
27 PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
28 PyTuple_SET_ITEM(t, 1, PyString_FromString("server not initialized"));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
29 PyErr_SetObject(e, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
30 Py_DECREF(t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
31 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
32 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
33 merr = mysql_errno(&(c->connection));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
34 if (!merr)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
35 e = _mysql_InterfaceError;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
36 else if (merr > CR_MAX_ERROR) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
37 PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
38 PyTuple_SET_ITEM(t, 1, PyString_FromString("error totally whack"));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
39 PyErr_SetObject(_mysql_InterfaceError, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
40 Py_DECREF(t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
41 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
42 }
8
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
43 else {
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
44 PyObject *py_merr = PyInt_FromLong(merr);
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
45 e = PyDict_GetItem(_mysql_error_map, py_merr);
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
46 Py_DECREF(py_merr);
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
47 if (!e) {
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
48 if (merr < 1000) e = _mysql_InternalError;
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
49 else e = _mysql_OperationalError;
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
50 }
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
51 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
52 PyTuple_SET_ITEM(t, 0, PyInt_FromLong((long)merr));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
53 PyTuple_SET_ITEM(t, 1, PyString_FromString(mysql_error(&(c->connection))));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
54 PyErr_SetObject(e, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
55 Py_DECREF(t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
56 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
57 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
58
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
59 static char _mysql_server_init__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
60 "Initialize embedded server. If this client is not linked against\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
61 the embedded server library, this function does nothing.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
62 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
63 args -- sequence of command-line arguments\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
64 groups -- sequence of groups to use in defaults files\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
65 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
66
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
67 static PyObject *_mysql_server_init(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
68 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
69 PyObject *args,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
70 PyObject *kwargs) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
71 static char *kwlist[] = {"args", "groups", NULL};
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
72 char **cmd_args_c=NULL, **groups_c=NULL, *s;
27
d301c95d8fd7 Apply missing Py_ssize_t conversion caught by spektrum.
kylev
parents: 18
diff changeset
73 Py_ssize_t cmd_argc=0, i, groupc;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
74 PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
75
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
76 if (_mysql_server_init_done) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
77 PyErr_SetString(_mysql_ProgrammingError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
78 "already initialized");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
79 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
80 }
27
d301c95d8fd7 Apply missing Py_ssize_t conversion caught by spektrum.
kylev
parents: 18
diff changeset
81
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
82 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
83 &cmd_args, &groups))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
84 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
85
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
86 #if MYSQL_VERSION_ID >= 40000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
87 if (cmd_args) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
88 if (!PySequence_Check(cmd_args)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
89 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
90 "args must be a sequence");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
91 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
92 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
93 cmd_argc = PySequence_Size(cmd_args);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
94 if (cmd_argc == -1) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
95 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
96 "args could not be sized");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
97 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
98 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
99 cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
100 for (i=0; i< cmd_argc; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
101 item = PySequence_GetItem(cmd_args, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
102 s = PyString_AsString(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
103 Py_DECREF(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
104 if (!s) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
105 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
106 "args must contain strings");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
107 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
108 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
109 cmd_args_c[i] = s;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
110 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
111 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
112 if (groups) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
113 if (!PySequence_Check(groups)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
114 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
115 "groups must be a sequence");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
116 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
117 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
118 groupc = PySequence_Size(groups);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
119 if (groupc == -1) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
120 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
121 "groups could not be sized");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
122 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
123 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
124 groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
125 for (i=0; i< groupc; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
126 item = PySequence_GetItem(groups, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
127 s = PyString_AsString(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
128 Py_DECREF(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
129 if (!s) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
130 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
131 "groups must contain strings");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
132 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
133 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
134 groups_c[i] = s;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
135 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
136 groups_c[groupc] = (char *)NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
137 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
138 /* even though this may block, don't give up the interpreter lock
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
139 so that the server can't be initialized multiple times. */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
140 if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
141 _mysql_Exception(NULL);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
142 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
143 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
144 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
145 ret = Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
146 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
147 _mysql_server_init_done = 1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
148 finish:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
149 PyMem_Free(groups_c);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
150 PyMem_Free(cmd_args_c);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
151 return ret;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
152 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
153
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
154 static char _mysql_server_end__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
155 "Shut down embedded server. If not using an embedded server, this\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
156 does nothing.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
157
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
158 static PyObject *_mysql_server_end(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
159 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
160 PyObject *args) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
161 if (_mysql_server_init_done) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
162 #if MYSQL_VERSION_ID >= 40000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
163 mysql_server_end();
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
164 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
165 _mysql_server_init_done = 0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
166 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
167 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
168 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
169 return _mysql_Exception(NULL);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
170 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
171
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
172 #if MYSQL_VERSION_ID >= 32314
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
173 static char _mysql_thread_safe__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
174 "Indicates whether the client is compiled as thread-safe.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
175
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
176 static PyObject *_mysql_thread_safe(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
177 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
178 PyObject *args) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
179 PyObject *flag;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
180 if (!PyArg_ParseTuple(args, "")) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
181 check_server_init(NULL);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
182 if (!(flag=PyInt_FromLong((long)mysql_thread_safe()))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
183 return flag;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
184 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
185 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
186
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
187 extern char _mysql_connect__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
188 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
189 _mysql_connect(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
190 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
191 PyObject *args,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
192 PyObject *kwargs);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
193
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
194 static char _mysql_debug__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
195 "Does a DBUG_PUSH with the given string.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
196 mysql_debug() uses the Fred Fish debug library.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
197 To use this function, you must compile the client library to\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
198 support debugging.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
199 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
200 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
201 _mysql_debug(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
202 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
203 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
204 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
205 char *debug;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
206 if (!PyArg_ParseTuple(args, "s", &debug)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
207 mysql_debug(debug);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
208 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
209 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
210 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
211
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
212 extern char _mysql_escape_string__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
213 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
214 _mysql_escape_string(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
215 _mysql_ConnectionObject *self,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
216 PyObject *args);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
217
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
218 extern char _mysql_string_literal__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
219 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
220 _mysql_string_literal(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
221 _mysql_ConnectionObject *self,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
222 PyObject *args);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
223
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
224 static PyObject *_mysql_NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
225
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
226 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
227 _escape_item(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
228 PyObject *item,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
229 PyObject *d)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
230 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
231 PyObject *quoted=NULL, *itemtype, *itemconv;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
232 if (!(itemtype = PyObject_Type(item)))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
233 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
234 itemconv = PyObject_GetItem(d, itemtype);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
235 Py_DECREF(itemtype);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
236 if (!itemconv) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
237 PyErr_Clear();
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
238 itemconv = PyObject_GetItem(d,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
239 (PyObject *) &PyString_Type);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
240 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
241 if (!itemconv) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
242 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
243 "no default type converter defined");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
244 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
245 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
246 quoted = PyObject_CallFunction(itemconv, "OO", item, d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
247 Py_DECREF(itemconv);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
248 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
249 return quoted;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
250 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
251
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
252 extern char _mysql_escape__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
253 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
254 _mysql_escape(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
255 PyObject *self,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
256 PyObject *args);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
257
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
258 static char _mysql_escape_sequence__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
259 "escape_sequence(seq, dict) -- escape any special characters in sequence\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
260 seq using mapping dict to provide quoting functions for each type.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
261 Returns a tuple of escaped items.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
262 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
263 _mysql_escape_sequence(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
264 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
265 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
266 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
267 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
268 int i, n;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
269 if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
270 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
271 if (!PyMapping_Check(d)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
272 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
273 "argument 2 must be a mapping");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
274 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
275 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
276 if ((n = PyObject_Length(o)) == -1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
277 if (!(r = PyTuple_New(n))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
278 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
279 item = PySequence_GetItem(o, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
280 if (!item) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
281 quoted = _escape_item(item, d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
282 Py_DECREF(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
283 if (!quoted) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
284 PyTuple_SET_ITEM(r, i, quoted);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
285 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
286 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
287 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
288 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
289 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
290 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
291
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
292 static char _mysql_escape_dict__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
293 "escape_sequence(d, dict) -- escape any special characters in\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
294 dictionary d using mapping dict to provide quoting functions for each type.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
295 Returns a dictionary of escaped items.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
296 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
297 _mysql_escape_dict(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
298 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
299 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
300 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
301 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey;
5
b70cce9bd065 Merge changes from 1.2 branch r456-468
adustman
parents: 4
diff changeset
302 Py_ssize_t ppos = 0;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
303 if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
304 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
305 if (!PyMapping_Check(d)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
306 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
307 "argument 2 must be a mapping");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
308 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
309 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
310 if (!(r = PyDict_New())) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
311 while (PyDict_Next(o, &ppos, &pkey, &item)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
312 quoted = _escape_item(item, d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
313 if (!quoted) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
314 if (PyDict_SetItem(r, pkey, quoted)==-1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
315 Py_DECREF(quoted);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
316 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
317 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
318 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
319 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
320 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
321 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
322
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
323 static char _mysql_get_client_info__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
324 "get_client_info() -- Returns a string that represents\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
325 the client library version.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
326 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
327 _mysql_get_client_info(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
328 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
329 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
330 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
331 if (!PyArg_ParseTuple(args, "")) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
332 check_server_init(NULL);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
333 return PyString_FromString(mysql_get_client_info());
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
334 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
335
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
336 extern PyTypeObject _mysql_ConnectionObject_Type;
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
337 extern PyTypeObject _mysql_ResultObject_Type;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
338
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
339 static PyMethodDef
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
340 _mysql_methods[] = {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
341 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
342 "connect",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
343 (PyCFunction)_mysql_connect,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
344 METH_VARARGS | METH_KEYWORDS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
345 _mysql_connect__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
346 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
347 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
348 "debug",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
349 (PyCFunction)_mysql_debug,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
350 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
351 _mysql_debug__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
352 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
353 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
354 "escape",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
355 (PyCFunction)_mysql_escape,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
356 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
357 _mysql_escape__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
358 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
359 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
360 "escape_sequence",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
361 (PyCFunction)_mysql_escape_sequence,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
362 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
363 _mysql_escape_sequence__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
364 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
365 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
366 "escape_dict",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
367 (PyCFunction)_mysql_escape_dict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
368 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
369 _mysql_escape_dict__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
370 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
371 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
372 "escape_string",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
373 (PyCFunction)_mysql_escape_string,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
374 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
375 _mysql_escape_string__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
376 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
377 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
378 "string_literal",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
379 (PyCFunction)_mysql_string_literal,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
380 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
381 _mysql_string_literal__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
382 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
383 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
384 "get_client_info",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
385 (PyCFunction)_mysql_get_client_info,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
386 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
387 _mysql_get_client_info__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
388 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
389 #if MYSQL_VERSION_ID >= 32314
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
390 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
391 "thread_safe",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
392 (PyCFunction)_mysql_thread_safe,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
393 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
394 _mysql_thread_safe__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
395 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
396 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
397 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
398 "server_init",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
399 (PyCFunction)_mysql_server_init,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
400 METH_VARARGS | METH_KEYWORDS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
401 _mysql_server_init__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
402 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
403 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
404 "server_end",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
405 (PyCFunction)_mysql_server_end,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
406 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
407 _mysql_server_end__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
408 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
409 {NULL, NULL} /* sentinel */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
410 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
411
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
412 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
413 _mysql_NewException(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
414 PyObject *dict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
415 PyObject *edict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
416 char *name)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
417 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
418 PyObject *e;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
419
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
420 if (!(e = PyDict_GetItemString(edict, name)))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
421 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
422 if (PyDict_SetItemString(dict, name, e)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
423 return e;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
424 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
425
4
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
426 #define QUOTE(X) _QUOTE(X)
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
427 #define _QUOTE(X) #X
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
428
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
429 static char _mysql___doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
430 "an adaptation of the MySQL C API (mostly)\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
431 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
432 You probably are better off using MySQLdb instead of using this\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
433 module directly.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
434 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
435 In general, renaming goes from mysql_* to _mysql.*. _mysql.connect()\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
436 returns a connection object (MYSQL). Functions which expect MYSQL * as\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
437 an argument are now methods of the connection object. A number of things\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
438 return result objects (MYSQL_RES). Functions which expect MYSQL_RES * as\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
439 an argument are now methods of the result object. Deprecated functions\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
440 (as of 3.23) are NOT implemented.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
441 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
442
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
443 DL_EXPORT(void)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
444 init_mysql(void)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
445 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
446 PyObject *dict, *module, *emod, *edict;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
447 module = Py_InitModule4("_mysql", _mysql_methods, _mysql___doc__,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
448 (PyObject *)NULL, PYTHON_API_VERSION);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
449 if (!module) return; /* this really should never happen */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
450 _mysql_ConnectionObject_Type.ob_type = &PyType_Type;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
451 _mysql_ResultObject_Type.ob_type = &PyType_Type;
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
452 _mysql_FieldObject_Type.ob_type = &PyType_Type;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
453 #if PY_VERSION_HEX >= 0x02020000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
454 _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
455 _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
456 _mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
457 _mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
458 _mysql_ResultObject_Type.tp_new = PyType_GenericNew;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
459 _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del;
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
460 _mysql_FieldObject_Type.tp_alloc = PyType_GenericAlloc;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
461 _mysql_FieldObject_Type.tp_new = PyType_GenericNew;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
462 _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
463 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
464
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
465 if (!(dict = PyModule_GetDict(module))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
466 if (PyDict_SetItemString(dict, "version_info",
4
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
467 PyRun_String(QUOTE(version_info), Py_eval_input,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
468 dict, dict)))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
469 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
470 if (PyDict_SetItemString(dict, "__version__",
4
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
471 PyString_FromString(QUOTE(__version__))))
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
472 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
473 if (PyDict_SetItemString(dict, "connection",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
474 (PyObject *)&_mysql_ConnectionObject_Type))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
475 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
476 Py_INCREF(&_mysql_ConnectionObject_Type);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
477 if (PyDict_SetItemString(dict, "result",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
478 (PyObject *)&_mysql_ResultObject_Type))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
479 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
480 Py_INCREF(&_mysql_ResultObject_Type);
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
481 if (PyDict_SetItemString(dict, "field",
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
482 (PyObject *)&_mysql_FieldObject_Type))
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
483 goto error;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
484 Py_INCREF(&_mysql_FieldObject_Type);
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
485 if (!(emod = PyImport_ImportModule("MySQLdb.exceptions")))
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
486 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
487 if (!(edict = PyModule_GetDict(emod))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
488 if (!(_mysql_MySQLError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
489 _mysql_NewException(dict, edict, "MySQLError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
490 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
491 if (!(_mysql_Warning =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
492 _mysql_NewException(dict, edict, "Warning")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
493 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
494 if (!(_mysql_Error =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
495 _mysql_NewException(dict, edict, "Error")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
496 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
497 if (!(_mysql_InterfaceError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
498 _mysql_NewException(dict, edict, "InterfaceError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
499 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
500 if (!(_mysql_DatabaseError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
501 _mysql_NewException(dict, edict, "DatabaseError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
502 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
503 if (!(_mysql_DataError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
504 _mysql_NewException(dict, edict, "DataError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
505 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
506 if (!(_mysql_OperationalError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
507 _mysql_NewException(dict, edict, "OperationalError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
508 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
509 if (!(_mysql_IntegrityError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
510 _mysql_NewException(dict, edict, "IntegrityError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
511 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
512 if (!(_mysql_InternalError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
513 _mysql_NewException(dict, edict, "InternalError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
514 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
515 if (!(_mysql_ProgrammingError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
516 _mysql_NewException(dict, edict, "ProgrammingError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
517 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
518 if (!(_mysql_NotSupportedError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
519 _mysql_NewException(dict, edict, "NotSupportedError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
520 goto error;
8
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
521 if (!(_mysql_error_map = PyDict_GetItemString(edict, "error_map")))
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
522 goto error;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
523 Py_DECREF(emod);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
524 if (!(_mysql_NULL = PyString_FromString("NULL")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
525 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
526 if (PyDict_SetItemString(dict, "NULL", _mysql_NULL)) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
527 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
528 if (PyErr_Occurred())
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
529 PyErr_SetString(PyExc_ImportError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
530 "_mysql: init failed");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
531 return;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
532 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
533
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
534