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