Mercurial > p > mysql-python > mysqldb-2
annotate src/connections.c @ 69:18e5892a5aed MySQLdb
Defer incrementing reference to the decoder stack until later so we don't have to
dec-ref if an error happens. Merge of change 630 on 1.2br.
author | kylev |
---|---|
date | Fri, 24 Jul 2009 00:27:38 +0000 |
parents | 98d968f5af11 |
children | f06381a47ab0 |
rev | line source |
---|---|
29 | 1 /* -*- mode: C; indent-tabs-mode: t; c-basic-offset: 8; -*- */ |
2 | |
55
e606fd52e866
make things a little cleaner by moving to a src directory for the C code
kylev
parents:
42
diff
changeset
|
3 #include "mysqlmod.h" |
0 | 4 |
5 static int | |
6 _mysql_ConnectionObject_Initialize( | |
7 _mysql_ConnectionObject *self, | |
8 PyObject *args, | |
9 PyObject *kwargs) | |
10 { | |
11 MYSQL *conn = NULL; | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
12 PyObject *decoder_stack = NULL; |
0 | 13 PyObject *ssl = NULL; |
14 #if HAVE_OPENSSL | |
15 char *key = NULL, *cert = NULL, *ca = NULL, | |
16 *capath = NULL, *cipher = NULL; | |
17 #endif | |
18 char *host = NULL, *user = NULL, *passwd = NULL, | |
19 *db = NULL, *unix_socket = NULL; | |
21 | 20 unsigned int port = 0; |
21 unsigned int client_flag = 0; | |
0 | 22 static char *kwlist[] = { "host", "user", "passwd", "db", "port", |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
23 "unix_socket", "decoder_stack", |
0 | 24 "connect_timeout", "compress", |
25 "named_pipe", "init_command", | |
26 "read_default_file", "read_default_group", | |
27 "client_flag", "ssl", | |
28 "local_infile", | |
29 NULL } ; | |
30 int connect_timeout = 0; | |
31 int compress = -1, named_pipe = -1, local_infile = -1; | |
32 char *init_command=NULL, | |
33 *read_default_file=NULL, | |
34 *read_default_group=NULL; | |
35 | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
36 self->decoder_stack = NULL; |
0 | 37 self->open = 0; |
38 check_server_init(-1); | |
39 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ssssisOiiisssiOi:connect", | |
40 kwlist, | |
41 &host, &user, &passwd, &db, | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
42 &port, &unix_socket, &decoder_stack, |
0 | 43 &connect_timeout, |
44 &compress, &named_pipe, | |
45 &init_command, &read_default_file, | |
46 &read_default_group, | |
47 &client_flag, &ssl, | |
48 &local_infile | |
49 )) | |
50 return -1; | |
51 | |
52 #define _stringsuck(d,t,s) {t=PyMapping_GetItemString(s,#d);\ | |
53 if(t){d=PyString_AsString(t);Py_DECREF(t);}\ | |
54 PyErr_Clear();} | |
55 | |
56 if (ssl) { | |
57 #if HAVE_OPENSSL | |
58 PyObject *value = NULL; | |
59 _stringsuck(ca, value, ssl); | |
60 _stringsuck(capath, value, ssl); | |
61 _stringsuck(cert, value, ssl); | |
62 _stringsuck(key, value, ssl); | |
63 _stringsuck(cipher, value, ssl); | |
64 #else | |
65 PyErr_SetString(_mysql_NotSupportedError, | |
66 "client library does not have SSL support"); | |
67 return -1; | |
68 #endif | |
69 } | |
70 | |
71 Py_BEGIN_ALLOW_THREADS ; | |
72 conn = mysql_init(&(self->connection)); | |
73 if (connect_timeout) { | |
74 unsigned int timeout = connect_timeout; | |
75 mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT, | |
76 (char *)&timeout); | |
77 } | |
78 if (compress != -1) { | |
79 mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0); | |
80 client_flag |= CLIENT_COMPRESS; | |
81 } | |
82 if (named_pipe != -1) | |
83 mysql_options(&(self->connection), MYSQL_OPT_NAMED_PIPE, 0); | |
84 if (init_command != NULL) | |
85 mysql_options(&(self->connection), MYSQL_INIT_COMMAND, init_command); | |
86 if (read_default_file != NULL) | |
87 mysql_options(&(self->connection), MYSQL_READ_DEFAULT_FILE, read_default_file); | |
88 if (read_default_group != NULL) | |
89 mysql_options(&(self->connection), MYSQL_READ_DEFAULT_GROUP, read_default_group); | |
90 | |
91 if (local_infile != -1) | |
92 mysql_options(&(self->connection), MYSQL_OPT_LOCAL_INFILE, (char *) &local_infile); | |
93 | |
94 #if HAVE_OPENSSL | |
95 if (ssl) | |
96 mysql_ssl_set(&(self->connection), | |
97 key, cert, ca, capath, cipher); | |
98 #endif | |
99 | |
100 conn = mysql_real_connect(&(self->connection), host, user, passwd, db, | |
101 port, unix_socket, client_flag); | |
102 | |
103 Py_END_ALLOW_THREADS ; | |
104 | |
105 if (!conn) { | |
106 _mysql_Exception(self); | |
107 return -1; | |
108 } | |
69
18e5892a5aed
Defer incrementing reference to the decoder stack until later so we don't have to
kylev
parents:
67
diff
changeset
|
109 |
18e5892a5aed
Defer incrementing reference to the decoder stack until later so we don't have to
kylev
parents:
67
diff
changeset
|
110 if (!decoder_stack) |
18e5892a5aed
Defer incrementing reference to the decoder stack until later so we don't have to
kylev
parents:
67
diff
changeset
|
111 decoder_stack = PyList_New(0); |
18e5892a5aed
Defer incrementing reference to the decoder stack until later so we don't have to
kylev
parents:
67
diff
changeset
|
112 else |
18e5892a5aed
Defer incrementing reference to the decoder stack until later so we don't have to
kylev
parents:
67
diff
changeset
|
113 Py_INCREF(decoder_stack); |
18e5892a5aed
Defer incrementing reference to the decoder stack until later so we don't have to
kylev
parents:
67
diff
changeset
|
114 self->decoder_stack = decoder_stack; |
18e5892a5aed
Defer incrementing reference to the decoder stack until later so we don't have to
kylev
parents:
67
diff
changeset
|
115 |
0 | 116 /* |
117 PyType_GenericAlloc() automatically sets up GC allocation and | |
118 tracking for GC objects, at least in 2.2.1, so it does not need to | |
119 be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(), | |
120 however. | |
121 */ | |
122 self->open = 1; | |
123 return 0; | |
124 } | |
125 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
126 char _mysql_connect__doc__[] = |
0 | 127 "Returns a MYSQL connection object. Exclusive use of\n\ |
128 keyword parameters strongly recommended. Consult the\n\ | |
129 MySQL C API documentation for more details.\n\ | |
130 \n\ | |
131 host\n\ | |
132 string, host to connect\n\ | |
133 \n\ | |
134 user\n\ | |
135 string, user to connect as\n\ | |
136 \n\ | |
137 passwd\n\ | |
138 string, password to use\n\ | |
139 \n\ | |
140 db\n\ | |
141 string, database to use\n\ | |
142 \n\ | |
143 port\n\ | |
144 integer, TCP/IP port to connect to\n\ | |
145 \n\ | |
146 unix_socket\n\ | |
147 string, location of unix_socket (UNIX-ish only)\n\ | |
148 \n\ | |
149 connect_timeout\n\ | |
150 number of seconds to wait before the connection\n\ | |
151 attempt fails.\n\ | |
152 \n\ | |
153 compress\n\ | |
154 if set, gzip compression is enabled\n\ | |
155 \n\ | |
156 named_pipe\n\ | |
157 if set, connect to server via named pipe (Windows only)\n\ | |
158 \n\ | |
159 init_command\n\ | |
160 command which is run once the connection is created\n\ | |
161 \n\ | |
162 read_default_file\n\ | |
163 see the MySQL documentation for mysql_options()\n\ | |
164 \n\ | |
165 read_default_group\n\ | |
166 see the MySQL documentation for mysql_options()\n\ | |
167 \n\ | |
168 client_flag\n\ | |
169 client flags from MySQLdb.constants.CLIENT\n\ | |
170 \n\ | |
171 load_infile\n\ | |
172 int, non-zero enables LOAD LOCAL INFILE, zero disables\n\ | |
173 \n\ | |
174 "; | |
175 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
176 PyObject * |
0 | 177 _mysql_connect( |
178 PyObject *self, | |
179 PyObject *args, | |
180 PyObject *kwargs) | |
181 { | |
182 _mysql_ConnectionObject *c=NULL; | |
183 | |
184 c = MyAlloc(_mysql_ConnectionObject, _mysql_ConnectionObject_Type); | |
185 if (c == NULL) return NULL; | |
186 if (_mysql_ConnectionObject_Initialize(c, args, kwargs)) { | |
187 Py_DECREF(c); | |
188 c = NULL; | |
189 } | |
190 return (PyObject *) c; | |
191 } | |
192 | |
193 static int _mysql_ConnectionObject_traverse( | |
194 _mysql_ConnectionObject *self, | |
195 visitproc visit, | |
196 void *arg) | |
197 { | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
198 if (self->decoder_stack) |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
199 return visit(self->decoder_stack, arg); |
0 | 200 return 0; |
201 } | |
202 | |
203 static int _mysql_ConnectionObject_clear( | |
204 _mysql_ConnectionObject *self) | |
205 { | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
206 Py_XDECREF(self->decoder_stack); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
207 self->decoder_stack = NULL; |
0 | 208 return 0; |
209 } | |
210 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
211 extern PyObject * |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
212 _escape_item( |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
213 PyObject *item, |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
214 PyObject *d); |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
215 |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
216 char _mysql_escape_string__doc__[] = |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
217 "escape_string(s) -- quote any SQL-interpreted characters in string s.\n\ |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
218 If you want quotes around your value, use string_literal(s) instead.\n\ |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
219 "; |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
220 |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
221 PyObject * |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
222 _mysql_escape_string( |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
223 _mysql_ConnectionObject *self, |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
224 PyObject *args) |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
225 { |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
226 PyObject *str; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
227 char *in, *out; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
228 int len, size; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
229 if (!PyArg_ParseTuple(args, "s#:escape_string", &in, &size)) return NULL; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
230 str = PyString_FromStringAndSize((char *) NULL, size*2+1); |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
231 if (!str) return PyErr_NoMemory(); |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
232 out = PyString_AS_STRING(str); |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
233 len = mysql_real_escape_string(&(self->connection), out, in, size); |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
234 if (_PyString_Resize(&str, len) < 0) return NULL; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
235 return (str); |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
236 } |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
237 |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
238 char _mysql_string_literal__doc__[] = |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
239 "string_literal(s) -- converts string s into a SQL string literal.\n\ |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
240 This means, any special SQL characters are escaped, and it is enclosed\n\ |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
241 within single quotes. In other words, it performs:\n\ |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
242 \n\ |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
243 \"'%s'\" % escape_string(s)\n\ |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
244 "; |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
245 |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
246 PyObject * |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
247 _mysql_string_literal( |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
248 _mysql_ConnectionObject *self, |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
249 PyObject *args) |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
250 { |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
251 PyObject *str; |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
252 char *in, *out; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
253 int len, size; |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
254 if (!PyArg_ParseTuple(args, "s#:string_literal", &in, &size)) return NULL; |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
255 str = PyString_FromStringAndSize((char *) NULL, size*2+3); |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
256 if (!str) return PyErr_NoMemory(); |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
257 out = PyString_AS_STRING(str); |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
258 len = mysql_real_escape_string(&(self->connection), out+1, in, size); |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
259 *out = *(out+len+1) = '\''; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
260 if (_PyString_Resize(&str, len+2) < 0) return NULL; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
261 return (str); |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
262 } |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
263 |
0 | 264 static char _mysql_ConnectionObject_close__doc__[] = |
265 "Close the connection. No further activity possible."; | |
266 | |
267 static PyObject * | |
268 _mysql_ConnectionObject_close( | |
269 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
270 PyObject *unused) |
0 | 271 { |
272 if (self->open) { | |
273 Py_BEGIN_ALLOW_THREADS | |
274 mysql_close(&(self->connection)); | |
275 Py_END_ALLOW_THREADS | |
276 self->open = 0; | |
277 } else { | |
278 PyErr_SetString(_mysql_ProgrammingError, | |
279 "closing a closed connection"); | |
280 return NULL; | |
281 } | |
282 _mysql_ConnectionObject_clear(self); | |
283 Py_INCREF(Py_None); | |
284 return Py_None; | |
285 } | |
286 | |
287 static char _mysql_ConnectionObject_affected_rows__doc__ [] = | |
288 "Return number of rows affected by the last query.\n\ | |
289 Non-standard. Use Cursor.rowcount.\n\ | |
290 "; | |
291 | |
292 static PyObject * | |
293 _mysql_ConnectionObject_affected_rows( | |
294 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
295 PyObject *unused) |
0 | 296 { |
297 check_connection(self); | |
298 return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection))); | |
299 } | |
300 | |
301 static char _mysql_ConnectionObject_dump_debug_info__doc__[] = | |
302 "Instructs the server to write some debug information to the\n\ | |
303 log. The connected user must have the process privilege for\n\ | |
304 this to work. Non-standard.\n\ | |
305 "; | |
306 | |
307 static PyObject * | |
308 _mysql_ConnectionObject_dump_debug_info( | |
309 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
310 PyObject *unused) |
0 | 311 { |
312 int err; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
313 |
0 | 314 check_connection(self); |
315 Py_BEGIN_ALLOW_THREADS | |
316 err = mysql_dump_debug_info(&(self->connection)); | |
317 Py_END_ALLOW_THREADS | |
318 if (err) return _mysql_Exception(self); | |
319 Py_INCREF(Py_None); | |
320 return Py_None; | |
321 } | |
322 | |
323 static char _mysql_ConnectionObject_autocommit__doc__[] = | |
324 "Set the autocommit mode. True values enable; False value disable.\n\ | |
325 "; | |
326 static PyObject * | |
327 _mysql_ConnectionObject_autocommit( | |
328 _mysql_ConnectionObject *self, | |
329 PyObject *args) | |
330 { | |
331 int flag, err; | |
332 if (!PyArg_ParseTuple(args, "i", &flag)) return NULL; | |
333 Py_BEGIN_ALLOW_THREADS | |
334 #if MYSQL_VERSION_ID >= 40100 | |
335 err = mysql_autocommit(&(self->connection), flag); | |
336 #else | |
337 { | |
338 char query[256]; | |
339 snprintf(query, 256, "SET AUTOCOMMIT=%d", flag); | |
340 err = mysql_query(&(self->connection), query); | |
341 } | |
342 #endif | |
343 Py_END_ALLOW_THREADS | |
344 if (err) return _mysql_Exception(self); | |
345 Py_INCREF(Py_None); | |
346 return Py_None; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
347 } |
0 | 348 |
349 static char _mysql_ConnectionObject_commit__doc__[] = | |
350 "Commits the current transaction\n\ | |
351 "; | |
352 static PyObject * | |
353 _mysql_ConnectionObject_commit( | |
354 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
355 PyObject *unused) |
0 | 356 { |
357 int err; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
358 |
0 | 359 Py_BEGIN_ALLOW_THREADS |
360 #if MYSQL_VERSION_ID >= 40100 | |
361 err = mysql_commit(&(self->connection)); | |
362 #else | |
363 err = mysql_query(&(self->connection), "COMMIT"); | |
364 #endif | |
365 Py_END_ALLOW_THREADS | |
366 if (err) return _mysql_Exception(self); | |
367 Py_INCREF(Py_None); | |
368 return Py_None; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
369 } |
0 | 370 |
371 static char _mysql_ConnectionObject_rollback__doc__[] = | |
372 "Rolls backs the current transaction\n\ | |
373 "; | |
374 static PyObject * | |
375 _mysql_ConnectionObject_rollback( | |
376 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
377 PyObject *unused) |
0 | 378 { |
379 int err; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
380 |
0 | 381 Py_BEGIN_ALLOW_THREADS |
382 #if MYSQL_VERSION_ID >= 40100 | |
383 err = mysql_rollback(&(self->connection)); | |
384 #else | |
385 err = mysql_query(&(self->connection), "ROLLBACK"); | |
386 #endif | |
387 Py_END_ALLOW_THREADS | |
388 if (err) return _mysql_Exception(self); | |
389 Py_INCREF(Py_None); | |
390 return Py_None; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
391 } |
0 | 392 |
393 static char _mysql_ConnectionObject_next_result__doc__[] = | |
394 "If more query results exist, next_result() reads the next query\n\ | |
395 results and returns the status back to application.\n\ | |
396 \n\ | |
397 After calling next_result() the state of the connection is as if\n\ | |
398 you had called query() for the next query. This means that you can\n\ | |
399 now call store_result(), warning_count(), affected_rows()\n\ | |
400 , and so forth. \n\ | |
401 \n\ | |
402 Returns 0 if there are more results; -1 if there are no more results\n\ | |
403 \n\ | |
404 Non-standard.\n\ | |
405 "; | |
406 static PyObject * | |
407 _mysql_ConnectionObject_next_result( | |
408 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
409 PyObject *unused) |
0 | 410 { |
411 int err; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
412 |
0 | 413 Py_BEGIN_ALLOW_THREADS |
414 #if MYSQL_VERSION_ID >= 40100 | |
415 err = mysql_next_result(&(self->connection)); | |
416 #else | |
417 err = -1; | |
418 #endif | |
419 Py_END_ALLOW_THREADS | |
420 if (err > 0) return _mysql_Exception(self); | |
421 return PyInt_FromLong(err); | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
422 } |
0 | 423 |
424 #if MYSQL_VERSION_ID >= 40100 | |
425 | |
426 static char _mysql_ConnectionObject_set_server_option__doc__[] = | |
427 "set_server_option(option) -- Enables or disables an option\n\ | |
428 for the connection.\n\ | |
429 \n\ | |
430 Non-standard.\n\ | |
431 "; | |
432 static PyObject * | |
433 _mysql_ConnectionObject_set_server_option( | |
434 _mysql_ConnectionObject *self, | |
435 PyObject *args) | |
436 { | |
437 int err, flags=0; | |
438 if (!PyArg_ParseTuple(args, "i", &flags)) | |
439 return NULL; | |
440 Py_BEGIN_ALLOW_THREADS | |
441 err = mysql_set_server_option(&(self->connection), flags); | |
442 Py_END_ALLOW_THREADS | |
443 if (err) return _mysql_Exception(self); | |
444 return PyInt_FromLong(err); | |
445 } | |
446 | |
447 static char _mysql_ConnectionObject_sqlstate__doc__[] = | |
448 "Returns a string containing the SQLSTATE error code\n\ | |
449 for the last error. The error code consists of five characters.\n\ | |
450 '00000' means \"no error.\" The values are specified by ANSI SQL\n\ | |
451 and ODBC. For a list of possible values, see section 23\n\ | |
452 Error Handling in MySQL in the MySQL Manual.\n\ | |
453 \n\ | |
454 Note that not all MySQL errors are yet mapped to SQLSTATE's.\n\ | |
455 The value 'HY000' (general error) is used for unmapped errors.\n\ | |
456 \n\ | |
457 Non-standard.\n\ | |
458 "; | |
459 static PyObject * | |
460 _mysql_ConnectionObject_sqlstate( | |
461 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
462 PyObject *unused) |
0 | 463 { |
464 return PyString_FromString(mysql_sqlstate(&(self->connection))); | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
465 } |
0 | 466 |
467 static char _mysql_ConnectionObject_warning_count__doc__[] = | |
468 "Returns the number of warnings generated during execution\n\ | |
469 of the previous SQL statement.\n\ | |
470 \n\ | |
471 Non-standard.\n\ | |
472 "; | |
473 static PyObject * | |
474 _mysql_ConnectionObject_warning_count( | |
475 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
476 PyObject *unused) |
0 | 477 { |
478 return PyInt_FromLong(mysql_warning_count(&(self->connection))); | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
479 } |
0 | 480 |
481 #endif | |
482 | |
483 static char _mysql_ConnectionObject_errno__doc__[] = | |
484 "Returns the error code for the most recently invoked API function\n\ | |
485 that can succeed or fail. A return value of zero means that no error\n\ | |
486 occurred.\n\ | |
487 "; | |
488 | |
489 static PyObject * | |
490 _mysql_ConnectionObject_errno( | |
491 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
492 PyObject *unused) |
0 | 493 { |
494 check_connection(self); | |
495 return PyInt_FromLong((long)mysql_errno(&(self->connection))); | |
496 } | |
497 | |
498 static char _mysql_ConnectionObject_error__doc__[] = | |
499 "Returns the error message for the most recently invoked API function\n\ | |
500 that can succeed or fail. An empty string ("") is returned if no error\n\ | |
501 occurred.\n\ | |
502 "; | |
503 | |
504 static PyObject * | |
505 _mysql_ConnectionObject_error( | |
506 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
507 PyObject *unused) |
0 | 508 { |
509 check_connection(self); | |
510 return PyString_FromString(mysql_error(&(self->connection))); | |
511 } | |
512 | |
513 #if MYSQL_VERSION_ID >= 32303 | |
514 | |
515 static char _mysql_ConnectionObject_change_user__doc__[] = | |
516 "Changes the user and causes the database specified by db to\n\ | |
517 become the default (current) database on the connection\n\ | |
518 specified by mysql. In subsequent queries, this database is\n\ | |
519 the default for table references that do not include an\n\ | |
520 explicit database specifier.\n\ | |
521 \n\ | |
522 This function was introduced in MySQL Version 3.23.3.\n\ | |
523 \n\ | |
524 Fails unless the connected user can be authenticated or if he\n\ | |
525 doesn't have permission to use the database. In this case the\n\ | |
526 user and database are not changed.\n\ | |
527 \n\ | |
528 The db parameter may be set to None if you don't want to have\n\ | |
529 a default database.\n\ | |
530 "; | |
531 | |
532 static PyObject * | |
533 _mysql_ConnectionObject_change_user( | |
534 _mysql_ConnectionObject *self, | |
535 PyObject *args, | |
536 PyObject *kwargs) | |
537 { | |
538 char *user, *pwd=NULL, *db=NULL; | |
539 int r; | |
540 static char *kwlist[] = { "user", "passwd", "db", NULL } ; | |
541 | |
542 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ss:change_user", | |
543 kwlist, &user, &pwd, &db)) | |
544 return NULL; | |
545 check_connection(self); | |
546 Py_BEGIN_ALLOW_THREADS | |
547 r = mysql_change_user(&(self->connection), user, pwd, db); | |
548 Py_END_ALLOW_THREADS | |
549 if (r) return _mysql_Exception(self); | |
550 Py_INCREF(Py_None); | |
551 return Py_None; | |
552 } | |
553 #endif | |
554 | |
555 static char _mysql_ConnectionObject_character_set_name__doc__[] = | |
556 "Returns the default character set for the current connection.\n\ | |
557 Non-standard.\n\ | |
558 "; | |
559 | |
560 static PyObject * | |
561 _mysql_ConnectionObject_character_set_name( | |
562 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
563 PyObject *unused) |
0 | 564 { |
565 const char *s; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
566 |
0 | 567 check_connection(self); |
568 #if MYSQL_VERSION_ID >= 32321 | |
569 s = mysql_character_set_name(&(self->connection)); | |
570 #else | |
571 s = "latin1"; | |
572 #endif | |
573 return PyString_FromString(s); | |
574 } | |
575 | |
576 #if MYSQL_VERSION_ID >= 50007 | |
577 static char _mysql_ConnectionObject_set_character_set__doc__[] = | |
578 "Sets the default character set for the current connection.\n\ | |
579 Non-standard.\n\ | |
580 "; | |
581 | |
582 static PyObject * | |
583 _mysql_ConnectionObject_set_character_set( | |
584 _mysql_ConnectionObject *self, | |
585 PyObject *args) | |
586 { | |
587 const char *s; | |
588 int err; | |
589 if (!PyArg_ParseTuple(args, "s", &s)) return NULL; | |
590 check_connection(self); | |
591 Py_BEGIN_ALLOW_THREADS | |
592 err = mysql_set_character_set(&(self->connection), s); | |
593 Py_END_ALLOW_THREADS | |
594 if (err) return _mysql_Exception(self); | |
595 Py_INCREF(Py_None); | |
596 return Py_None; | |
597 } | |
598 #endif | |
599 | |
600 #if MYSQL_VERSION_ID >= 50010 | |
601 static char _mysql_ConnectionObject_get_character_set_info__doc__[] = | |
602 "Returns a dict with information about the current character set:\n\ | |
603 \n\ | |
604 collation\n\ | |
605 collation name\n\ | |
606 name\n\ | |
607 character set name\n\ | |
608 comment\n\ | |
609 comment or descriptive name\n\ | |
610 dir\n\ | |
611 character set directory\n\ | |
612 mbminlen\n\ | |
613 min. length for multibyte string\n\ | |
614 mbmaxlen\n\ | |
615 max. length for multibyte string\n\ | |
616 \n\ | |
617 Not all keys may be present, particularly dir.\n\ | |
618 \n\ | |
619 Non-standard.\n\ | |
620 "; | |
621 | |
622 static PyObject * | |
623 _mysql_ConnectionObject_get_character_set_info( | |
624 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
625 PyObject *unused) |
0 | 626 { |
627 PyObject *result; | |
628 MY_CHARSET_INFO cs; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
629 |
0 | 630 check_connection(self); |
631 mysql_get_character_set_info(&(self->connection), &cs); | |
632 if (!(result = PyDict_New())) return NULL; | |
633 if (cs.csname) | |
634 PyDict_SetItemString(result, "name", PyString_FromString(cs.csname)); | |
635 if (cs.name) | |
636 PyDict_SetItemString(result, "collation", PyString_FromString(cs.name)); | |
637 if (cs.comment) | |
638 PyDict_SetItemString(result, "comment", PyString_FromString(cs.comment)); | |
639 if (cs.dir) | |
640 PyDict_SetItemString(result, "dir", PyString_FromString(cs.dir)); | |
641 PyDict_SetItemString(result, "mbminlen", PyInt_FromLong(cs.mbminlen)); | |
642 PyDict_SetItemString(result, "mbmaxlen", PyInt_FromLong(cs.mbmaxlen)); | |
643 return result; | |
644 } | |
645 #endif | |
646 | |
647 static char _mysql_ConnectionObject_get_host_info__doc__[] = | |
648 "Returns a string that represents the MySQL client library\n\ | |
649 version. Non-standard.\n\ | |
650 "; | |
651 | |
652 static PyObject * | |
653 _mysql_ConnectionObject_get_host_info( | |
654 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
655 PyObject *unused) |
0 | 656 { |
657 check_connection(self); | |
658 return PyString_FromString(mysql_get_host_info(&(self->connection))); | |
659 } | |
660 | |
661 static char _mysql_ConnectionObject_get_proto_info__doc__[] = | |
662 "Returns an unsigned integer representing the protocol version\n\ | |
663 used by the current connection. Non-standard.\n\ | |
664 "; | |
665 | |
666 static PyObject * | |
667 _mysql_ConnectionObject_get_proto_info( | |
668 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
669 PyObject *unused) |
0 | 670 { |
671 check_connection(self); | |
672 return PyInt_FromLong((long)mysql_get_proto_info(&(self->connection))); | |
673 } | |
674 | |
675 static char _mysql_ConnectionObject_get_server_info__doc__[] = | |
676 "Returns a string that represents the server version number.\n\ | |
677 Non-standard.\n\ | |
678 "; | |
679 | |
680 static PyObject * | |
681 _mysql_ConnectionObject_get_server_info( | |
682 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
683 PyObject *unused) |
0 | 684 { |
685 check_connection(self); | |
686 return PyString_FromString(mysql_get_server_info(&(self->connection))); | |
687 } | |
688 | |
689 static char _mysql_ConnectionObject_info__doc__[] = | |
690 "Retrieves a string providing information about the most\n\ | |
691 recently executed query. Non-standard. Use messages or\n\ | |
692 Cursor.messages.\n\ | |
693 "; | |
694 | |
695 static PyObject * | |
696 _mysql_ConnectionObject_info( | |
697 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
698 PyObject *unused) |
0 | 699 { |
700 const char *s; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
701 |
0 | 702 check_connection(self); |
703 s = mysql_info(&(self->connection)); | |
704 if (s) return PyString_FromString(s); | |
705 Py_INCREF(Py_None); | |
706 return Py_None; | |
707 } | |
708 | |
709 static char _mysql_ConnectionObject_insert_id__doc__[] = | |
710 "Returns the ID generated for an AUTO_INCREMENT column by the previous\n\ | |
711 query. Use this function after you have performed an INSERT query into a\n\ | |
712 table that contains an AUTO_INCREMENT field.\n\ | |
713 \n\ | |
714 Note that this returns 0 if the previous query does not\n\ | |
715 generate an AUTO_INCREMENT value. If you need to save the value for\n\ | |
716 later, be sure to call this immediately after the query\n\ | |
717 that generates the value.\n\ | |
718 \n\ | |
719 The ID is updated after INSERT and UPDATE statements that generate\n\ | |
720 an AUTO_INCREMENT value or that set a column value to\n\ | |
721 LAST_INSERT_ID(expr). See section 6.3.5.2 Miscellaneous Functions\n\ | |
722 in the MySQL documentation.\n\ | |
723 \n\ | |
724 Also note that the value of the SQL LAST_INSERT_ID() function always\n\ | |
725 contains the most recently generated AUTO_INCREMENT value, and is not\n\ | |
726 reset between queries because the value of that function is maintained\n\ | |
727 in the server.\n\ | |
728 " ; | |
729 | |
730 static PyObject * | |
731 _mysql_ConnectionObject_insert_id( | |
732 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
733 PyObject *unused) |
0 | 734 { |
735 my_ulonglong r; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
736 |
0 | 737 check_connection(self); |
738 Py_BEGIN_ALLOW_THREADS | |
739 r = mysql_insert_id(&(self->connection)); | |
740 Py_END_ALLOW_THREADS | |
741 return PyLong_FromUnsignedLongLong(r); | |
742 } | |
743 | |
744 static char _mysql_ConnectionObject_kill__doc__[] = | |
745 "Asks the server to kill the thread specified by pid.\n\ | |
746 Non-standard."; | |
747 | |
748 static PyObject * | |
749 _mysql_ConnectionObject_kill( | |
750 _mysql_ConnectionObject *self, | |
751 PyObject *args) | |
752 { | |
753 unsigned long pid; | |
754 int r; | |
755 if (!PyArg_ParseTuple(args, "i:kill", &pid)) return NULL; | |
756 check_connection(self); | |
757 Py_BEGIN_ALLOW_THREADS | |
758 r = mysql_kill(&(self->connection), pid); | |
759 Py_END_ALLOW_THREADS | |
760 if (r) return _mysql_Exception(self); | |
761 Py_INCREF(Py_None); | |
762 return Py_None; | |
763 } | |
764 | |
765 static char _mysql_ConnectionObject_field_count__doc__[] = | |
766 "Returns the number of columns for the most recent query on the\n\ | |
767 connection. Non-standard. Will probably give you bogus results\n\ | |
768 on most cursor classes. Use Cursor.rowcount.\n\ | |
769 "; | |
770 | |
771 static PyObject * | |
772 _mysql_ConnectionObject_field_count( | |
773 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
774 PyObject *unused) |
0 | 775 { |
776 check_connection(self); | |
777 #if MYSQL_VERSION_ID < 32224 | |
778 return PyInt_FromLong((long)mysql_num_fields(&(self->connection))); | |
779 #else | |
780 return PyInt_FromLong((long)mysql_field_count(&(self->connection))); | |
781 #endif | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
782 } |
0 | 783 |
784 static char _mysql_ConnectionObject_ping__doc__[] = | |
785 "Checks whether or not the connection to the server is\n\ | |
786 working. If it has gone down, an automatic reconnection is\n\ | |
787 attempted.\n\ | |
788 \n\ | |
789 This function can be used by clients that remain idle for a\n\ | |
790 long while, to check whether or not the server has closed the\n\ | |
791 connection and reconnect if necessary.\n\ | |
792 \n\ | |
5 | 793 New in 1.2.2: Accepts an optional reconnect parameter. If True,\n\ |
794 then the client will attempt reconnection. Note that this setting\n\ | |
795 is persistent. By default, this is on in MySQL<5.0.3, and off\n\ | |
796 thereafter.\n\ | |
797 \n\ | |
798 Non-standard. You should assume that ping() performs an\n\ | |
799 implicit rollback; use only when starting a new transaction.\n\ | |
800 You have been warned.\n\ | |
0 | 801 "; |
802 | |
803 static PyObject * | |
804 _mysql_ConnectionObject_ping( | |
805 _mysql_ConnectionObject *self, | |
806 PyObject *args) | |
807 { | |
5 | 808 int r, reconnect = -1; |
809 if (!PyArg_ParseTuple(args, "|I", &reconnect)) return NULL; | |
0 | 810 check_connection(self); |
5 | 811 if ( reconnect != -1 ) self->connection.reconnect = reconnect; |
0 | 812 Py_BEGIN_ALLOW_THREADS |
813 r = mysql_ping(&(self->connection)); | |
814 Py_END_ALLOW_THREADS | |
815 if (r) return _mysql_Exception(self); | |
816 Py_INCREF(Py_None); | |
817 return Py_None; | |
818 } | |
819 | |
820 static char _mysql_ConnectionObject_query__doc__[] = | |
821 "Execute a query. store_result() or use_result() will get the\n\ | |
822 result set, if any. Non-standard. Use cursor() to create a cursor,\n\ | |
823 then cursor.execute().\n\ | |
824 " ; | |
825 | |
826 static PyObject * | |
827 _mysql_ConnectionObject_query( | |
828 _mysql_ConnectionObject *self, | |
829 PyObject *args) | |
830 { | |
831 char *query; | |
832 int len, r; | |
833 if (!PyArg_ParseTuple(args, "s#:query", &query, &len)) return NULL; | |
834 check_connection(self); | |
835 Py_BEGIN_ALLOW_THREADS | |
836 r = mysql_real_query(&(self->connection), query, len); | |
837 Py_END_ALLOW_THREADS | |
838 if (r) return _mysql_Exception(self); | |
839 Py_INCREF(Py_None); | |
840 return Py_None; | |
841 } | |
842 | |
843 | |
844 static char _mysql_ConnectionObject_select_db__doc__[] = | |
845 "Causes the database specified by db to become the default\n\ | |
846 (current) database on the connection specified by mysql. In subsequent\n\ | |
847 queries, this database is the default for table references that do not\n\ | |
848 include an explicit database specifier.\n\ | |
849 \n\ | |
850 Fails unless the connected user can be authenticated as having\n\ | |
851 permission to use the database.\n\ | |
852 \n\ | |
853 Non-standard.\n\ | |
854 "; | |
855 | |
856 static PyObject * | |
857 _mysql_ConnectionObject_select_db( | |
858 _mysql_ConnectionObject *self, | |
859 PyObject *args) | |
860 { | |
861 char *db; | |
862 int r; | |
863 if (!PyArg_ParseTuple(args, "s:select_db", &db)) return NULL; | |
864 check_connection(self); | |
865 Py_BEGIN_ALLOW_THREADS | |
866 r = mysql_select_db(&(self->connection), db); | |
867 Py_END_ALLOW_THREADS | |
868 if (r) return _mysql_Exception(self); | |
869 Py_INCREF(Py_None); | |
870 return Py_None; | |
871 } | |
872 | |
873 static char _mysql_ConnectionObject_shutdown__doc__[] = | |
874 "Asks the database server to shut down. The connected user must\n\ | |
875 have shutdown privileges. Non-standard.\n\ | |
876 "; | |
877 | |
878 static PyObject * | |
879 _mysql_ConnectionObject_shutdown( | |
880 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
881 PyObject *unused) |
0 | 882 { |
883 int r; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
884 |
0 | 885 check_connection(self); |
886 Py_BEGIN_ALLOW_THREADS | |
887 r = mysql_shutdown(&(self->connection) | |
888 #if MYSQL_VERSION_ID >= 40103 | |
889 , SHUTDOWN_DEFAULT | |
890 #endif | |
891 ); | |
892 Py_END_ALLOW_THREADS | |
893 if (r) return _mysql_Exception(self); | |
894 Py_INCREF(Py_None); | |
895 return Py_None; | |
896 } | |
897 | |
898 static char _mysql_ConnectionObject_stat__doc__[] = | |
899 "Returns a character string containing information similar to\n\ | |
900 that provided by the mysqladmin status command. This includes\n\ | |
901 uptime in seconds and the number of running threads,\n\ | |
902 questions, reloads, and open tables. Non-standard.\n\ | |
903 "; | |
904 | |
905 static PyObject * | |
906 _mysql_ConnectionObject_stat( | |
907 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
908 PyObject *unused) |
0 | 909 { |
910 const char *s; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
911 |
0 | 912 check_connection(self); |
913 Py_BEGIN_ALLOW_THREADS | |
914 s = mysql_stat(&(self->connection)); | |
915 Py_END_ALLOW_THREADS | |
916 if (!s) return _mysql_Exception(self); | |
917 return PyString_FromString(s); | |
918 } | |
919 | |
920 static char _mysql_ConnectionObject_store_result__doc__[] = | |
921 "Returns a result object acquired by mysql_store_result\n\ | |
922 (results stored in the client). If no results are available,\n\ | |
923 None is returned. Non-standard.\n\ | |
924 "; | |
925 | |
926 static PyObject * | |
927 _mysql_ConnectionObject_store_result( | |
928 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
929 PyObject *unused) |
0 | 930 { |
931 PyObject *arglist=NULL, *kwarglist=NULL, *result=NULL; | |
932 _mysql_ResultObject *r=NULL; | |
933 | |
934 check_connection(self); | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
935 arglist = Py_BuildValue("(OiO)", self, 0, self->decoder_stack); |
0 | 936 if (!arglist) goto error; |
937 kwarglist = PyDict_New(); | |
938 if (!kwarglist) goto error; | |
939 r = MyAlloc(_mysql_ResultObject, _mysql_ResultObject_Type); | |
940 if (!r) goto error; | |
941 if (_mysql_ResultObject_Initialize(r, arglist, kwarglist)) | |
942 goto error; | |
943 result = (PyObject *) r; | |
944 if (!(r->result)) { | |
945 Py_DECREF(result); | |
946 Py_INCREF(Py_None); | |
947 result = Py_None; | |
948 } | |
949 error: | |
950 Py_XDECREF(arglist); | |
951 Py_XDECREF(kwarglist); | |
952 return result; | |
953 } | |
954 | |
955 static char _mysql_ConnectionObject_thread_id__doc__[] = | |
956 "Returns the thread ID of the current connection. This value\n\ | |
957 can be used as an argument to kill() to kill the thread.\n\ | |
958 \n\ | |
959 If the connection is lost and you reconnect with ping(), the\n\ | |
960 thread ID will change. This means you should not get the\n\ | |
961 thread ID and store it for later. You should get it when you\n\ | |
962 need it.\n\ | |
963 \n\ | |
964 Non-standard."; | |
965 | |
966 static PyObject * | |
967 _mysql_ConnectionObject_thread_id( | |
968 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
969 PyObject *unused) |
0 | 970 { |
971 unsigned long pid; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
972 |
0 | 973 check_connection(self); |
974 Py_BEGIN_ALLOW_THREADS | |
975 pid = mysql_thread_id(&(self->connection)); | |
976 Py_END_ALLOW_THREADS | |
977 return PyInt_FromLong((long)pid); | |
978 } | |
979 | |
980 static char _mysql_ConnectionObject_use_result__doc__[] = | |
981 "Returns a result object acquired by mysql_use_result\n\ | |
982 (results stored in the server). If no results are available,\n\ | |
983 None is returned. Non-standard.\n\ | |
984 "; | |
985 | |
986 static PyObject * | |
987 _mysql_ConnectionObject_use_result( | |
988 _mysql_ConnectionObject *self, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
989 PyObject *unused) |
0 | 990 { |
991 PyObject *arglist=NULL, *kwarglist=NULL, *result=NULL; | |
992 _mysql_ResultObject *r=NULL; | |
993 | |
994 check_connection(self); | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
995 arglist = Py_BuildValue("(OiO)", self, 1, self->decoder_stack); |
0 | 996 if (!arglist) return NULL; |
997 kwarglist = PyDict_New(); | |
998 if (!kwarglist) goto error; | |
999 r = MyAlloc(_mysql_ResultObject, _mysql_ResultObject_Type); | |
1000 if (!r) goto error; | |
1001 result = (PyObject *) r; | |
1002 if (_mysql_ResultObject_Initialize(r, arglist, kwarglist)) | |
1003 goto error; | |
1004 if (!(r->result)) { | |
1005 Py_DECREF(result); | |
1006 Py_INCREF(Py_None); | |
1007 result = Py_None; | |
1008 } | |
1009 error: | |
1010 Py_DECREF(arglist); | |
1011 Py_XDECREF(kwarglist); | |
1012 return result; | |
1013 } | |
1014 | |
1015 static void | |
1016 _mysql_ConnectionObject_dealloc( | |
1017 _mysql_ConnectionObject *self) | |
1018 { | |
1019 PyObject *o; | |
1020 | |
1021 PyObject_GC_UnTrack(self); | |
1022 if (self->open) { | |
1023 o = _mysql_ConnectionObject_close(self, NULL); | |
1024 Py_XDECREF(o); | |
1025 } | |
1026 MyFree(self); | |
1027 } | |
1028 | |
1029 static PyObject * | |
1030 _mysql_ConnectionObject_repr( | |
1031 _mysql_ConnectionObject *self) | |
1032 { | |
1033 char buf[300]; | |
1034 if (self->open) | |
1035 sprintf(buf, "<_mysql.connection open to '%.256s' at %lx>", | |
1036 self->connection.host, | |
1037 (long)self); | |
1038 else | |
1039 sprintf(buf, "<_mysql.connection closed at %lx>", | |
1040 (long)self); | |
1041 return PyString_FromString(buf); | |
1042 } | |
1043 | |
1044 static PyMethodDef _mysql_ConnectionObject_methods[] = { | |
1045 { | |
1046 "affected_rows", | |
1047 (PyCFunction)_mysql_ConnectionObject_affected_rows, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1048 METH_NOARGS, |
0 | 1049 _mysql_ConnectionObject_affected_rows__doc__ |
1050 }, | |
1051 { | |
1052 "autocommit", | |
1053 (PyCFunction)_mysql_ConnectionObject_autocommit, | |
1054 METH_VARARGS, | |
1055 _mysql_ConnectionObject_autocommit__doc__ | |
1056 }, | |
1057 { | |
1058 "commit", | |
1059 (PyCFunction)_mysql_ConnectionObject_commit, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1060 METH_NOARGS, |
0 | 1061 _mysql_ConnectionObject_commit__doc__ |
1062 }, | |
1063 { | |
1064 "rollback", | |
1065 (PyCFunction)_mysql_ConnectionObject_rollback, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1066 METH_NOARGS, |
0 | 1067 _mysql_ConnectionObject_rollback__doc__ |
1068 }, | |
1069 { | |
1070 "next_result", | |
1071 (PyCFunction)_mysql_ConnectionObject_next_result, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1072 METH_NOARGS, |
0 | 1073 _mysql_ConnectionObject_next_result__doc__ |
1074 }, | |
1075 #if MYSQL_VERSION_ID >= 40100 | |
1076 { | |
1077 "set_server_option", | |
1078 (PyCFunction)_mysql_ConnectionObject_set_server_option, | |
1079 METH_VARARGS, | |
1080 _mysql_ConnectionObject_set_server_option__doc__ | |
1081 }, | |
1082 { | |
1083 "sqlstate", | |
1084 (PyCFunction)_mysql_ConnectionObject_sqlstate, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1085 METH_NOARGS, |
0 | 1086 _mysql_ConnectionObject_sqlstate__doc__ |
1087 }, | |
1088 { | |
1089 "warning_count", | |
1090 (PyCFunction)_mysql_ConnectionObject_warning_count, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1091 METH_NOARGS, |
0 | 1092 _mysql_ConnectionObject_warning_count__doc__ |
1093 }, | |
1094 #endif | |
1095 #if MYSQL_VERSION_ID >= 32303 | |
1096 { | |
1097 "change_user", | |
1098 (PyCFunction)_mysql_ConnectionObject_change_user, | |
1099 METH_VARARGS | METH_KEYWORDS, | |
1100 _mysql_ConnectionObject_change_user__doc__ | |
1101 }, | |
1102 #endif | |
1103 { | |
1104 "character_set_name", | |
1105 (PyCFunction)_mysql_ConnectionObject_character_set_name, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1106 METH_NOARGS, |
0 | 1107 _mysql_ConnectionObject_character_set_name__doc__ |
1108 }, | |
1109 #if MYSQL_VERSION_ID >= 50007 | |
1110 { | |
1111 "set_character_set", | |
1112 (PyCFunction)_mysql_ConnectionObject_set_character_set, | |
1113 METH_VARARGS, | |
1114 _mysql_ConnectionObject_set_character_set__doc__ | |
1115 }, | |
1116 #endif | |
1117 #if MYSQL_VERSION_ID >= 50010 | |
1118 { | |
1119 "get_character_set_info", | |
1120 (PyCFunction)_mysql_ConnectionObject_get_character_set_info, | |
1121 METH_VARARGS, | |
1122 _mysql_ConnectionObject_get_character_set_info__doc__ | |
1123 }, | |
1124 #endif | |
1125 { | |
1126 "close", | |
1127 (PyCFunction)_mysql_ConnectionObject_close, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1128 METH_NOARGS, |
0 | 1129 _mysql_ConnectionObject_close__doc__ |
1130 }, | |
1131 { | |
1132 "dump_debug_info", | |
1133 (PyCFunction)_mysql_ConnectionObject_dump_debug_info, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1134 METH_NOARGS, |
0 | 1135 _mysql_ConnectionObject_dump_debug_info__doc__ |
1136 }, | |
1137 { | |
1138 "escape_string", | |
1139 (PyCFunction)_mysql_escape_string, | |
1140 METH_VARARGS, | |
1141 _mysql_escape_string__doc__ | |
1142 }, | |
1143 { | |
1144 "error", | |
1145 (PyCFunction)_mysql_ConnectionObject_error, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1146 METH_NOARGS, |
0 | 1147 _mysql_ConnectionObject_error__doc__ |
1148 }, | |
1149 { | |
1150 "errno", | |
1151 (PyCFunction)_mysql_ConnectionObject_errno, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1152 METH_NOARGS, |
0 | 1153 _mysql_ConnectionObject_errno__doc__ |
1154 }, | |
1155 { | |
1156 "field_count", | |
1157 (PyCFunction)_mysql_ConnectionObject_field_count, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1158 METH_NOARGS, |
0 | 1159 _mysql_ConnectionObject_field_count__doc__ |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1160 }, |
0 | 1161 { |
1162 "get_host_info", | |
1163 (PyCFunction)_mysql_ConnectionObject_get_host_info, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1164 METH_NOARGS, |
0 | 1165 _mysql_ConnectionObject_get_host_info__doc__ |
1166 }, | |
1167 { | |
1168 "get_proto_info", | |
1169 (PyCFunction)_mysql_ConnectionObject_get_proto_info, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1170 METH_NOARGS, |
0 | 1171 _mysql_ConnectionObject_get_proto_info__doc__ |
1172 }, | |
1173 { | |
1174 "get_server_info", | |
1175 (PyCFunction)_mysql_ConnectionObject_get_server_info, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1176 METH_NOARGS, |
0 | 1177 _mysql_ConnectionObject_get_server_info__doc__ |
1178 }, | |
1179 { | |
1180 "info", | |
1181 (PyCFunction)_mysql_ConnectionObject_info, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1182 METH_NOARGS, |
0 | 1183 _mysql_ConnectionObject_info__doc__ |
1184 }, | |
1185 { | |
1186 "insert_id", | |
1187 (PyCFunction)_mysql_ConnectionObject_insert_id, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1188 METH_NOARGS, |
0 | 1189 _mysql_ConnectionObject_insert_id__doc__ |
1190 }, | |
1191 { | |
1192 "kill", | |
1193 (PyCFunction)_mysql_ConnectionObject_kill, | |
1194 METH_VARARGS, | |
1195 _mysql_ConnectionObject_kill__doc__ | |
1196 }, | |
1197 { | |
1198 "ping", | |
1199 (PyCFunction)_mysql_ConnectionObject_ping, | |
1200 METH_VARARGS, | |
1201 _mysql_ConnectionObject_ping__doc__ | |
1202 }, | |
1203 { | |
1204 "query", | |
1205 (PyCFunction)_mysql_ConnectionObject_query, | |
1206 METH_VARARGS, | |
1207 _mysql_ConnectionObject_query__doc__ | |
1208 }, | |
1209 { | |
1210 "select_db", | |
1211 (PyCFunction)_mysql_ConnectionObject_select_db, | |
1212 METH_VARARGS, | |
1213 _mysql_ConnectionObject_select_db__doc__ | |
1214 }, | |
1215 { | |
1216 "shutdown", | |
1217 (PyCFunction)_mysql_ConnectionObject_shutdown, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1218 METH_NOARGS, |
0 | 1219 _mysql_ConnectionObject_shutdown__doc__ |
1220 }, | |
1221 { | |
1222 "stat", | |
1223 (PyCFunction)_mysql_ConnectionObject_stat, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1224 METH_NOARGS, |
0 | 1225 _mysql_ConnectionObject_stat__doc__ |
1226 }, | |
1227 { | |
1228 "store_result", | |
1229 (PyCFunction)_mysql_ConnectionObject_store_result, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1230 METH_NOARGS, |
0 | 1231 _mysql_ConnectionObject_store_result__doc__ |
1232 }, | |
1233 { | |
1234 "string_literal", | |
1235 (PyCFunction)_mysql_string_literal, | |
1236 METH_VARARGS, | |
1237 _mysql_string_literal__doc__}, | |
1238 { | |
1239 "thread_id", | |
1240 (PyCFunction)_mysql_ConnectionObject_thread_id, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1241 METH_NOARGS, |
0 | 1242 _mysql_ConnectionObject_thread_id__doc__ |
1243 }, | |
1244 { | |
1245 "use_result", | |
1246 (PyCFunction)_mysql_ConnectionObject_use_result, | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1247 METH_NOARGS, |
0 | 1248 _mysql_ConnectionObject_use_result__doc__ |
1249 }, | |
1250 {NULL, NULL} /* sentinel */ | |
1251 }; | |
1252 | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1253 static struct PyMemberDef _mysql_ConnectionObject_memberlist[] = { |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1254 { |
0 | 1255 "open", |
1256 T_INT, | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1257 offsetof(_mysql_ConnectionObject, open), |
0 | 1258 RO, |
1259 "True if connection is open" | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1260 }, |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1261 { |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
1262 "decoder_stack", |
0 | 1263 T_OBJECT, |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
1264 offsetof(_mysql_ConnectionObject, decoder_stack), |
0 | 1265 0, |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
55
diff
changeset
|
1266 "Type decoder stack" |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1267 }, |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1268 { |
0 | 1269 "server_capabilities", |
1270 T_UINT, | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1271 offsetof(_mysql_ConnectionObject, connection.server_capabilities), |
0 | 1272 RO, |
1273 "Capabilites of server; consult MySQLdb.constants.CLIENT" | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1274 }, |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1275 { |
0 | 1276 "port", |
1277 T_UINT, | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1278 offsetof(_mysql_ConnectionObject, connection.port), |
0 | 1279 RO, |
1280 "TCP/IP port of the server connection" | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1281 }, |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1282 { |
0 | 1283 "client_flag", |
1284 T_UINT, | |
1285 RO, | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1286 offsetof(_mysql_ConnectionObject, connection.client_flag), |
0 | 1287 "Client flags; refer to MySQLdb.constants.CLIENT" |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1288 }, |
0 | 1289 {NULL} /* Sentinel */ |
1290 }; | |
25
25c5d3b241ba
Start converting some some things to METH_NOARGS to save invocation time, add
kylev
parents:
21
diff
changeset
|
1291 |
0 | 1292 static PyObject * |
1293 _mysql_ConnectionObject_getattr( | |
1294 _mysql_ConnectionObject *self, | |
1295 char *name) | |
1296 { | |
1297 PyObject *res; | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1298 struct PyMemberDef *l; |
0 | 1299 |
1300 res = Py_FindMethod(_mysql_ConnectionObject_methods, (PyObject *)self, name); | |
1301 if (res != NULL) | |
1302 return res; | |
1303 PyErr_Clear(); | |
1304 if (strcmp(name, "closed") == 0) | |
1305 return PyInt_FromLong((long)!(self->open)); | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1306 |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1307 for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++) { |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1308 if (strcmp(l->name, name) == 0) |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1309 return PyMember_GetOne((char *)self, l); |
0 | 1310 } |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1311 |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1312 PyErr_SetString(PyExc_AttributeError, name); |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1313 return NULL; |
0 | 1314 } |
1315 | |
1316 static int | |
1317 _mysql_ConnectionObject_setattr( | |
1318 _mysql_ConnectionObject *self, | |
1319 char *name, | |
1320 PyObject *v) | |
1321 { | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1322 struct PyMemberDef *l; |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1323 |
0 | 1324 if (v == NULL) { |
1325 PyErr_SetString(PyExc_AttributeError, | |
1326 "can't delete connection attributes"); | |
1327 return -1; | |
1328 } | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1329 |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1330 for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++) |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1331 if (strcmp(l->name, name) == 0) |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1332 return PyMember_SetOne((char *)self, l, v); |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1333 |
0 | 1334 PyErr_SetString(PyExc_AttributeError, name); |
1335 return -1; | |
1336 } | |
1337 | |
1338 PyTypeObject _mysql_ConnectionObject_Type = { | |
1339 PyObject_HEAD_INIT(NULL) | |
1340 0, | |
1341 "_mysql.connection", /* (char *)tp_name For printing */ | |
29 | 1342 sizeof(_mysql_ConnectionObject), /* tp_basicsize */ |
0 | 1343 0, |
1344 (destructor)_mysql_ConnectionObject_dealloc, /* tp_dealloc */ | |
1345 0, /*tp_print*/ | |
1346 (getattrfunc)_mysql_ConnectionObject_getattr, /* tp_getattr */ | |
1347 (setattrfunc)_mysql_ConnectionObject_setattr, /* tp_setattr */ | |
1348 0, /*tp_compare*/ | |
1349 (reprfunc)_mysql_ConnectionObject_repr, /* tp_repr */ | |
29 | 1350 |
0 | 1351 /* Method suites for standard classes */ |
29 | 1352 |
0 | 1353 0, /* (PyNumberMethods *) tp_as_number */ |
1354 0, /* (PySequenceMethods *) tp_as_sequence */ | |
1355 0, /* (PyMappingMethods *) tp_as_mapping */ | |
29 | 1356 |
0 | 1357 /* More standard operations (here for binary compatibility) */ |
29 | 1358 |
0 | 1359 0, /* (hashfunc) tp_hash */ |
1360 0, /* (ternaryfunc) tp_call */ | |
1361 0, /* (reprfunc) tp_str */ | |
1362 0, /* (getattrofunc) tp_getattro */ | |
1363 0, /* (setattrofunc) tp_setattro */ | |
29 | 1364 |
0 | 1365 /* Functions to access object as input/output buffer */ |
1366 0, /* (PyBufferProcs *) tp_as_buffer */ | |
29 | 1367 |
0 | 1368 /* Flags to define presence of optional/expanded features */ |
1369 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, | |
29 | 1370 |
0 | 1371 _mysql_connect__doc__, /* (char *) tp_doc Documentation string */ |
29 | 1372 |
0 | 1373 /* call function for all accessible objects */ |
29 | 1374 (traverseproc)_mysql_ConnectionObject_traverse, /* tp_traverse */ |
1375 | |
0 | 1376 /* delete references to contained objects */ |
29 | 1377 (inquiry)_mysql_ConnectionObject_clear, /* tp_clear */ |
1378 | |
0 | 1379 /* rich comparisons */ |
1380 0, /* (richcmpfunc) tp_richcompare */ | |
29 | 1381 |
0 | 1382 /* weak reference enabler */ |
1383 0, /* (long) tp_weaklistoffset */ | |
29 | 1384 |
0 | 1385 /* Iterators */ |
1386 0, /* (getiterfunc) tp_iter */ | |
1387 0, /* (iternextfunc) tp_iternext */ | |
29 | 1388 |
0 | 1389 /* Attribute descriptor and subclassing stuff */ |
1390 (struct PyMethodDef *)_mysql_ConnectionObject_methods, /* tp_methods */ | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
29
diff
changeset
|
1391 (struct PyMemberDef *)_mysql_ConnectionObject_memberlist, /* tp_members */ |
0 | 1392 0, /* (struct getsetlist *) tp_getset; */ |
1393 0, /* (struct _typeobject *) tp_base; */ | |
1394 0, /* (PyObject *) tp_dict */ | |
1395 0, /* (descrgetfunc) tp_descr_get */ | |
1396 0, /* (descrsetfunc) tp_descr_set */ | |
1397 0, /* (long) tp_dictoffset */ | |
1398 (initproc)_mysql_ConnectionObject_Initialize, /* tp_init */ | |
1399 NULL, /* tp_alloc */ | |
1400 NULL, /* tp_new */ | |
29 | 1401 NULL, /* tp_free Low-level free-memory routine */ |
0 | 1402 0, /* (PyObject *) tp_bases */ |
1403 0, /* (PyObject *) tp_mro method resolution order */ | |
1404 0, /* (PyObject *) tp_defined */ | |
29 | 1405 }; |