comparison src/connections.c @ 55:e606fd52e866 MySQLdb

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