Merge lp:~thedac/ubuntu/wily/python-mysqldb/debian-merge into lp:ubuntu/wily/python-mysqldb
- Wily (15.10)
- debian-merge
- Merge into wily
Proposed by
David Ames
Status: | Merged |
---|---|
Merge reported by: | Iain Lane |
Merged at revision: | not available |
Proposed branch: | lp:~thedac/ubuntu/wily/python-mysqldb/debian-merge |
Merge into: | lp:ubuntu/wily/python-mysqldb |
Diff against target: |
14723 lines (+3853/-9113) 74 files modified
.cvsignore (+0/-6) .pc/.quilt_patches (+0/-1) .pc/.quilt_series (+0/-1) .pc/.version (+0/-1) .pc/01_converters_boolean.patch/MySQLdb/converters.py (+0/-171) .pc/03_converters_set2str.patch/MySQLdb/converters.py (+0/-176) .pc/05_ssl.patch/_mysql.c (+0/-2890) .pc/06_fix_error_checking.patch/_mysql.c (+0/-2894) .pc/applied-patches (+0/-4) GPL-2.0 (+339/-0) HISTORY (+227/-116) INSTALL (+253/-0) MANIFEST.in (+13/-13) MySQL_python.egg-info/PKG-INFO (+0/-45) MySQL_python.egg-info/SOURCES.txt (+0/-42) MySQL_python.egg-info/dependency_links.txt (+0/-1) MySQL_python.egg-info/top_level.txt (+0/-3) MySQLdb/.cvsignore (+0/-1) MySQLdb/__init__.py (+4/-4) MySQLdb/compat.py (+12/-0) MySQLdb/connections.py (+95/-41) MySQLdb/constants/.cvsignore (+0/-1) MySQLdb/converters.py (+34/-62) MySQLdb/cursors.py (+90/-34) MySQLdb/release.py (+3/-3) MySQLdb/times.py (+42/-13) PKG-INFO (+17/-12) README (+0/-253) README.md (+18/-0) _mysql.c (+418/-252) _mysql_exceptions.py (+6/-2) debian/README.source (+0/-2) debian/changelog (+40/-3) debian/compat (+1/-1) debian/control (+79/-32) debian/copyright (+36/-28) debian/docs (+3/-3) debian/patches/01_converters_boolean.patch (+7/-6) debian/patches/03_converters_set2str.patch (+5/-3) debian/patches/05_ssl.patch (+5/-5) debian/patches/06_fix_error_checking.patch (+0/-18) debian/patches/series (+0/-1) debian/rules (+4/-51) doc/.cvsignore (+0/-2) doc/FAQ.rst (+143/-0) doc/FAQ.txt (+0/-143) doc/MySQLdb.constants.rst (+59/-0) doc/MySQLdb.rst (+50/-0) doc/MySQLdb.txt (+0/-718) doc/_mysql.rst (+7/-0) doc/_mysql_exceptions.rst (+7/-0) doc/conf.py (+242/-0) doc/index.rst (+24/-0) doc/modules.rst (+7/-0) doc/user_guide.rst (+718/-0) ez_setup.py (+0/-284) metadata.cfg (+18/-10) mysqlclient.egg-info/PKG-INFO (+50/-0) mysqlclient.egg-info/SOURCES.txt (+47/-0) mysqlclient.egg-info/dependency_links.txt (+1/-0) mysqlclient.egg-info/top_level.txt (+3/-0) pymemcompat.h (+0/-87) setup.cfg (+4/-4) setup.py (+10/-7) setup_common.py (+8/-3) setup_posix.py (+11/-6) setup_windows.py (+15/-11) site.cfg (+3/-4) tests/capabilities.py (+281/-289) tests/configdb.py (+25/-0) tests/dbapi20.py (+50/-50) tests/test_MySQLdb_capabilities.py (+111/-93) tests/test_MySQLdb_dbapi20.py (+204/-205) tests/test_MySQLdb_nonstandard.py (+4/-2) |
To merge this branch: | bzr merge lp:~thedac/ubuntu/wily/python-mysqldb/debian-merge |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu branches | Pending | ||
Review via email: mp+268401@code.launchpad.net |
Commit message
Description of the change
Merge from Debian unstable.
To post a comment you must log in.
Revision history for this message
Corey Bryant (corey.bryant) wrote : | # |
Revision history for this message
Iain Lane (laney) wrote : | # |
Looks like someone synced this already
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file '.cvsignore' |
2 | --- .cvsignore 2011-07-14 01:41:37 +0000 |
3 | +++ .cvsignore 1970-01-01 00:00:00 +0000 |
4 | @@ -1,6 +0,0 @@ |
5 | -dist |
6 | -build |
7 | -regress.py |
8 | -test.py |
9 | -PKG-INFO |
10 | -*.pyc |
11 | |
12 | === removed directory '.pc' |
13 | === removed file '.pc/.quilt_patches' |
14 | --- .pc/.quilt_patches 2013-03-11 18:03:06 +0000 |
15 | +++ .pc/.quilt_patches 1970-01-01 00:00:00 +0000 |
16 | @@ -1,1 +0,0 @@ |
17 | -debian/patches |
18 | |
19 | === removed file '.pc/.quilt_series' |
20 | --- .pc/.quilt_series 2013-03-11 18:03:06 +0000 |
21 | +++ .pc/.quilt_series 1970-01-01 00:00:00 +0000 |
22 | @@ -1,1 +0,0 @@ |
23 | -series |
24 | |
25 | === removed file '.pc/.version' |
26 | --- .pc/.version 2011-10-18 12:45:53 +0000 |
27 | +++ .pc/.version 1970-01-01 00:00:00 +0000 |
28 | @@ -1,1 +0,0 @@ |
29 | -2 |
30 | |
31 | === removed directory '.pc/01_converters_boolean.patch' |
32 | === removed directory '.pc/01_converters_boolean.patch/MySQLdb' |
33 | === removed file '.pc/01_converters_boolean.patch/MySQLdb/converters.py' |
34 | --- .pc/01_converters_boolean.patch/MySQLdb/converters.py 2011-10-18 12:45:53 +0000 |
35 | +++ .pc/01_converters_boolean.patch/MySQLdb/converters.py 1970-01-01 00:00:00 +0000 |
36 | @@ -1,171 +0,0 @@ |
37 | -"""MySQLdb type conversion module |
38 | - |
39 | -This module handles all the type conversions for MySQL. If the default |
40 | -type conversions aren't what you need, you can make your own. The |
41 | -dictionary conversions maps some kind of type to a conversion function |
42 | -which returns the corresponding value: |
43 | - |
44 | -Key: FIELD_TYPE.* (from MySQLdb.constants) |
45 | - |
46 | -Conversion function: |
47 | - |
48 | - Arguments: string |
49 | - |
50 | - Returns: Python object |
51 | - |
52 | -Key: Python type object (from types) or class |
53 | - |
54 | -Conversion function: |
55 | - |
56 | - Arguments: Python object of indicated type or class AND |
57 | - conversion dictionary |
58 | - |
59 | - Returns: SQL literal value |
60 | - |
61 | - Notes: Most conversion functions can ignore the dictionary, but |
62 | - it is a required parameter. It is necessary for converting |
63 | - things like sequences and instances. |
64 | - |
65 | -Don't modify conversions if you can avoid it. Instead, make copies |
66 | -(with the copy() method), modify the copies, and then pass them to |
67 | -MySQL.connect(). |
68 | - |
69 | -""" |
70 | - |
71 | -from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL |
72 | -from constants import FIELD_TYPE, FLAG |
73 | -from times import * |
74 | -import types |
75 | -import array |
76 | - |
77 | -try: |
78 | - set |
79 | -except NameError: |
80 | - from sets import Set as set |
81 | - |
82 | -def Bool2Str(s, d): return str(int(s)) |
83 | - |
84 | -def Str2Set(s): |
85 | - return set([ i for i in s.split(',') if i ]) |
86 | - |
87 | -def Set2Str(s, d): |
88 | - return string_literal(','.join(s), d) |
89 | - |
90 | -def Thing2Str(s, d): |
91 | - """Convert something into a string via str().""" |
92 | - return str(s) |
93 | - |
94 | -def Unicode2Str(s, d): |
95 | - """Convert a unicode object to a string using the default encoding. |
96 | - This is only used as a placeholder for the real function, which |
97 | - is connection-dependent.""" |
98 | - return s.encode() |
99 | - |
100 | -Long2Int = Thing2Str |
101 | - |
102 | -def Float2Str(o, d): |
103 | - return '%.15g' % o |
104 | - |
105 | -def None2NULL(o, d): |
106 | - """Convert None to NULL.""" |
107 | - return NULL # duh |
108 | - |
109 | -def Thing2Literal(o, d): |
110 | - |
111 | - """Convert something into a SQL string literal. If using |
112 | - MySQL-3.23 or newer, string_literal() is a method of the |
113 | - _mysql.MYSQL object, and this function will be overridden with |
114 | - that method when the connection is created.""" |
115 | - |
116 | - return string_literal(o, d) |
117 | - |
118 | - |
119 | -def Instance2Str(o, d): |
120 | - |
121 | - """ |
122 | - |
123 | - Convert an Instance to a string representation. If the __str__() |
124 | - method produces acceptable output, then you don't need to add the |
125 | - class to conversions; it will be handled by the default |
126 | - converter. If the exact class is not found in d, it will use the |
127 | - first class it can find for which o is an instance. |
128 | - |
129 | - """ |
130 | - |
131 | - if d.has_key(o.__class__): |
132 | - return d[o.__class__](o, d) |
133 | - cl = filter(lambda x,o=o: |
134 | - type(x) is types.ClassType |
135 | - and isinstance(o, x), d.keys()) |
136 | - if not cl and hasattr(types, 'ObjectType'): |
137 | - cl = filter(lambda x,o=o: |
138 | - type(x) is types.TypeType |
139 | - and isinstance(o, x) |
140 | - and d[x] is not Instance2Str, |
141 | - d.keys()) |
142 | - if not cl: |
143 | - return d[types.StringType](o,d) |
144 | - d[o.__class__] = d[cl[0]] |
145 | - return d[cl[0]](o, d) |
146 | - |
147 | -def char_array(s): |
148 | - return array.array('c', s) |
149 | - |
150 | -def array2Str(o, d): |
151 | - return Thing2Literal(o.tostring(), d) |
152 | - |
153 | -conversions = { |
154 | - types.IntType: Thing2Str, |
155 | - types.LongType: Long2Int, |
156 | - types.FloatType: Float2Str, |
157 | - types.NoneType: None2NULL, |
158 | - types.TupleType: escape_sequence, |
159 | - types.ListType: escape_sequence, |
160 | - types.DictType: escape_dict, |
161 | - types.InstanceType: Instance2Str, |
162 | - array.ArrayType: array2Str, |
163 | - types.StringType: Thing2Literal, # default |
164 | - types.UnicodeType: Unicode2Str, |
165 | - types.ObjectType: Instance2Str, |
166 | - types.BooleanType: Bool2Str, |
167 | - DateTimeType: DateTime2literal, |
168 | - DateTimeDeltaType: DateTimeDelta2literal, |
169 | - set: Set2Str, |
170 | - FIELD_TYPE.TINY: int, |
171 | - FIELD_TYPE.SHORT: int, |
172 | - FIELD_TYPE.LONG: long, |
173 | - FIELD_TYPE.FLOAT: float, |
174 | - FIELD_TYPE.DOUBLE: float, |
175 | - FIELD_TYPE.DECIMAL: float, |
176 | - FIELD_TYPE.NEWDECIMAL: float, |
177 | - FIELD_TYPE.LONGLONG: long, |
178 | - FIELD_TYPE.INT24: int, |
179 | - FIELD_TYPE.YEAR: int, |
180 | - FIELD_TYPE.SET: Str2Set, |
181 | - FIELD_TYPE.TIMESTAMP: mysql_timestamp_converter, |
182 | - FIELD_TYPE.DATETIME: DateTime_or_None, |
183 | - FIELD_TYPE.TIME: TimeDelta_or_None, |
184 | - FIELD_TYPE.DATE: Date_or_None, |
185 | - FIELD_TYPE.BLOB: [ |
186 | - (FLAG.BINARY, str), |
187 | - ], |
188 | - FIELD_TYPE.STRING: [ |
189 | - (FLAG.BINARY, str), |
190 | - ], |
191 | - FIELD_TYPE.VAR_STRING: [ |
192 | - (FLAG.BINARY, str), |
193 | - ], |
194 | - FIELD_TYPE.VARCHAR: [ |
195 | - (FLAG.BINARY, str), |
196 | - ], |
197 | - } |
198 | - |
199 | -try: |
200 | - from decimal import Decimal |
201 | - conversions[FIELD_TYPE.DECIMAL] = Decimal |
202 | - conversions[FIELD_TYPE.NEWDECIMAL] = Decimal |
203 | -except ImportError: |
204 | - pass |
205 | - |
206 | - |
207 | - |
208 | |
209 | === removed directory '.pc/03_converters_set2str.patch' |
210 | === removed directory '.pc/03_converters_set2str.patch/MySQLdb' |
211 | === removed file '.pc/03_converters_set2str.patch/MySQLdb/converters.py' |
212 | --- .pc/03_converters_set2str.patch/MySQLdb/converters.py 2011-10-18 12:45:53 +0000 |
213 | +++ .pc/03_converters_set2str.patch/MySQLdb/converters.py 1970-01-01 00:00:00 +0000 |
214 | @@ -1,176 +0,0 @@ |
215 | -"""MySQLdb type conversion module |
216 | - |
217 | -This module handles all the type conversions for MySQL. If the default |
218 | -type conversions aren't what you need, you can make your own. The |
219 | -dictionary conversions maps some kind of type to a conversion function |
220 | -which returns the corresponding value: |
221 | - |
222 | -Key: FIELD_TYPE.* (from MySQLdb.constants) |
223 | - |
224 | -Conversion function: |
225 | - |
226 | - Arguments: string |
227 | - |
228 | - Returns: Python object |
229 | - |
230 | -Key: Python type object (from types) or class |
231 | - |
232 | -Conversion function: |
233 | - |
234 | - Arguments: Python object of indicated type or class AND |
235 | - conversion dictionary |
236 | - |
237 | - Returns: SQL literal value |
238 | - |
239 | - Notes: Most conversion functions can ignore the dictionary, but |
240 | - it is a required parameter. It is necessary for converting |
241 | - things like sequences and instances. |
242 | - |
243 | -Don't modify conversions if you can avoid it. Instead, make copies |
244 | -(with the copy() method), modify the copies, and then pass them to |
245 | -MySQL.connect(). |
246 | - |
247 | -""" |
248 | - |
249 | -from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL |
250 | -from constants import FIELD_TYPE, FLAG |
251 | -from times import * |
252 | -import types |
253 | -import array |
254 | - |
255 | -try: |
256 | - set |
257 | -except NameError: |
258 | - from sets import Set as set |
259 | - |
260 | -def Bool2Str(s, d): return str(int(s)) |
261 | - |
262 | -def Str2Set(s): |
263 | - return set([ i for i in s.split(',') if i ]) |
264 | - |
265 | -def Set2Str(s, d): |
266 | - return string_literal(','.join(s), d) |
267 | - |
268 | -def Thing2Str(s, d): |
269 | - """Convert something into a string via str().""" |
270 | - return str(s) |
271 | - |
272 | -def Unicode2Str(s, d): |
273 | - """Convert a unicode object to a string using the default encoding. |
274 | - This is only used as a placeholder for the real function, which |
275 | - is connection-dependent.""" |
276 | - return s.encode() |
277 | - |
278 | -Long2Int = Thing2Str |
279 | - |
280 | -def Float2Str(o, d): |
281 | - return '%.15g' % o |
282 | - |
283 | -def None2NULL(o, d): |
284 | - """Convert None to NULL.""" |
285 | - return NULL # duh |
286 | - |
287 | -def Thing2Literal(o, d): |
288 | - |
289 | - """Convert something into a SQL string literal. If using |
290 | - MySQL-3.23 or newer, string_literal() is a method of the |
291 | - _mysql.MYSQL object, and this function will be overridden with |
292 | - that method when the connection is created.""" |
293 | - |
294 | - return string_literal(o, d) |
295 | - |
296 | - |
297 | -def Instance2Str(o, d): |
298 | - |
299 | - """ |
300 | - |
301 | - Convert an Instance to a string representation. If the __str__() |
302 | - method produces acceptable output, then you don't need to add the |
303 | - class to conversions; it will be handled by the default |
304 | - converter. If the exact class is not found in d, it will use the |
305 | - first class it can find for which o is an instance. |
306 | - |
307 | - """ |
308 | - |
309 | - if d.has_key(o.__class__): |
310 | - return d[o.__class__](o, d) |
311 | - cl = filter(lambda x,o=o: |
312 | - type(x) is types.ClassType |
313 | - and isinstance(o, x), d.keys()) |
314 | - if not cl and hasattr(types, 'ObjectType'): |
315 | - cl = filter(lambda x,o=o: |
316 | - type(x) is types.TypeType |
317 | - and isinstance(o, x) |
318 | - and d[x] is not Instance2Str, |
319 | - d.keys()) |
320 | - if not cl: |
321 | - return d[types.StringType](o,d) |
322 | - d[o.__class__] = d[cl[0]] |
323 | - return d[cl[0]](o, d) |
324 | - |
325 | -def char_array(s): |
326 | - return array.array('c', s) |
327 | - |
328 | -def array2Str(o, d): |
329 | - return Thing2Literal(o.tostring(), d) |
330 | - |
331 | -conversions = { |
332 | - types.IntType: Thing2Str, |
333 | - types.LongType: Long2Int, |
334 | - types.FloatType: Float2Str, |
335 | - types.NoneType: None2NULL, |
336 | - types.TupleType: escape_sequence, |
337 | - types.ListType: escape_sequence, |
338 | - types.DictType: escape_dict, |
339 | - types.InstanceType: Instance2Str, |
340 | - array.ArrayType: array2Str, |
341 | - types.StringType: Thing2Literal, # default |
342 | - types.UnicodeType: Unicode2Str, |
343 | - types.ObjectType: Instance2Str, |
344 | - types.BooleanType: Bool2Str, |
345 | - DateTimeType: DateTime2literal, |
346 | - DateTimeDeltaType: DateTimeDelta2literal, |
347 | - set: Set2Str, |
348 | - FIELD_TYPE.TINY: int, |
349 | - FIELD_TYPE.SHORT: int, |
350 | - FIELD_TYPE.LONG: long, |
351 | - FIELD_TYPE.FLOAT: float, |
352 | - FIELD_TYPE.DOUBLE: float, |
353 | - FIELD_TYPE.DECIMAL: float, |
354 | - FIELD_TYPE.NEWDECIMAL: float, |
355 | - FIELD_TYPE.LONGLONG: long, |
356 | - FIELD_TYPE.INT24: int, |
357 | - FIELD_TYPE.YEAR: int, |
358 | - FIELD_TYPE.SET: Str2Set, |
359 | - FIELD_TYPE.TIMESTAMP: mysql_timestamp_converter, |
360 | - FIELD_TYPE.DATETIME: DateTime_or_None, |
361 | - FIELD_TYPE.TIME: TimeDelta_or_None, |
362 | - FIELD_TYPE.DATE: Date_or_None, |
363 | - FIELD_TYPE.BLOB: [ |
364 | - (FLAG.BINARY, str), |
365 | - ], |
366 | - FIELD_TYPE.STRING: [ |
367 | - (FLAG.BINARY, str), |
368 | - ], |
369 | - FIELD_TYPE.VAR_STRING: [ |
370 | - (FLAG.BINARY, str), |
371 | - ], |
372 | - FIELD_TYPE.VARCHAR: [ |
373 | - (FLAG.BINARY, str), |
374 | - ], |
375 | - } |
376 | - |
377 | -try: |
378 | - from decimal import Decimal |
379 | - conversions[FIELD_TYPE.DECIMAL] = Decimal |
380 | - conversions[FIELD_TYPE.NEWDECIMAL] = Decimal |
381 | -except ImportError: |
382 | - pass |
383 | - |
384 | -try: |
385 | - from types import BooleanType |
386 | - def Bool2Str(s, d): return str(int(s)) |
387 | - conversions[BooleanType] = Bool2Str |
388 | -except ImportError: |
389 | - pass |
390 | - |
391 | |
392 | === removed directory '.pc/05_ssl.patch' |
393 | === removed file '.pc/05_ssl.patch/_mysql.c' |
394 | --- .pc/05_ssl.patch/_mysql.c 2013-03-11 18:03:06 +0000 |
395 | +++ .pc/05_ssl.patch/_mysql.c 1970-01-01 00:00:00 +0000 |
396 | @@ -1,2890 +0,0 @@ |
397 | -/* |
398 | -This program is free software; you can redistribute it and/or modify |
399 | -it under the terms of the GNU General Public License as published by |
400 | -the Free Software Foundation; either version 2, or (at your option) |
401 | -any later version. Alternatively, you may use the original license |
402 | -reproduced below. |
403 | - |
404 | -Copyright 1999 by Comstar.net, Inc., Atlanta, GA, US. |
405 | - |
406 | - All Rights Reserved |
407 | - |
408 | -Permission to use, copy, modify, and distribute this software and its |
409 | -documentation for any purpose and without fee is hereby granted, |
410 | -provided that the above copyright notice appear in all copies and that |
411 | -both that copyright notice and this permission notice appear in |
412 | -supporting documentation, and that the name of Comstar.net, Inc. |
413 | -or COMSTAR not be used in advertising or publicity pertaining to |
414 | -distribution of the software without specific, written prior permission. |
415 | - |
416 | -COMSTAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
417 | -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
418 | -EVENT SHALL COMSTAR BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
419 | -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
420 | -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
421 | -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
422 | -PERFORMANCE OF THIS SOFTWARE. |
423 | -*/ |
424 | - |
425 | -#include "pymemcompat.h" |
426 | -#include "structmember.h" |
427 | -#if defined(MS_WINDOWS) |
428 | -#include <winsock2.h> |
429 | -#include <windows.h> |
430 | -#include <config-win.h> |
431 | -#else |
432 | -#include "my_config.h" |
433 | -#endif |
434 | -#include "mysql.h" |
435 | -#include "mysqld_error.h" |
436 | -#include "errmsg.h" |
437 | - |
438 | -#if PY_VERSION_HEX < 0x02020000 |
439 | -# define MyTuple_Resize(t,n,d) _PyTuple_Resize(t, n, d) |
440 | -# define MyMember(a,b,c,d,e) {a,b,c,d} |
441 | -# define MyMemberlist(x) struct memberlist x |
442 | -# define MyAlloc(s,t) PyObject_New(s,&t) |
443 | -# define MyFree(o) PyObject_Del(o) |
444 | -#else |
445 | -# define MyTuple_Resize(t,n,d) _PyTuple_Resize(t, n) |
446 | -# define MyMember(a,b,c,d,e) {a,b,c,d,e} |
447 | -# define MyMemberlist(x) struct PyMemberDef x |
448 | -# define MyAlloc(s,t) (s *) t.tp_alloc(&t,0) |
449 | -# define MyFree(ob) ob->ob_type->tp_free((PyObject *)ob) |
450 | -#endif |
451 | - |
452 | -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) |
453 | -typedef int Py_ssize_t; |
454 | -#define PY_SSIZE_T_MAX INT_MAX |
455 | -#define PY_SSIZE_T_MIN INT_MIN |
456 | -#endif |
457 | - |
458 | -static PyObject *_mysql_MySQLError; |
459 | -static PyObject *_mysql_Warning; |
460 | -static PyObject *_mysql_Error; |
461 | -static PyObject *_mysql_DatabaseError; |
462 | -static PyObject *_mysql_InterfaceError; |
463 | -static PyObject *_mysql_DataError; |
464 | -static PyObject *_mysql_OperationalError; |
465 | -static PyObject *_mysql_IntegrityError; |
466 | -static PyObject *_mysql_InternalError; |
467 | -static PyObject *_mysql_ProgrammingError; |
468 | -static PyObject *_mysql_NotSupportedError; |
469 | - |
470 | -typedef struct { |
471 | - PyObject_HEAD |
472 | - MYSQL connection; |
473 | - int open; |
474 | - PyObject *converter; |
475 | -} _mysql_ConnectionObject; |
476 | - |
477 | -#define check_connection(c) if (!(c->open)) return _mysql_Exception(c) |
478 | -#define result_connection(r) ((_mysql_ConnectionObject *)r->conn) |
479 | -#define check_result_connection(r) check_connection(result_connection(r)) |
480 | - |
481 | -extern PyTypeObject _mysql_ConnectionObject_Type; |
482 | - |
483 | -typedef struct { |
484 | - PyObject_HEAD |
485 | - PyObject *conn; |
486 | - MYSQL_RES *result; |
487 | - int nfields; |
488 | - int use; |
489 | - PyObject *converter; |
490 | -} _mysql_ResultObject; |
491 | - |
492 | -extern PyTypeObject _mysql_ResultObject_Type; |
493 | - |
494 | -static int _mysql_server_init_done = 0; |
495 | -#if MYSQL_VERSION_ID >= 40000 |
496 | -#define check_server_init(x) if (!_mysql_server_init_done) { if (mysql_server_init(0, NULL, NULL)) { _mysql_Exception(NULL); return x; } else { _mysql_server_init_done = 1;} } |
497 | -#else |
498 | -#define check_server_init(x) if (!_mysql_server_init_done) _mysql_server_init_done = 1 |
499 | -#endif |
500 | - |
501 | -PyObject * |
502 | -_mysql_Exception(_mysql_ConnectionObject *c) |
503 | -{ |
504 | - PyObject *t, *e; |
505 | - int merr; |
506 | - |
507 | - if (!(t = PyTuple_New(2))) return NULL; |
508 | - if (!_mysql_server_init_done) { |
509 | - e = _mysql_InternalError; |
510 | - PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L)); |
511 | - PyTuple_SET_ITEM(t, 1, PyString_FromString("server not initialized")); |
512 | - PyErr_SetObject(e, t); |
513 | - Py_DECREF(t); |
514 | - return NULL; |
515 | - } |
516 | - merr = mysql_errno(&(c->connection)); |
517 | - if (!merr) |
518 | - e = _mysql_InterfaceError; |
519 | - else if (merr > CR_MAX_ERROR) { |
520 | - PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L)); |
521 | - PyTuple_SET_ITEM(t, 1, PyString_FromString("error totally whack")); |
522 | - PyErr_SetObject(_mysql_InterfaceError, t); |
523 | - Py_DECREF(t); |
524 | - return NULL; |
525 | - } |
526 | - else switch (merr) { |
527 | - case CR_COMMANDS_OUT_OF_SYNC: |
528 | - case ER_DB_CREATE_EXISTS: |
529 | - case ER_SYNTAX_ERROR: |
530 | - case ER_PARSE_ERROR: |
531 | - case ER_NO_SUCH_TABLE: |
532 | - case ER_WRONG_DB_NAME: |
533 | - case ER_WRONG_TABLE_NAME: |
534 | - case ER_FIELD_SPECIFIED_TWICE: |
535 | - case ER_INVALID_GROUP_FUNC_USE: |
536 | - case ER_UNSUPPORTED_EXTENSION: |
537 | - case ER_TABLE_MUST_HAVE_COLUMNS: |
538 | -#ifdef ER_CANT_DO_THIS_DURING_AN_TRANSACTION |
539 | - case ER_CANT_DO_THIS_DURING_AN_TRANSACTION: |
540 | -#endif |
541 | - e = _mysql_ProgrammingError; |
542 | - break; |
543 | -#ifdef WARN_DATA_TRUNCATED |
544 | - case WARN_DATA_TRUNCATED: |
545 | -#ifdef WARN_NULL_TO_NOTNULL |
546 | - case WARN_NULL_TO_NOTNULL: |
547 | -#endif |
548 | -#ifdef ER_WARN_DATA_OUT_OF_RANGE |
549 | - case ER_WARN_DATA_OUT_OF_RANGE: |
550 | -#endif |
551 | -#ifdef ER_NO_DEFAULT |
552 | - case ER_NO_DEFAULT: |
553 | -#endif |
554 | -#ifdef ER_PRIMARY_CANT_HAVE_NULL |
555 | - case ER_PRIMARY_CANT_HAVE_NULL: |
556 | -#endif |
557 | -#ifdef ER_DATA_TOO_LONG |
558 | - case ER_DATA_TOO_LONG: |
559 | -#endif |
560 | -#ifdef ER_DATETIME_FUNCTION_OVERFLOW |
561 | - case ER_DATETIME_FUNCTION_OVERFLOW: |
562 | -#endif |
563 | - e = _mysql_DataError; |
564 | - break; |
565 | -#endif |
566 | - case ER_DUP_ENTRY: |
567 | -#ifdef ER_DUP_UNIQUE |
568 | - case ER_DUP_UNIQUE: |
569 | -#endif |
570 | -#ifdef ER_NO_REFERENCED_ROW |
571 | - case ER_NO_REFERENCED_ROW: |
572 | -#endif |
573 | -#ifdef ER_NO_REFERENCED_ROW_2 |
574 | - case ER_NO_REFERENCED_ROW_2: |
575 | -#endif |
576 | -#ifdef ER_ROW_IS_REFERENCED |
577 | - case ER_ROW_IS_REFERENCED: |
578 | -#endif |
579 | -#ifdef ER_ROW_IS_REFERENCED_2 |
580 | - case ER_ROW_IS_REFERENCED_2: |
581 | -#endif |
582 | -#ifdef ER_CANNOT_ADD_FOREIGN |
583 | - case ER_CANNOT_ADD_FOREIGN: |
584 | -#endif |
585 | - e = _mysql_IntegrityError; |
586 | - break; |
587 | -#ifdef ER_WARNING_NOT_COMPLETE_ROLLBACK |
588 | - case ER_WARNING_NOT_COMPLETE_ROLLBACK: |
589 | -#endif |
590 | -#ifdef ER_NOT_SUPPORTED_YET |
591 | - case ER_NOT_SUPPORTED_YET: |
592 | -#endif |
593 | -#ifdef ER_FEATURE_DISABLED |
594 | - case ER_FEATURE_DISABLED: |
595 | -#endif |
596 | -#ifdef ER_UNKNOWN_STORAGE_ENGINE |
597 | - case ER_UNKNOWN_STORAGE_ENGINE: |
598 | -#endif |
599 | - e = _mysql_NotSupportedError; |
600 | - break; |
601 | - default: |
602 | - if (merr < 1000) |
603 | - e = _mysql_InternalError; |
604 | - else |
605 | - e = _mysql_OperationalError; |
606 | - break; |
607 | - } |
608 | - PyTuple_SET_ITEM(t, 0, PyInt_FromLong((long)merr)); |
609 | - PyTuple_SET_ITEM(t, 1, PyString_FromString(mysql_error(&(c->connection)))); |
610 | - PyErr_SetObject(e, t); |
611 | - Py_DECREF(t); |
612 | - return NULL; |
613 | -} |
614 | - |
615 | -static char _mysql_server_init__doc__[] = |
616 | -"Initialize embedded server. If this client is not linked against\n\ |
617 | -the embedded server library, this function does nothing.\n\ |
618 | -\n\ |
619 | -args -- sequence of command-line arguments\n\ |
620 | -groups -- sequence of groups to use in defaults files\n\ |
621 | -"; |
622 | - |
623 | -static PyObject *_mysql_server_init( |
624 | - PyObject *self, |
625 | - PyObject *args, |
626 | - PyObject *kwargs) { |
627 | - static char *kwlist[] = {"args", "groups", NULL}; |
628 | - char **cmd_args_c=NULL, **groups_c=NULL, *s; |
629 | - int cmd_argc=0, i, groupc; |
630 | - PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item; |
631 | - |
632 | - if (_mysql_server_init_done) { |
633 | - PyErr_SetString(_mysql_ProgrammingError, |
634 | - "already initialized"); |
635 | - return NULL; |
636 | - } |
637 | - |
638 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist, |
639 | - &cmd_args, &groups)) |
640 | - return NULL; |
641 | - |
642 | -#if MYSQL_VERSION_ID >= 40000 |
643 | - if (cmd_args) { |
644 | - if (!PySequence_Check(cmd_args)) { |
645 | - PyErr_SetString(PyExc_TypeError, |
646 | - "args must be a sequence"); |
647 | - goto finish; |
648 | - } |
649 | - cmd_argc = PySequence_Size(cmd_args); |
650 | - if (cmd_argc == -1) { |
651 | - PyErr_SetString(PyExc_TypeError, |
652 | - "args could not be sized"); |
653 | - goto finish; |
654 | - } |
655 | - cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *)); |
656 | - for (i=0; i< cmd_argc; i++) { |
657 | - item = PySequence_GetItem(cmd_args, i); |
658 | - s = PyString_AsString(item); |
659 | - Py_DECREF(item); |
660 | - if (!s) { |
661 | - PyErr_SetString(PyExc_TypeError, |
662 | - "args must contain strings"); |
663 | - goto finish; |
664 | - } |
665 | - cmd_args_c[i] = s; |
666 | - } |
667 | - } |
668 | - if (groups) { |
669 | - if (!PySequence_Check(groups)) { |
670 | - PyErr_SetString(PyExc_TypeError, |
671 | - "groups must be a sequence"); |
672 | - goto finish; |
673 | - } |
674 | - groupc = PySequence_Size(groups); |
675 | - if (groupc == -1) { |
676 | - PyErr_SetString(PyExc_TypeError, |
677 | - "groups could not be sized"); |
678 | - goto finish; |
679 | - } |
680 | - groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *)); |
681 | - for (i=0; i< groupc; i++) { |
682 | - item = PySequence_GetItem(groups, i); |
683 | - s = PyString_AsString(item); |
684 | - Py_DECREF(item); |
685 | - if (!s) { |
686 | - PyErr_SetString(PyExc_TypeError, |
687 | - "groups must contain strings"); |
688 | - goto finish; |
689 | - } |
690 | - groups_c[i] = s; |
691 | - } |
692 | - groups_c[groupc] = (char *)NULL; |
693 | - } |
694 | - /* even though this may block, don't give up the interpreter lock |
695 | - so that the server can't be initialized multiple times. */ |
696 | - if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) { |
697 | - _mysql_Exception(NULL); |
698 | - goto finish; |
699 | - } |
700 | -#endif |
701 | - ret = Py_None; |
702 | - Py_INCREF(Py_None); |
703 | - _mysql_server_init_done = 1; |
704 | - finish: |
705 | - PyMem_Free(groups_c); |
706 | - PyMem_Free(cmd_args_c); |
707 | - return ret; |
708 | -} |
709 | - |
710 | -static char _mysql_server_end__doc__[] = |
711 | -"Shut down embedded server. If not using an embedded server, this\n\ |
712 | -does nothing."; |
713 | - |
714 | -static PyObject *_mysql_server_end( |
715 | - PyObject *self, |
716 | - PyObject *args) { |
717 | - if (_mysql_server_init_done) { |
718 | -#if MYSQL_VERSION_ID >= 40000 |
719 | - mysql_server_end(); |
720 | -#endif |
721 | - _mysql_server_init_done = 0; |
722 | - Py_INCREF(Py_None); |
723 | - return Py_None; |
724 | - } |
725 | - return _mysql_Exception(NULL); |
726 | -} |
727 | - |
728 | -#if MYSQL_VERSION_ID >= 32314 |
729 | -static char _mysql_thread_safe__doc__[] = |
730 | -"Indicates whether the client is compiled as thread-safe."; |
731 | - |
732 | -static PyObject *_mysql_thread_safe( |
733 | - PyObject *self, |
734 | - PyObject *args) { |
735 | - PyObject *flag; |
736 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
737 | - check_server_init(NULL); |
738 | - if (!(flag=PyInt_FromLong((long)mysql_thread_safe()))) return NULL; |
739 | - return flag; |
740 | -} |
741 | -#endif |
742 | - |
743 | -static char _mysql_ResultObject__doc__[] = |
744 | -"result(connection, use=0, converter={}) -- Result set from a query.\n\ |
745 | -\n\ |
746 | -Creating instances of this class directly is an excellent way to\n\ |
747 | -shoot yourself in the foot. If using _mysql.connection directly,\n\ |
748 | -use connection.store_result() or connection.use_result() instead.\n\ |
749 | -If using MySQLdb.Connection, this is done by the cursor class.\n\ |
750 | -Just forget you ever saw this. Forget... FOR-GET..."; |
751 | - |
752 | -static int |
753 | -_mysql_ResultObject_Initialize( |
754 | - _mysql_ResultObject *self, |
755 | - PyObject *args, |
756 | - PyObject *kwargs) |
757 | -{ |
758 | - static char *kwlist[] = {"connection", "use", "converter", NULL}; |
759 | - MYSQL_RES *result; |
760 | - _mysql_ConnectionObject *conn=NULL; |
761 | - int use=0; |
762 | - PyObject *conv=NULL; |
763 | - int n, i; |
764 | - MYSQL_FIELD *fields; |
765 | - |
766 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist, |
767 | - &conn, &use, &conv)) |
768 | - return -1; |
769 | - if (!conv) conv = PyDict_New(); |
770 | - if (!conv) return -1; |
771 | - self->conn = (PyObject *) conn; |
772 | - Py_INCREF(conn); |
773 | - self->use = use; |
774 | - Py_BEGIN_ALLOW_THREADS ; |
775 | - if (use) |
776 | - result = mysql_use_result(&(conn->connection)); |
777 | - else |
778 | - result = mysql_store_result(&(conn->connection)); |
779 | - self->result = result; |
780 | - Py_END_ALLOW_THREADS ; |
781 | - if (!result) { |
782 | - self->converter = PyTuple_New(0); |
783 | - return 0; |
784 | - } |
785 | - n = mysql_num_fields(result); |
786 | - self->nfields = n; |
787 | - if (!(self->converter = PyTuple_New(n))) return -1; |
788 | - fields = mysql_fetch_fields(result); |
789 | - for (i=0; i<n; i++) { |
790 | - PyObject *tmp, *fun; |
791 | - tmp = PyInt_FromLong((long) fields[i].type); |
792 | - if (!tmp) return -1; |
793 | - fun = PyObject_GetItem(conv, tmp); |
794 | - Py_DECREF(tmp); |
795 | - if (!fun) { |
796 | - PyErr_Clear(); |
797 | - fun = Py_None; |
798 | - Py_INCREF(Py_None); |
799 | - } |
800 | - if (PySequence_Check(fun)) { |
801 | - int j, n2=PySequence_Size(fun); |
802 | - PyObject *fun2=NULL; |
803 | - for (j=0; j<n2; j++) { |
804 | - PyObject *t = PySequence_GetItem(fun, j); |
805 | - if (!t) continue; |
806 | - if (!PyTuple_Check(t)) goto cleanup; |
807 | - if (PyTuple_GET_SIZE(t) == 2) { |
808 | - long mask; |
809 | - PyObject *pmask=NULL; |
810 | - pmask = PyTuple_GET_ITEM(t, 0); |
811 | - fun2 = PyTuple_GET_ITEM(t, 1); |
812 | - if (PyInt_Check(pmask)) { |
813 | - mask = PyInt_AS_LONG(pmask); |
814 | - if (mask & fields[i].flags) { |
815 | - Py_DECREF(t); |
816 | - break; |
817 | - } |
818 | - else { |
819 | - goto cleanup; |
820 | - } |
821 | - } else { |
822 | - Py_DECREF(t); |
823 | - break; |
824 | - } |
825 | - } |
826 | - cleanup: |
827 | - Py_DECREF(t); |
828 | - } |
829 | - if (!fun2) fun2 = Py_None; |
830 | - Py_INCREF(fun2); |
831 | - Py_DECREF(fun); |
832 | - fun = fun2; |
833 | - } |
834 | - PyTuple_SET_ITEM(self->converter, i, fun); |
835 | - } |
836 | - return 0; |
837 | -} |
838 | - |
839 | -#if PY_VERSION_HEX >= 0x02020000 |
840 | -static int _mysql_ResultObject_traverse( |
841 | - _mysql_ResultObject *self, |
842 | - visitproc visit, |
843 | - void *arg) |
844 | -{ |
845 | - int r; |
846 | - if (self->converter) { |
847 | - if (!(r = visit(self->converter, arg))) return r; |
848 | - } |
849 | - if (self->conn) |
850 | - return visit(self->conn, arg); |
851 | - return 0; |
852 | -} |
853 | -#endif |
854 | - |
855 | -static int _mysql_ResultObject_clear( |
856 | - _mysql_ResultObject *self) |
857 | -{ |
858 | - Py_XDECREF(self->converter); |
859 | - self->converter = NULL; |
860 | - Py_XDECREF(self->conn); |
861 | - self->conn = NULL; |
862 | - return 0; |
863 | -} |
864 | - |
865 | -static int |
866 | -_mysql_ConnectionObject_Initialize( |
867 | - _mysql_ConnectionObject *self, |
868 | - PyObject *args, |
869 | - PyObject *kwargs) |
870 | -{ |
871 | - MYSQL *conn = NULL; |
872 | - PyObject *conv = NULL; |
873 | - PyObject *ssl = NULL; |
874 | -#if HAVE_OPENSSL |
875 | - char *key = NULL, *cert = NULL, *ca = NULL, |
876 | - *capath = NULL, *cipher = NULL; |
877 | -#endif |
878 | - char *host = NULL, *user = NULL, *passwd = NULL, |
879 | - *db = NULL, *unix_socket = NULL; |
880 | - unsigned int port = 0; |
881 | - unsigned int client_flag = 0; |
882 | - static char *kwlist[] = { "host", "user", "passwd", "db", "port", |
883 | - "unix_socket", "conv", |
884 | - "connect_timeout", "compress", |
885 | - "named_pipe", "init_command", |
886 | - "read_default_file", "read_default_group", |
887 | - "client_flag", "ssl", |
888 | - "local_infile", |
889 | - NULL } ; |
890 | - int connect_timeout = 0; |
891 | - int compress = -1, named_pipe = -1, local_infile = -1; |
892 | - char *init_command=NULL, |
893 | - *read_default_file=NULL, |
894 | - *read_default_group=NULL; |
895 | - |
896 | - self->converter = NULL; |
897 | - self->open = 0; |
898 | - check_server_init(-1); |
899 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ssssisOiiisssiOi:connect", |
900 | - kwlist, |
901 | - &host, &user, &passwd, &db, |
902 | - &port, &unix_socket, &conv, |
903 | - &connect_timeout, |
904 | - &compress, &named_pipe, |
905 | - &init_command, &read_default_file, |
906 | - &read_default_group, |
907 | - &client_flag, &ssl, |
908 | - &local_infile /* DO NOT PATCH FOR RECONNECT, IDIOTS |
909 | - IF YOU DO THIS, I WILL NOT SUPPORT YOUR PACKAGES. */ |
910 | - )) |
911 | - return -1; |
912 | - |
913 | -#define _stringsuck(d,t,s) {t=PyMapping_GetItemString(s,#d);\ |
914 | - if(t){d=PyString_AsString(t);Py_DECREF(t);}\ |
915 | - PyErr_Clear();} |
916 | - |
917 | - if (ssl) { |
918 | -#if HAVE_OPENSSL |
919 | - PyObject *value = NULL; |
920 | - _stringsuck(ca, value, ssl); |
921 | - _stringsuck(capath, value, ssl); |
922 | - _stringsuck(cert, value, ssl); |
923 | - _stringsuck(key, value, ssl); |
924 | - _stringsuck(cipher, value, ssl); |
925 | -#else |
926 | - PyErr_SetString(_mysql_NotSupportedError, |
927 | - "client library does not have SSL support"); |
928 | - return -1; |
929 | -#endif |
930 | - } |
931 | - |
932 | - Py_BEGIN_ALLOW_THREADS ; |
933 | - conn = mysql_init(&(self->connection)); |
934 | - if (connect_timeout) { |
935 | - unsigned int timeout = connect_timeout; |
936 | - mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT, |
937 | - (char *)&timeout); |
938 | - } |
939 | - if (compress != -1) { |
940 | - mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0); |
941 | - client_flag |= CLIENT_COMPRESS; |
942 | - } |
943 | - if (named_pipe != -1) |
944 | - mysql_options(&(self->connection), MYSQL_OPT_NAMED_PIPE, 0); |
945 | - if (init_command != NULL) |
946 | - mysql_options(&(self->connection), MYSQL_INIT_COMMAND, init_command); |
947 | - if (read_default_file != NULL) |
948 | - mysql_options(&(self->connection), MYSQL_READ_DEFAULT_FILE, read_default_file); |
949 | - if (read_default_group != NULL) |
950 | - mysql_options(&(self->connection), MYSQL_READ_DEFAULT_GROUP, read_default_group); |
951 | - |
952 | - if (local_infile != -1) |
953 | - mysql_options(&(self->connection), MYSQL_OPT_LOCAL_INFILE, (char *) &local_infile); |
954 | - |
955 | -#if HAVE_OPENSSL |
956 | - if (ssl) |
957 | - mysql_ssl_set(&(self->connection), |
958 | - key, cert, ca, capath, cipher); |
959 | -#endif |
960 | - |
961 | - conn = mysql_real_connect(&(self->connection), host, user, passwd, db, |
962 | - port, unix_socket, client_flag); |
963 | - |
964 | - Py_END_ALLOW_THREADS ; |
965 | - |
966 | - if (!conn) { |
967 | - _mysql_Exception(self); |
968 | - return -1; |
969 | - } |
970 | - |
971 | - /* Internal references to python-land objects */ |
972 | - if (!conv) |
973 | - conv = PyDict_New(); |
974 | - else |
975 | - Py_INCREF(conv); |
976 | - |
977 | - if (!conv) |
978 | - return -1; |
979 | - self->converter = conv; |
980 | - |
981 | - /* |
982 | - PyType_GenericAlloc() automatically sets up GC allocation and |
983 | - tracking for GC objects, at least in 2.2.1, so it does not need to |
984 | - be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(), |
985 | - however. |
986 | - */ |
987 | - self->open = 1; |
988 | - return 0; |
989 | -} |
990 | - |
991 | -static char _mysql_connect__doc__[] = |
992 | -"Returns a MYSQL connection object. Exclusive use of\n\ |
993 | -keyword parameters strongly recommended. Consult the\n\ |
994 | -MySQL C API documentation for more details.\n\ |
995 | -\n\ |
996 | -host\n\ |
997 | - string, host to connect\n\ |
998 | -\n\ |
999 | -user\n\ |
1000 | - string, user to connect as\n\ |
1001 | -\n\ |
1002 | -passwd\n\ |
1003 | - string, password to use\n\ |
1004 | -\n\ |
1005 | -db\n\ |
1006 | - string, database to use\n\ |
1007 | -\n\ |
1008 | -port\n\ |
1009 | - integer, TCP/IP port to connect to\n\ |
1010 | -\n\ |
1011 | -unix_socket\n\ |
1012 | - string, location of unix_socket (UNIX-ish only)\n\ |
1013 | -\n\ |
1014 | -conv\n\ |
1015 | - mapping, maps MySQL FIELD_TYPE.* to Python functions which\n\ |
1016 | - convert a string to the appropriate Python type\n\ |
1017 | -\n\ |
1018 | -connect_timeout\n\ |
1019 | - number of seconds to wait before the connection\n\ |
1020 | - attempt fails.\n\ |
1021 | -\n\ |
1022 | -compress\n\ |
1023 | - if set, gzip compression is enabled\n\ |
1024 | -\n\ |
1025 | -named_pipe\n\ |
1026 | - if set, connect to server via named pipe (Windows only)\n\ |
1027 | -\n\ |
1028 | -init_command\n\ |
1029 | - command which is run once the connection is created\n\ |
1030 | -\n\ |
1031 | -read_default_file\n\ |
1032 | - see the MySQL documentation for mysql_options()\n\ |
1033 | -\n\ |
1034 | -read_default_group\n\ |
1035 | - see the MySQL documentation for mysql_options()\n\ |
1036 | -\n\ |
1037 | -client_flag\n\ |
1038 | - client flags from MySQLdb.constants.CLIENT\n\ |
1039 | -\n\ |
1040 | -load_infile\n\ |
1041 | - int, non-zero enables LOAD LOCAL INFILE, zero disables\n\ |
1042 | -\n\ |
1043 | -"; |
1044 | - |
1045 | -static PyObject * |
1046 | -_mysql_connect( |
1047 | - PyObject *self, |
1048 | - PyObject *args, |
1049 | - PyObject *kwargs) |
1050 | -{ |
1051 | - _mysql_ConnectionObject *c=NULL; |
1052 | - |
1053 | - c = MyAlloc(_mysql_ConnectionObject, _mysql_ConnectionObject_Type); |
1054 | - if (c == NULL) return NULL; |
1055 | - if (_mysql_ConnectionObject_Initialize(c, args, kwargs)) { |
1056 | - Py_DECREF(c); |
1057 | - c = NULL; |
1058 | - } |
1059 | - return (PyObject *) c; |
1060 | -} |
1061 | - |
1062 | -#if PY_VERSION_HEX >= 0x02020000 |
1063 | -static int _mysql_ConnectionObject_traverse( |
1064 | - _mysql_ConnectionObject *self, |
1065 | - visitproc visit, |
1066 | - void *arg) |
1067 | -{ |
1068 | - if (self->converter) |
1069 | - return visit(self->converter, arg); |
1070 | - return 0; |
1071 | -} |
1072 | -#endif |
1073 | - |
1074 | -static int _mysql_ConnectionObject_clear( |
1075 | - _mysql_ConnectionObject *self) |
1076 | -{ |
1077 | - Py_XDECREF(self->converter); |
1078 | - self->converter = NULL; |
1079 | - return 0; |
1080 | -} |
1081 | - |
1082 | -static char _mysql_ConnectionObject_close__doc__[] = |
1083 | -"Close the connection. No further activity possible."; |
1084 | - |
1085 | -static PyObject * |
1086 | -_mysql_ConnectionObject_close( |
1087 | - _mysql_ConnectionObject *self, |
1088 | - PyObject *args) |
1089 | -{ |
1090 | - if (args) { |
1091 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1092 | - } |
1093 | - if (self->open) { |
1094 | - Py_BEGIN_ALLOW_THREADS |
1095 | - mysql_close(&(self->connection)); |
1096 | - Py_END_ALLOW_THREADS |
1097 | - self->open = 0; |
1098 | - } else { |
1099 | - PyErr_SetString(_mysql_ProgrammingError, |
1100 | - "closing a closed connection"); |
1101 | - return NULL; |
1102 | - } |
1103 | - _mysql_ConnectionObject_clear(self); |
1104 | - Py_INCREF(Py_None); |
1105 | - return Py_None; |
1106 | -} |
1107 | - |
1108 | -static char _mysql_ConnectionObject_affected_rows__doc__ [] = |
1109 | -"Return number of rows affected by the last query.\n\ |
1110 | -Non-standard. Use Cursor.rowcount.\n\ |
1111 | -"; |
1112 | - |
1113 | -static PyObject * |
1114 | -_mysql_ConnectionObject_affected_rows( |
1115 | - _mysql_ConnectionObject *self, |
1116 | - PyObject *args) |
1117 | -{ |
1118 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1119 | - check_connection(self); |
1120 | - return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection))); |
1121 | -} |
1122 | - |
1123 | -static char _mysql_debug__doc__[] = |
1124 | -"Does a DBUG_PUSH with the given string.\n\ |
1125 | -mysql_debug() uses the Fred Fish debug library.\n\ |
1126 | -To use this function, you must compile the client library to\n\ |
1127 | -support debugging.\n\ |
1128 | -"; |
1129 | -static PyObject * |
1130 | -_mysql_debug( |
1131 | - PyObject *self, |
1132 | - PyObject *args) |
1133 | -{ |
1134 | - char *debug; |
1135 | - if (!PyArg_ParseTuple(args, "s", &debug)) return NULL; |
1136 | - mysql_debug(debug); |
1137 | - Py_INCREF(Py_None); |
1138 | - return Py_None; |
1139 | -} |
1140 | - |
1141 | -static char _mysql_ConnectionObject_dump_debug_info__doc__[] = |
1142 | -"Instructs the server to write some debug information to the\n\ |
1143 | -log. The connected user must have the process privilege for\n\ |
1144 | -this to work. Non-standard.\n\ |
1145 | -"; |
1146 | - |
1147 | -static PyObject * |
1148 | -_mysql_ConnectionObject_dump_debug_info( |
1149 | - _mysql_ConnectionObject *self, |
1150 | - PyObject *args) |
1151 | -{ |
1152 | - int err; |
1153 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1154 | - check_connection(self); |
1155 | - Py_BEGIN_ALLOW_THREADS |
1156 | - err = mysql_dump_debug_info(&(self->connection)); |
1157 | - Py_END_ALLOW_THREADS |
1158 | - if (err) return _mysql_Exception(self); |
1159 | - Py_INCREF(Py_None); |
1160 | - return Py_None; |
1161 | -} |
1162 | - |
1163 | -static char _mysql_ConnectionObject_autocommit__doc__[] = |
1164 | -"Set the autocommit mode. True values enable; False value disable.\n\ |
1165 | -"; |
1166 | -static PyObject * |
1167 | -_mysql_ConnectionObject_autocommit( |
1168 | - _mysql_ConnectionObject *self, |
1169 | - PyObject *args) |
1170 | -{ |
1171 | - int flag, err; |
1172 | - if (!PyArg_ParseTuple(args, "i", &flag)) return NULL; |
1173 | - Py_BEGIN_ALLOW_THREADS |
1174 | -#if MYSQL_VERSION_ID >= 40100 |
1175 | - err = mysql_autocommit(&(self->connection), flag); |
1176 | -#else |
1177 | - { |
1178 | - char query[256]; |
1179 | - snprintf(query, 256, "SET AUTOCOMMIT=%d", flag); |
1180 | - err = mysql_query(&(self->connection), query); |
1181 | - } |
1182 | -#endif |
1183 | - Py_END_ALLOW_THREADS |
1184 | - if (err) return _mysql_Exception(self); |
1185 | - Py_INCREF(Py_None); |
1186 | - return Py_None; |
1187 | -} |
1188 | - |
1189 | -static char _mysql_ConnectionObject_commit__doc__[] = |
1190 | -"Commits the current transaction\n\ |
1191 | -"; |
1192 | -static PyObject * |
1193 | -_mysql_ConnectionObject_commit( |
1194 | - _mysql_ConnectionObject *self, |
1195 | - PyObject *args) |
1196 | -{ |
1197 | - int err; |
1198 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1199 | - Py_BEGIN_ALLOW_THREADS |
1200 | -#if MYSQL_VERSION_ID >= 40100 |
1201 | - err = mysql_commit(&(self->connection)); |
1202 | -#else |
1203 | - err = mysql_query(&(self->connection), "COMMIT"); |
1204 | -#endif |
1205 | - Py_END_ALLOW_THREADS |
1206 | - if (err) return _mysql_Exception(self); |
1207 | - Py_INCREF(Py_None); |
1208 | - return Py_None; |
1209 | -} |
1210 | - |
1211 | -static char _mysql_ConnectionObject_rollback__doc__[] = |
1212 | -"Rolls backs the current transaction\n\ |
1213 | -"; |
1214 | -static PyObject * |
1215 | -_mysql_ConnectionObject_rollback( |
1216 | - _mysql_ConnectionObject *self, |
1217 | - PyObject *args) |
1218 | -{ |
1219 | - int err; |
1220 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1221 | - Py_BEGIN_ALLOW_THREADS |
1222 | -#if MYSQL_VERSION_ID >= 40100 |
1223 | - err = mysql_rollback(&(self->connection)); |
1224 | -#else |
1225 | - err = mysql_query(&(self->connection), "ROLLBACK"); |
1226 | -#endif |
1227 | - Py_END_ALLOW_THREADS |
1228 | - if (err) return _mysql_Exception(self); |
1229 | - Py_INCREF(Py_None); |
1230 | - return Py_None; |
1231 | -} |
1232 | - |
1233 | -static char _mysql_ConnectionObject_next_result__doc__[] = |
1234 | -"If more query results exist, next_result() reads the next query\n\ |
1235 | -results and returns the status back to application.\n\ |
1236 | -\n\ |
1237 | -After calling next_result() the state of the connection is as if\n\ |
1238 | -you had called query() for the next query. This means that you can\n\ |
1239 | -now call store_result(), warning_count(), affected_rows()\n\ |
1240 | -, and so forth. \n\ |
1241 | -\n\ |
1242 | -Returns 0 if there are more results; -1 if there are no more results\n\ |
1243 | -\n\ |
1244 | -Non-standard.\n\ |
1245 | -"; |
1246 | -static PyObject * |
1247 | -_mysql_ConnectionObject_next_result( |
1248 | - _mysql_ConnectionObject *self, |
1249 | - PyObject *args) |
1250 | -{ |
1251 | - int err; |
1252 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1253 | - Py_BEGIN_ALLOW_THREADS |
1254 | -#if MYSQL_VERSION_ID >= 40100 |
1255 | - err = mysql_next_result(&(self->connection)); |
1256 | -#else |
1257 | - err = -1; |
1258 | -#endif |
1259 | - Py_END_ALLOW_THREADS |
1260 | - if (err > 0) return _mysql_Exception(self); |
1261 | - return PyInt_FromLong(err); |
1262 | -} |
1263 | - |
1264 | -#if MYSQL_VERSION_ID >= 40100 |
1265 | - |
1266 | -static char _mysql_ConnectionObject_set_server_option__doc__[] = |
1267 | -"set_server_option(option) -- Enables or disables an option\n\ |
1268 | -for the connection.\n\ |
1269 | -\n\ |
1270 | -Non-standard.\n\ |
1271 | -"; |
1272 | -static PyObject * |
1273 | -_mysql_ConnectionObject_set_server_option( |
1274 | - _mysql_ConnectionObject *self, |
1275 | - PyObject *args) |
1276 | -{ |
1277 | - int err, flags=0; |
1278 | - if (!PyArg_ParseTuple(args, "i", &flags)) |
1279 | - return NULL; |
1280 | - Py_BEGIN_ALLOW_THREADS |
1281 | - err = mysql_set_server_option(&(self->connection), flags); |
1282 | - Py_END_ALLOW_THREADS |
1283 | - if (err) return _mysql_Exception(self); |
1284 | - return PyInt_FromLong(err); |
1285 | -} |
1286 | - |
1287 | -static char _mysql_ConnectionObject_sqlstate__doc__[] = |
1288 | -"Returns a string containing the SQLSTATE error code\n\ |
1289 | -for the last error. The error code consists of five characters.\n\ |
1290 | -'00000' means \"no error.\" The values are specified by ANSI SQL\n\ |
1291 | -and ODBC. For a list of possible values, see section 23\n\ |
1292 | -Error Handling in MySQL in the MySQL Manual.\n\ |
1293 | -\n\ |
1294 | -Note that not all MySQL errors are yet mapped to SQLSTATE's.\n\ |
1295 | -The value 'HY000' (general error) is used for unmapped errors.\n\ |
1296 | -\n\ |
1297 | -Non-standard.\n\ |
1298 | -"; |
1299 | -static PyObject * |
1300 | -_mysql_ConnectionObject_sqlstate( |
1301 | - _mysql_ConnectionObject *self, |
1302 | - PyObject *args) |
1303 | -{ |
1304 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1305 | - return PyString_FromString(mysql_sqlstate(&(self->connection))); |
1306 | -} |
1307 | - |
1308 | -static char _mysql_ConnectionObject_warning_count__doc__[] = |
1309 | -"Returns the number of warnings generated during execution\n\ |
1310 | -of the previous SQL statement.\n\ |
1311 | -\n\ |
1312 | -Non-standard.\n\ |
1313 | -"; |
1314 | -static PyObject * |
1315 | -_mysql_ConnectionObject_warning_count( |
1316 | - _mysql_ConnectionObject *self, |
1317 | - PyObject *args) |
1318 | -{ |
1319 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1320 | - return PyInt_FromLong(mysql_warning_count(&(self->connection))); |
1321 | -} |
1322 | - |
1323 | -#endif |
1324 | - |
1325 | -static char _mysql_ConnectionObject_errno__doc__[] = |
1326 | -"Returns the error code for the most recently invoked API function\n\ |
1327 | -that can succeed or fail. A return value of zero means that no error\n\ |
1328 | -occurred.\n\ |
1329 | -"; |
1330 | - |
1331 | -static PyObject * |
1332 | -_mysql_ConnectionObject_errno( |
1333 | - _mysql_ConnectionObject *self, |
1334 | - PyObject *args) |
1335 | -{ |
1336 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1337 | - check_connection(self); |
1338 | - return PyInt_FromLong((long)mysql_errno(&(self->connection))); |
1339 | -} |
1340 | - |
1341 | -static char _mysql_ConnectionObject_error__doc__[] = |
1342 | -"Returns the error message for the most recently invoked API function\n\ |
1343 | -that can succeed or fail. An empty string ("") is returned if no error\n\ |
1344 | -occurred.\n\ |
1345 | -"; |
1346 | - |
1347 | -static PyObject * |
1348 | -_mysql_ConnectionObject_error( |
1349 | - _mysql_ConnectionObject *self, |
1350 | - PyObject *args) |
1351 | -{ |
1352 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1353 | - check_connection(self); |
1354 | - return PyString_FromString(mysql_error(&(self->connection))); |
1355 | -} |
1356 | - |
1357 | -static char _mysql_escape_string__doc__[] = |
1358 | -"escape_string(s) -- quote any SQL-interpreted characters in string s.\n\ |
1359 | -\n\ |
1360 | -Use connection.escape_string(s), if you use it at all.\n\ |
1361 | -_mysql.escape_string(s) cannot handle character sets. You are\n\ |
1362 | -probably better off using connection.escape(o) instead, since\n\ |
1363 | -it will escape entire sequences as well as strings."; |
1364 | - |
1365 | -static PyObject * |
1366 | -_mysql_escape_string( |
1367 | - _mysql_ConnectionObject *self, |
1368 | - PyObject *args) |
1369 | -{ |
1370 | - PyObject *str; |
1371 | - char *in, *out; |
1372 | - int len, size; |
1373 | - if (!PyArg_ParseTuple(args, "s#:escape_string", &in, &size)) return NULL; |
1374 | - str = PyString_FromStringAndSize((char *) NULL, size*2+1); |
1375 | - if (!str) return PyErr_NoMemory(); |
1376 | - out = PyString_AS_STRING(str); |
1377 | -#if MYSQL_VERSION_ID < 32321 |
1378 | - len = mysql_escape_string(out, in, size); |
1379 | -#else |
1380 | - check_server_init(NULL); |
1381 | - if (self && self->open) |
1382 | - len = mysql_real_escape_string(&(self->connection), out, in, size); |
1383 | - else |
1384 | - len = mysql_escape_string(out, in, size); |
1385 | -#endif |
1386 | - if (_PyString_Resize(&str, len) < 0) return NULL; |
1387 | - return (str); |
1388 | -} |
1389 | - |
1390 | -static char _mysql_string_literal__doc__[] = |
1391 | -"string_literal(obj) -- converts object obj into a SQL string literal.\n\ |
1392 | -This means, any special SQL characters are escaped, and it is enclosed\n\ |
1393 | -within single quotes. In other words, it performs:\n\ |
1394 | -\n\ |
1395 | -\"'%s'\" % escape_string(str(obj))\n\ |
1396 | -\n\ |
1397 | -Use connection.string_literal(obj), if you use it at all.\n\ |
1398 | -_mysql.string_literal(obj) cannot handle character sets."; |
1399 | - |
1400 | -static PyObject * |
1401 | -_mysql_string_literal( |
1402 | - _mysql_ConnectionObject *self, |
1403 | - PyObject *args) |
1404 | -{ |
1405 | - PyObject *str, *s, *o, *d; |
1406 | - char *in, *out; |
1407 | - int len, size; |
1408 | - if (!PyArg_ParseTuple(args, "O|O:string_literal", &o, &d)) return NULL; |
1409 | - s = PyObject_Str(o); |
1410 | - if (!s) return NULL; |
1411 | - in = PyString_AsString(s); |
1412 | - size = PyString_GET_SIZE(s); |
1413 | - str = PyString_FromStringAndSize((char *) NULL, size*2+3); |
1414 | - if (!str) return PyErr_NoMemory(); |
1415 | - out = PyString_AS_STRING(str); |
1416 | -#if MYSQL_VERSION_ID < 32321 |
1417 | - len = mysql_escape_string(out+1, in, size); |
1418 | -#else |
1419 | - check_server_init(NULL); |
1420 | - if (self && self->open) |
1421 | - len = mysql_real_escape_string(&(self->connection), out+1, in, size); |
1422 | - else |
1423 | - len = mysql_escape_string(out+1, in, size); |
1424 | -#endif |
1425 | - *out = *(out+len+1) = '\''; |
1426 | - if (_PyString_Resize(&str, len+2) < 0) return NULL; |
1427 | - Py_DECREF(s); |
1428 | - return (str); |
1429 | -} |
1430 | - |
1431 | -static PyObject *_mysql_NULL; |
1432 | - |
1433 | -static PyObject * |
1434 | -_escape_item( |
1435 | - PyObject *item, |
1436 | - PyObject *d) |
1437 | -{ |
1438 | - PyObject *quoted=NULL, *itemtype, *itemconv; |
1439 | - if (!(itemtype = PyObject_Type(item))) |
1440 | - goto error; |
1441 | - itemconv = PyObject_GetItem(d, itemtype); |
1442 | - Py_DECREF(itemtype); |
1443 | - if (!itemconv) { |
1444 | - PyErr_Clear(); |
1445 | - itemconv = PyObject_GetItem(d, |
1446 | - (PyObject *) &PyString_Type); |
1447 | - } |
1448 | - if (!itemconv) { |
1449 | - PyErr_SetString(PyExc_TypeError, |
1450 | - "no default type converter defined"); |
1451 | - goto error; |
1452 | - } |
1453 | - quoted = PyObject_CallFunction(itemconv, "OO", item, d); |
1454 | - Py_DECREF(itemconv); |
1455 | -error: |
1456 | - return quoted; |
1457 | -} |
1458 | - |
1459 | -static char _mysql_escape__doc__[] = |
1460 | -"escape(obj, dict) -- escape any special characters in object obj\n\ |
1461 | -using mapping dict to provide quoting functions for each type.\n\ |
1462 | -Returns a SQL literal string."; |
1463 | -static PyObject * |
1464 | -_mysql_escape( |
1465 | - PyObject *self, |
1466 | - PyObject *args) |
1467 | -{ |
1468 | - PyObject *o=NULL, *d=NULL; |
1469 | - if (!PyArg_ParseTuple(args, "O|O:escape", &o, &d)) |
1470 | - return NULL; |
1471 | - if (d) { |
1472 | - if (!PyMapping_Check(d)) { |
1473 | - PyErr_SetString(PyExc_TypeError, |
1474 | - "argument 2 must be a mapping"); |
1475 | - return NULL; |
1476 | - } |
1477 | - return _escape_item(o, d); |
1478 | - } else { |
1479 | - if (!self) { |
1480 | - PyErr_SetString(PyExc_TypeError, |
1481 | - "argument 2 must be a mapping"); |
1482 | - return NULL; |
1483 | - } |
1484 | - return _escape_item(o, |
1485 | - ((_mysql_ConnectionObject *) self)->converter); |
1486 | - } |
1487 | -} |
1488 | - |
1489 | -static char _mysql_escape_sequence__doc__[] = |
1490 | -"escape_sequence(seq, dict) -- escape any special characters in sequence\n\ |
1491 | -seq using mapping dict to provide quoting functions for each type.\n\ |
1492 | -Returns a tuple of escaped items."; |
1493 | -static PyObject * |
1494 | -_mysql_escape_sequence( |
1495 | - PyObject *self, |
1496 | - PyObject *args) |
1497 | -{ |
1498 | - PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted; |
1499 | - int i, n; |
1500 | - if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d)) |
1501 | - goto error; |
1502 | - if (!PyMapping_Check(d)) { |
1503 | - PyErr_SetString(PyExc_TypeError, |
1504 | - "argument 2 must be a mapping"); |
1505 | - return NULL; |
1506 | - } |
1507 | - if ((n = PyObject_Length(o)) == -1) goto error; |
1508 | - if (!(r = PyTuple_New(n))) goto error; |
1509 | - for (i=0; i<n; i++) { |
1510 | - item = PySequence_GetItem(o, i); |
1511 | - if (!item) goto error; |
1512 | - quoted = _escape_item(item, d); |
1513 | - Py_DECREF(item); |
1514 | - if (!quoted) goto error; |
1515 | - PyTuple_SET_ITEM(r, i, quoted); |
1516 | - } |
1517 | - return r; |
1518 | - error: |
1519 | - Py_XDECREF(r); |
1520 | - return NULL; |
1521 | -} |
1522 | - |
1523 | -static char _mysql_escape_dict__doc__[] = |
1524 | -"escape_sequence(d, dict) -- escape any special characters in\n\ |
1525 | -dictionary d using mapping dict to provide quoting functions for each type.\n\ |
1526 | -Returns a dictionary of escaped items."; |
1527 | -static PyObject * |
1528 | -_mysql_escape_dict( |
1529 | - PyObject *self, |
1530 | - PyObject *args) |
1531 | -{ |
1532 | - PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey; |
1533 | - Py_ssize_t ppos = 0; |
1534 | - if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d)) |
1535 | - goto error; |
1536 | - if (!PyMapping_Check(d)) { |
1537 | - PyErr_SetString(PyExc_TypeError, |
1538 | - "argument 2 must be a mapping"); |
1539 | - return NULL; |
1540 | - } |
1541 | - if (!(r = PyDict_New())) goto error; |
1542 | - while (PyDict_Next(o, &ppos, &pkey, &item)) { |
1543 | - quoted = _escape_item(item, d); |
1544 | - if (!quoted) goto error; |
1545 | - if (PyDict_SetItem(r, pkey, quoted)==-1) goto error; |
1546 | - Py_DECREF(quoted); |
1547 | - } |
1548 | - return r; |
1549 | - error: |
1550 | - Py_XDECREF(r); |
1551 | - return NULL; |
1552 | -} |
1553 | - |
1554 | -static char _mysql_ResultObject_describe__doc__[] = |
1555 | -"Returns the sequence of 7-tuples required by the DB-API for\n\ |
1556 | -the Cursor.description attribute.\n\ |
1557 | -"; |
1558 | - |
1559 | -static PyObject * |
1560 | -_mysql_ResultObject_describe( |
1561 | - _mysql_ResultObject *self, |
1562 | - PyObject *args) |
1563 | -{ |
1564 | - PyObject *d; |
1565 | - MYSQL_FIELD *fields; |
1566 | - unsigned int i, n; |
1567 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1568 | - check_result_connection(self); |
1569 | - n = mysql_num_fields(self->result); |
1570 | - fields = mysql_fetch_fields(self->result); |
1571 | - if (!(d = PyTuple_New(n))) return NULL; |
1572 | - for (i=0; i<n; i++) { |
1573 | - PyObject *t; |
1574 | - t = Py_BuildValue("(siiiiii)", |
1575 | - fields[i].name, |
1576 | - (long) fields[i].type, |
1577 | - (long) fields[i].max_length, |
1578 | - (long) fields[i].length, |
1579 | - (long) fields[i].length, |
1580 | - (long) fields[i].decimals, |
1581 | - (long) !(IS_NOT_NULL(fields[i].flags))); |
1582 | - if (!t) goto error; |
1583 | - PyTuple_SET_ITEM(d, i, t); |
1584 | - } |
1585 | - return d; |
1586 | - error: |
1587 | - Py_XDECREF(d); |
1588 | - return NULL; |
1589 | -} |
1590 | - |
1591 | -static char _mysql_ResultObject_field_flags__doc__[] = |
1592 | -"Returns a tuple of field flags, one for each column in the result.\n\ |
1593 | -" ; |
1594 | - |
1595 | -static PyObject * |
1596 | -_mysql_ResultObject_field_flags( |
1597 | - _mysql_ResultObject *self, |
1598 | - PyObject *args) |
1599 | -{ |
1600 | - PyObject *d; |
1601 | - MYSQL_FIELD *fields; |
1602 | - unsigned int i, n; |
1603 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1604 | - check_result_connection(self); |
1605 | - n = mysql_num_fields(self->result); |
1606 | - fields = mysql_fetch_fields(self->result); |
1607 | - if (!(d = PyTuple_New(n))) return NULL; |
1608 | - for (i=0; i<n; i++) { |
1609 | - PyObject *f; |
1610 | - if (!(f = PyInt_FromLong((long)fields[i].flags))) goto error; |
1611 | - PyTuple_SET_ITEM(d, i, f); |
1612 | - } |
1613 | - return d; |
1614 | - error: |
1615 | - Py_XDECREF(d); |
1616 | - return NULL; |
1617 | -} |
1618 | - |
1619 | -static PyObject * |
1620 | -_mysql_field_to_python( |
1621 | - PyObject *converter, |
1622 | - char *rowitem, |
1623 | - unsigned long length) |
1624 | -{ |
1625 | - PyObject *v; |
1626 | - if (rowitem) { |
1627 | - if (converter != Py_None) |
1628 | - v = PyObject_CallFunction(converter, |
1629 | - "s#", |
1630 | - rowitem, |
1631 | - (int)length); |
1632 | - else |
1633 | - v = PyString_FromStringAndSize(rowitem, |
1634 | - (int)length); |
1635 | - if (!v) |
1636 | - return NULL; |
1637 | - } else { |
1638 | - Py_INCREF(Py_None); |
1639 | - v = Py_None; |
1640 | - } |
1641 | - return v; |
1642 | -} |
1643 | - |
1644 | -static PyObject * |
1645 | -_mysql_row_to_tuple( |
1646 | - _mysql_ResultObject *self, |
1647 | - MYSQL_ROW row) |
1648 | -{ |
1649 | - unsigned int n, i; |
1650 | - unsigned long *length; |
1651 | - PyObject *r, *c; |
1652 | - |
1653 | - n = mysql_num_fields(self->result); |
1654 | - if (!(r = PyTuple_New(n))) return NULL; |
1655 | - length = mysql_fetch_lengths(self->result); |
1656 | - for (i=0; i<n; i++) { |
1657 | - PyObject *v; |
1658 | - c = PyTuple_GET_ITEM(self->converter, i); |
1659 | - v = _mysql_field_to_python(c, row[i], length[i]); |
1660 | - if (!v) goto error; |
1661 | - PyTuple_SET_ITEM(r, i, v); |
1662 | - } |
1663 | - return r; |
1664 | - error: |
1665 | - Py_XDECREF(r); |
1666 | - return NULL; |
1667 | -} |
1668 | - |
1669 | -static PyObject * |
1670 | -_mysql_row_to_dict( |
1671 | - _mysql_ResultObject *self, |
1672 | - MYSQL_ROW row) |
1673 | -{ |
1674 | - unsigned int n, i; |
1675 | - unsigned long *length; |
1676 | - PyObject *r, *c; |
1677 | - MYSQL_FIELD *fields; |
1678 | - |
1679 | - n = mysql_num_fields(self->result); |
1680 | - if (!(r = PyDict_New())) return NULL; |
1681 | - length = mysql_fetch_lengths(self->result); |
1682 | - fields = mysql_fetch_fields(self->result); |
1683 | - for (i=0; i<n; i++) { |
1684 | - PyObject *v; |
1685 | - c = PyTuple_GET_ITEM(self->converter, i); |
1686 | - v = _mysql_field_to_python(c, row[i], length[i]); |
1687 | - if (!v) goto error; |
1688 | - if (!PyMapping_HasKeyString(r, fields[i].name)) { |
1689 | - PyMapping_SetItemString(r, fields[i].name, v); |
1690 | - } else { |
1691 | - int len; |
1692 | - char buf[256]; |
1693 | - strncpy(buf, fields[i].table, 256); |
1694 | - len = strlen(buf); |
1695 | - strncat(buf, ".", 256-len); |
1696 | - len = strlen(buf); |
1697 | - strncat(buf, fields[i].name, 256-len); |
1698 | - PyMapping_SetItemString(r, buf, v); |
1699 | - } |
1700 | - Py_DECREF(v); |
1701 | - } |
1702 | - return r; |
1703 | - error: |
1704 | - Py_XDECREF(r); |
1705 | - return NULL; |
1706 | -} |
1707 | - |
1708 | -static PyObject * |
1709 | -_mysql_row_to_dict_old( |
1710 | - _mysql_ResultObject *self, |
1711 | - MYSQL_ROW row) |
1712 | -{ |
1713 | - unsigned int n, i; |
1714 | - unsigned long *length; |
1715 | - PyObject *r, *c; |
1716 | - MYSQL_FIELD *fields; |
1717 | - |
1718 | - n = mysql_num_fields(self->result); |
1719 | - if (!(r = PyDict_New())) return NULL; |
1720 | - length = mysql_fetch_lengths(self->result); |
1721 | - fields = mysql_fetch_fields(self->result); |
1722 | - for (i=0; i<n; i++) { |
1723 | - PyObject *v; |
1724 | - c = PyTuple_GET_ITEM(self->converter, i); |
1725 | - v = _mysql_field_to_python(c, row[i], length[i]); |
1726 | - if (!v) goto error; |
1727 | - { |
1728 | - int len=0; |
1729 | - char buf[256]=""; |
1730 | - if (strlen(fields[i].table)) { |
1731 | - strncpy(buf, fields[i].table, 256); |
1732 | - len = strlen(buf); |
1733 | - strncat(buf, ".", 256-len); |
1734 | - len = strlen(buf); |
1735 | - } |
1736 | - strncat(buf, fields[i].name, 256-len); |
1737 | - PyMapping_SetItemString(r, buf, v); |
1738 | - } |
1739 | - Py_DECREF(v); |
1740 | - } |
1741 | - return r; |
1742 | - error: |
1743 | - Py_XDECREF(r); |
1744 | - return NULL; |
1745 | -} |
1746 | - |
1747 | -typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW); |
1748 | - |
1749 | -int |
1750 | -_mysql__fetch_row( |
1751 | - _mysql_ResultObject *self, |
1752 | - PyObject **r, |
1753 | - int skiprows, |
1754 | - int maxrows, |
1755 | - _PYFUNC *convert_row) |
1756 | -{ |
1757 | - unsigned int i; |
1758 | - MYSQL_ROW row; |
1759 | - |
1760 | - for (i = skiprows; i<(skiprows+maxrows); i++) { |
1761 | - PyObject *v; |
1762 | - if (!self->use) |
1763 | - row = mysql_fetch_row(self->result); |
1764 | - else { |
1765 | - Py_BEGIN_ALLOW_THREADS; |
1766 | - row = mysql_fetch_row(self->result); |
1767 | - Py_END_ALLOW_THREADS; |
1768 | - } |
1769 | - if (!row && mysql_errno(&(((_mysql_ConnectionObject *)(self->conn))->connection))) { |
1770 | - _mysql_Exception((_mysql_ConnectionObject *)self->conn); |
1771 | - goto error; |
1772 | - } |
1773 | - if (!row) { |
1774 | - if (MyTuple_Resize(r, i, 0) == -1) goto error; |
1775 | - break; |
1776 | - } |
1777 | - v = convert_row(self, row); |
1778 | - if (!v) goto error; |
1779 | - PyTuple_SET_ITEM(*r, i, v); |
1780 | - } |
1781 | - return i-skiprows; |
1782 | - error: |
1783 | - return -1; |
1784 | -} |
1785 | - |
1786 | -static char _mysql_ResultObject_fetch_row__doc__[] = |
1787 | -"fetch_row([maxrows, how]) -- Fetches up to maxrows as a tuple.\n\ |
1788 | -The rows are formatted according to how:\n\ |
1789 | -\n\ |
1790 | - 0 -- tuples (default)\n\ |
1791 | - 1 -- dictionaries, key=column or table.column if duplicated\n\ |
1792 | - 2 -- dictionaries, key=table.column\n\ |
1793 | -"; |
1794 | - |
1795 | -static PyObject * |
1796 | -_mysql_ResultObject_fetch_row( |
1797 | - _mysql_ResultObject *self, |
1798 | - PyObject *args, |
1799 | - PyObject *kwargs) |
1800 | -{ |
1801 | - typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW); |
1802 | - static char *kwlist[] = { "maxrows", "how", NULL }; |
1803 | - static _PYFUNC *row_converters[] = |
1804 | - { |
1805 | - _mysql_row_to_tuple, |
1806 | - _mysql_row_to_dict, |
1807 | - _mysql_row_to_dict_old |
1808 | - }; |
1809 | - _PYFUNC *convert_row; |
1810 | - unsigned int maxrows=1, how=0, skiprows=0, rowsadded; |
1811 | - PyObject *r=NULL; |
1812 | - |
1813 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii:fetch_row", kwlist, |
1814 | - &maxrows, &how)) |
1815 | - return NULL; |
1816 | - check_result_connection(self); |
1817 | - if (how < 0 || how >= sizeof(row_converters)) { |
1818 | - PyErr_SetString(PyExc_ValueError, "how out of range"); |
1819 | - return NULL; |
1820 | - } |
1821 | - convert_row = row_converters[how]; |
1822 | - if (maxrows) { |
1823 | - if (!(r = PyTuple_New(maxrows))) goto error; |
1824 | - rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows, |
1825 | - convert_row); |
1826 | - if (rowsadded == -1) goto error; |
1827 | - } else { |
1828 | - if (self->use) { |
1829 | - maxrows = 1000; |
1830 | - if (!(r = PyTuple_New(maxrows))) goto error; |
1831 | - while (1) { |
1832 | - rowsadded = _mysql__fetch_row(self, &r, skiprows, |
1833 | - maxrows, convert_row); |
1834 | - if (rowsadded == -1) goto error; |
1835 | - skiprows += rowsadded; |
1836 | - if (rowsadded < maxrows) break; |
1837 | - if (MyTuple_Resize(&r, skiprows+maxrows, 0) == -1) |
1838 | - goto error; |
1839 | - } |
1840 | - } else { |
1841 | - /* XXX if overflow, maxrows<0? */ |
1842 | - maxrows = (int) mysql_num_rows(self->result); |
1843 | - if (!(r = PyTuple_New(maxrows))) goto error; |
1844 | - rowsadded = _mysql__fetch_row(self, &r, 0, |
1845 | - maxrows, convert_row); |
1846 | - if (rowsadded == -1) goto error; |
1847 | - } |
1848 | - } |
1849 | - return r; |
1850 | - error: |
1851 | - Py_XDECREF(r); |
1852 | - return NULL; |
1853 | -} |
1854 | - |
1855 | -#if MYSQL_VERSION_ID >= 32303 |
1856 | - |
1857 | -static char _mysql_ConnectionObject_change_user__doc__[] = |
1858 | -"Changes the user and causes the database specified by db to\n\ |
1859 | -become the default (current) database on the connection\n\ |
1860 | -specified by mysql. In subsequent queries, this database is\n\ |
1861 | -the default for table references that do not include an\n\ |
1862 | -explicit database specifier.\n\ |
1863 | -\n\ |
1864 | -This function was introduced in MySQL Version 3.23.3.\n\ |
1865 | -\n\ |
1866 | -Fails unless the connected user can be authenticated or if he\n\ |
1867 | -doesn't have permission to use the database. In this case the\n\ |
1868 | -user and database are not changed.\n\ |
1869 | -\n\ |
1870 | -The db parameter may be set to None if you don't want to have\n\ |
1871 | -a default database.\n\ |
1872 | -"; |
1873 | - |
1874 | -static PyObject * |
1875 | -_mysql_ConnectionObject_change_user( |
1876 | - _mysql_ConnectionObject *self, |
1877 | - PyObject *args, |
1878 | - PyObject *kwargs) |
1879 | -{ |
1880 | - char *user, *pwd=NULL, *db=NULL; |
1881 | - int r; |
1882 | - static char *kwlist[] = { "user", "passwd", "db", NULL } ; |
1883 | - |
1884 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ss:change_user", |
1885 | - kwlist, &user, &pwd, &db)) |
1886 | - return NULL; |
1887 | - check_connection(self); |
1888 | - Py_BEGIN_ALLOW_THREADS |
1889 | - r = mysql_change_user(&(self->connection), user, pwd, db); |
1890 | - Py_END_ALLOW_THREADS |
1891 | - if (r) return _mysql_Exception(self); |
1892 | - Py_INCREF(Py_None); |
1893 | - return Py_None; |
1894 | -} |
1895 | -#endif |
1896 | - |
1897 | -static char _mysql_ConnectionObject_character_set_name__doc__[] = |
1898 | -"Returns the default character set for the current connection.\n\ |
1899 | -Non-standard.\n\ |
1900 | -"; |
1901 | - |
1902 | -static PyObject * |
1903 | -_mysql_ConnectionObject_character_set_name( |
1904 | - _mysql_ConnectionObject *self, |
1905 | - PyObject *args) |
1906 | -{ |
1907 | - const char *s; |
1908 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1909 | - check_connection(self); |
1910 | -#if MYSQL_VERSION_ID >= 32321 |
1911 | - s = mysql_character_set_name(&(self->connection)); |
1912 | -#else |
1913 | - s = "latin1"; |
1914 | -#endif |
1915 | - return PyString_FromString(s); |
1916 | -} |
1917 | - |
1918 | -#if MYSQL_VERSION_ID >= 50007 |
1919 | -static char _mysql_ConnectionObject_set_character_set__doc__[] = |
1920 | -"Sets the default character set for the current connection.\n\ |
1921 | -Non-standard.\n\ |
1922 | -"; |
1923 | - |
1924 | -static PyObject * |
1925 | -_mysql_ConnectionObject_set_character_set( |
1926 | - _mysql_ConnectionObject *self, |
1927 | - PyObject *args) |
1928 | -{ |
1929 | - const char *s; |
1930 | - int err; |
1931 | - if (!PyArg_ParseTuple(args, "s", &s)) return NULL; |
1932 | - check_connection(self); |
1933 | - Py_BEGIN_ALLOW_THREADS |
1934 | - err = mysql_set_character_set(&(self->connection), s); |
1935 | - Py_END_ALLOW_THREADS |
1936 | - if (err) return _mysql_Exception(self); |
1937 | - Py_INCREF(Py_None); |
1938 | - return Py_None; |
1939 | -} |
1940 | -#endif |
1941 | - |
1942 | -#if MYSQL_VERSION_ID >= 50010 |
1943 | -static char _mysql_ConnectionObject_get_character_set_info__doc__[] = |
1944 | -"Returns a dict with information about the current character set:\n\ |
1945 | -\n\ |
1946 | -collation\n\ |
1947 | - collation name\n\ |
1948 | -name\n\ |
1949 | - character set name\n\ |
1950 | -comment\n\ |
1951 | - comment or descriptive name\n\ |
1952 | -dir\n\ |
1953 | - character set directory\n\ |
1954 | -mbminlen\n\ |
1955 | - min. length for multibyte string\n\ |
1956 | -mbmaxlen\n\ |
1957 | - max. length for multibyte string\n\ |
1958 | -\n\ |
1959 | -Not all keys may be present, particularly dir.\n\ |
1960 | -\n\ |
1961 | -Non-standard.\n\ |
1962 | -"; |
1963 | - |
1964 | -static PyObject * |
1965 | -_mysql_ConnectionObject_get_character_set_info( |
1966 | - _mysql_ConnectionObject *self, |
1967 | - PyObject *args) |
1968 | -{ |
1969 | - PyObject *result; |
1970 | - MY_CHARSET_INFO cs; |
1971 | - |
1972 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1973 | - check_connection(self); |
1974 | - mysql_get_character_set_info(&(self->connection), &cs); |
1975 | - if (!(result = PyDict_New())) return NULL; |
1976 | - if (cs.csname) |
1977 | - PyDict_SetItemString(result, "name", PyString_FromString(cs.csname)); |
1978 | - if (cs.name) |
1979 | - PyDict_SetItemString(result, "collation", PyString_FromString(cs.name)); |
1980 | - if (cs.comment) |
1981 | - PyDict_SetItemString(result, "comment", PyString_FromString(cs.comment)); |
1982 | - if (cs.dir) |
1983 | - PyDict_SetItemString(result, "dir", PyString_FromString(cs.dir)); |
1984 | - PyDict_SetItemString(result, "mbminlen", PyInt_FromLong(cs.mbminlen)); |
1985 | - PyDict_SetItemString(result, "mbmaxlen", PyInt_FromLong(cs.mbmaxlen)); |
1986 | - return result; |
1987 | -} |
1988 | -#endif |
1989 | - |
1990 | -static char _mysql_get_client_info__doc__[] = |
1991 | -"get_client_info() -- Returns a string that represents\n\ |
1992 | -the client library version."; |
1993 | -static PyObject * |
1994 | -_mysql_get_client_info( |
1995 | - PyObject *self, |
1996 | - PyObject *args) |
1997 | -{ |
1998 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
1999 | - check_server_init(NULL); |
2000 | - return PyString_FromString(mysql_get_client_info()); |
2001 | -} |
2002 | - |
2003 | -static char _mysql_ConnectionObject_get_host_info__doc__[] = |
2004 | -"Returns a string that represents the MySQL client library\n\ |
2005 | -version. Non-standard.\n\ |
2006 | -"; |
2007 | - |
2008 | -static PyObject * |
2009 | -_mysql_ConnectionObject_get_host_info( |
2010 | - _mysql_ConnectionObject *self, |
2011 | - PyObject *args) |
2012 | -{ |
2013 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2014 | - check_connection(self); |
2015 | - return PyString_FromString(mysql_get_host_info(&(self->connection))); |
2016 | -} |
2017 | - |
2018 | -static char _mysql_ConnectionObject_get_proto_info__doc__[] = |
2019 | -"Returns an unsigned integer representing the protocol version\n\ |
2020 | -used by the current connection. Non-standard.\n\ |
2021 | -"; |
2022 | - |
2023 | -static PyObject * |
2024 | -_mysql_ConnectionObject_get_proto_info( |
2025 | - _mysql_ConnectionObject *self, |
2026 | - PyObject *args) |
2027 | -{ |
2028 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2029 | - check_connection(self); |
2030 | - return PyInt_FromLong((long)mysql_get_proto_info(&(self->connection))); |
2031 | -} |
2032 | - |
2033 | -static char _mysql_ConnectionObject_get_server_info__doc__[] = |
2034 | -"Returns a string that represents the server version number.\n\ |
2035 | -Non-standard.\n\ |
2036 | -"; |
2037 | - |
2038 | -static PyObject * |
2039 | -_mysql_ConnectionObject_get_server_info( |
2040 | - _mysql_ConnectionObject *self, |
2041 | - PyObject *args) |
2042 | -{ |
2043 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2044 | - check_connection(self); |
2045 | - return PyString_FromString(mysql_get_server_info(&(self->connection))); |
2046 | -} |
2047 | - |
2048 | -static char _mysql_ConnectionObject_info__doc__[] = |
2049 | -"Retrieves a string providing information about the most\n\ |
2050 | -recently executed query. Non-standard. Use messages or\n\ |
2051 | -Cursor.messages.\n\ |
2052 | -"; |
2053 | - |
2054 | -static PyObject * |
2055 | -_mysql_ConnectionObject_info( |
2056 | - _mysql_ConnectionObject *self, |
2057 | - PyObject *args) |
2058 | -{ |
2059 | - const char *s; |
2060 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2061 | - check_connection(self); |
2062 | - s = mysql_info(&(self->connection)); |
2063 | - if (s) return PyString_FromString(s); |
2064 | - Py_INCREF(Py_None); |
2065 | - return Py_None; |
2066 | -} |
2067 | - |
2068 | -static char _mysql_ConnectionObject_insert_id__doc__[] = |
2069 | -"Returns the ID generated for an AUTO_INCREMENT column by the previous\n\ |
2070 | -query. Use this function after you have performed an INSERT query into a\n\ |
2071 | -table that contains an AUTO_INCREMENT field.\n\ |
2072 | -\n\ |
2073 | -Note that this returns 0 if the previous query does not\n\ |
2074 | -generate an AUTO_INCREMENT value. If you need to save the value for\n\ |
2075 | -later, be sure to call this immediately after the query\n\ |
2076 | -that generates the value.\n\ |
2077 | -\n\ |
2078 | -The ID is updated after INSERT and UPDATE statements that generate\n\ |
2079 | -an AUTO_INCREMENT value or that set a column value to\n\ |
2080 | -LAST_INSERT_ID(expr). See section 6.3.5.2 Miscellaneous Functions\n\ |
2081 | -in the MySQL documentation.\n\ |
2082 | -\n\ |
2083 | -Also note that the value of the SQL LAST_INSERT_ID() function always\n\ |
2084 | -contains the most recently generated AUTO_INCREMENT value, and is not\n\ |
2085 | -reset between queries because the value of that function is maintained\n\ |
2086 | -in the server.\n\ |
2087 | -" ; |
2088 | - |
2089 | -static PyObject * |
2090 | -_mysql_ConnectionObject_insert_id( |
2091 | - _mysql_ConnectionObject *self, |
2092 | - PyObject *args) |
2093 | -{ |
2094 | - my_ulonglong r; |
2095 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2096 | - check_connection(self); |
2097 | - Py_BEGIN_ALLOW_THREADS |
2098 | - r = mysql_insert_id(&(self->connection)); |
2099 | - Py_END_ALLOW_THREADS |
2100 | - return PyLong_FromUnsignedLongLong(r); |
2101 | -} |
2102 | - |
2103 | -static char _mysql_ConnectionObject_kill__doc__[] = |
2104 | -"Asks the server to kill the thread specified by pid.\n\ |
2105 | -Non-standard."; |
2106 | - |
2107 | -static PyObject * |
2108 | -_mysql_ConnectionObject_kill( |
2109 | - _mysql_ConnectionObject *self, |
2110 | - PyObject *args) |
2111 | -{ |
2112 | - unsigned long pid; |
2113 | - int r; |
2114 | - if (!PyArg_ParseTuple(args, "k:kill", &pid)) return NULL; |
2115 | - check_connection(self); |
2116 | - Py_BEGIN_ALLOW_THREADS |
2117 | - r = mysql_kill(&(self->connection), pid); |
2118 | - Py_END_ALLOW_THREADS |
2119 | - if (r) return _mysql_Exception(self); |
2120 | - Py_INCREF(Py_None); |
2121 | - return Py_None; |
2122 | -} |
2123 | - |
2124 | -static char _mysql_ConnectionObject_field_count__doc__[] = |
2125 | -"Returns the number of columns for the most recent query on the\n\ |
2126 | -connection. Non-standard. Will probably give you bogus results\n\ |
2127 | -on most cursor classes. Use Cursor.rowcount.\n\ |
2128 | -"; |
2129 | - |
2130 | -static PyObject * |
2131 | -_mysql_ConnectionObject_field_count( |
2132 | - _mysql_ConnectionObject *self, |
2133 | - PyObject *args) |
2134 | -{ |
2135 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2136 | - check_connection(self); |
2137 | -#if MYSQL_VERSION_ID < 32224 |
2138 | - return PyInt_FromLong((long)mysql_num_fields(&(self->connection))); |
2139 | -#else |
2140 | - return PyInt_FromLong((long)mysql_field_count(&(self->connection))); |
2141 | -#endif |
2142 | -} |
2143 | - |
2144 | -static char _mysql_ResultObject_num_fields__doc__[] = |
2145 | -"Returns the number of fields (column) in the result." ; |
2146 | - |
2147 | -static PyObject * |
2148 | -_mysql_ResultObject_num_fields( |
2149 | - _mysql_ResultObject *self, |
2150 | - PyObject *args) |
2151 | -{ |
2152 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2153 | - check_result_connection(self); |
2154 | - return PyInt_FromLong((long)mysql_num_fields(self->result)); |
2155 | -} |
2156 | - |
2157 | -static char _mysql_ResultObject_num_rows__doc__[] = |
2158 | -"Returns the number of rows in the result set. Note that if\n\ |
2159 | -use=1, this will not return a valid value until the entire result\n\ |
2160 | -set has been read.\n\ |
2161 | -"; |
2162 | - |
2163 | -static PyObject * |
2164 | -_mysql_ResultObject_num_rows( |
2165 | - _mysql_ResultObject *self, |
2166 | - PyObject *args) |
2167 | -{ |
2168 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2169 | - check_result_connection(self); |
2170 | - return PyLong_FromUnsignedLongLong(mysql_num_rows(self->result)); |
2171 | -} |
2172 | - |
2173 | -static char _mysql_ConnectionObject_ping__doc__[] = |
2174 | -"Checks whether or not the connection to the server is\n\ |
2175 | -working. If it has gone down, an automatic reconnection is\n\ |
2176 | -attempted.\n\ |
2177 | -\n\ |
2178 | -This function can be used by clients that remain idle for a\n\ |
2179 | -long while, to check whether or not the server has closed the\n\ |
2180 | -connection and reconnect if necessary.\n\ |
2181 | -\n\ |
2182 | -New in 1.2.2: Accepts an optional reconnect parameter. If True,\n\ |
2183 | -then the client will attempt reconnection. Note that this setting\n\ |
2184 | -is persistent. By default, this is on in MySQL<5.0.3, and off\n\ |
2185 | -thereafter.\n\ |
2186 | -\n\ |
2187 | -Non-standard. You should assume that ping() performs an\n\ |
2188 | -implicit rollback; use only when starting a new transaction.\n\ |
2189 | -You have been warned.\n\ |
2190 | -"; |
2191 | - |
2192 | -static PyObject * |
2193 | -_mysql_ConnectionObject_ping( |
2194 | - _mysql_ConnectionObject *self, |
2195 | - PyObject *args) |
2196 | -{ |
2197 | - int r, reconnect = -1; |
2198 | - if (!PyArg_ParseTuple(args, "|I", &reconnect)) return NULL; |
2199 | - check_connection(self); |
2200 | - if ( reconnect != -1 ) self->connection.reconnect = reconnect; |
2201 | - Py_BEGIN_ALLOW_THREADS |
2202 | - r = mysql_ping(&(self->connection)); |
2203 | - Py_END_ALLOW_THREADS |
2204 | - if (r) return _mysql_Exception(self); |
2205 | - Py_INCREF(Py_None); |
2206 | - return Py_None; |
2207 | -} |
2208 | - |
2209 | -static char _mysql_ConnectionObject_query__doc__[] = |
2210 | -"Execute a query. store_result() or use_result() will get the\n\ |
2211 | -result set, if any. Non-standard. Use cursor() to create a cursor,\n\ |
2212 | -then cursor.execute().\n\ |
2213 | -" ; |
2214 | - |
2215 | -static PyObject * |
2216 | -_mysql_ConnectionObject_query( |
2217 | - _mysql_ConnectionObject *self, |
2218 | - PyObject *args) |
2219 | -{ |
2220 | - char *query; |
2221 | - int len, r; |
2222 | - if (!PyArg_ParseTuple(args, "s#:query", &query, &len)) return NULL; |
2223 | - check_connection(self); |
2224 | - Py_BEGIN_ALLOW_THREADS |
2225 | - r = mysql_real_query(&(self->connection), query, len); |
2226 | - Py_END_ALLOW_THREADS |
2227 | - if (r) return _mysql_Exception(self); |
2228 | - Py_INCREF(Py_None); |
2229 | - return Py_None; |
2230 | -} |
2231 | - |
2232 | - |
2233 | -static char _mysql_ConnectionObject_select_db__doc__[] = |
2234 | -"Causes the database specified by db to become the default\n\ |
2235 | -(current) database on the connection specified by mysql. In subsequent\n\ |
2236 | -queries, this database is the default for table references that do not\n\ |
2237 | -include an explicit database specifier.\n\ |
2238 | -\n\ |
2239 | -Fails unless the connected user can be authenticated as having\n\ |
2240 | -permission to use the database.\n\ |
2241 | -\n\ |
2242 | -Non-standard.\n\ |
2243 | -"; |
2244 | - |
2245 | -static PyObject * |
2246 | -_mysql_ConnectionObject_select_db( |
2247 | - _mysql_ConnectionObject *self, |
2248 | - PyObject *args) |
2249 | -{ |
2250 | - char *db; |
2251 | - int r; |
2252 | - if (!PyArg_ParseTuple(args, "s:select_db", &db)) return NULL; |
2253 | - check_connection(self); |
2254 | - Py_BEGIN_ALLOW_THREADS |
2255 | - r = mysql_select_db(&(self->connection), db); |
2256 | - Py_END_ALLOW_THREADS |
2257 | - if (r) return _mysql_Exception(self); |
2258 | - Py_INCREF(Py_None); |
2259 | - return Py_None; |
2260 | -} |
2261 | - |
2262 | -static char _mysql_ConnectionObject_shutdown__doc__[] = |
2263 | -"Asks the database server to shut down. The connected user must\n\ |
2264 | -have shutdown privileges. Non-standard.\n\ |
2265 | -"; |
2266 | - |
2267 | -static PyObject * |
2268 | -_mysql_ConnectionObject_shutdown( |
2269 | - _mysql_ConnectionObject *self, |
2270 | - PyObject *args) |
2271 | -{ |
2272 | - int r; |
2273 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2274 | - check_connection(self); |
2275 | - Py_BEGIN_ALLOW_THREADS |
2276 | - r = mysql_shutdown(&(self->connection) |
2277 | -#if MYSQL_VERSION_ID >= 40103 |
2278 | - , SHUTDOWN_DEFAULT |
2279 | -#endif |
2280 | - ); |
2281 | - Py_END_ALLOW_THREADS |
2282 | - if (r) return _mysql_Exception(self); |
2283 | - Py_INCREF(Py_None); |
2284 | - return Py_None; |
2285 | -} |
2286 | - |
2287 | -static char _mysql_ConnectionObject_stat__doc__[] = |
2288 | -"Returns a character string containing information similar to\n\ |
2289 | -that provided by the mysqladmin status command. This includes\n\ |
2290 | -uptime in seconds and the number of running threads,\n\ |
2291 | -questions, reloads, and open tables. Non-standard.\n\ |
2292 | -"; |
2293 | - |
2294 | -static PyObject * |
2295 | -_mysql_ConnectionObject_stat( |
2296 | - _mysql_ConnectionObject *self, |
2297 | - PyObject *args) |
2298 | -{ |
2299 | - const char *s; |
2300 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2301 | - check_connection(self); |
2302 | - Py_BEGIN_ALLOW_THREADS |
2303 | - s = mysql_stat(&(self->connection)); |
2304 | - Py_END_ALLOW_THREADS |
2305 | - if (!s) return _mysql_Exception(self); |
2306 | - return PyString_FromString(s); |
2307 | -} |
2308 | - |
2309 | -static char _mysql_ConnectionObject_store_result__doc__[] = |
2310 | -"Returns a result object acquired by mysql_store_result\n\ |
2311 | -(results stored in the client). If no results are available,\n\ |
2312 | -None is returned. Non-standard.\n\ |
2313 | -"; |
2314 | - |
2315 | -static PyObject * |
2316 | -_mysql_ConnectionObject_store_result( |
2317 | - _mysql_ConnectionObject *self, |
2318 | - PyObject *args) |
2319 | -{ |
2320 | - PyObject *arglist=NULL, *kwarglist=NULL, *result=NULL; |
2321 | - _mysql_ResultObject *r=NULL; |
2322 | - |
2323 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2324 | - check_connection(self); |
2325 | - arglist = Py_BuildValue("(OiO)", self, 0, self->converter); |
2326 | - if (!arglist) goto error; |
2327 | - kwarglist = PyDict_New(); |
2328 | - if (!kwarglist) goto error; |
2329 | - r = MyAlloc(_mysql_ResultObject, _mysql_ResultObject_Type); |
2330 | - if (!r) goto error; |
2331 | - if (_mysql_ResultObject_Initialize(r, arglist, kwarglist)) |
2332 | - goto error; |
2333 | - result = (PyObject *) r; |
2334 | - if (!(r->result)) { |
2335 | - Py_DECREF(result); |
2336 | - Py_INCREF(Py_None); |
2337 | - result = Py_None; |
2338 | - } |
2339 | - error: |
2340 | - Py_XDECREF(arglist); |
2341 | - Py_XDECREF(kwarglist); |
2342 | - return result; |
2343 | -} |
2344 | - |
2345 | -static char _mysql_ConnectionObject_thread_id__doc__[] = |
2346 | -"Returns the thread ID of the current connection. This value\n\ |
2347 | -can be used as an argument to kill() to kill the thread.\n\ |
2348 | -\n\ |
2349 | -If the connection is lost and you reconnect with ping(), the\n\ |
2350 | -thread ID will change. This means you should not get the\n\ |
2351 | -thread ID and store it for later. You should get it when you\n\ |
2352 | -need it.\n\ |
2353 | -\n\ |
2354 | -Non-standard."; |
2355 | - |
2356 | -static PyObject * |
2357 | -_mysql_ConnectionObject_thread_id( |
2358 | - _mysql_ConnectionObject *self, |
2359 | - PyObject *args) |
2360 | -{ |
2361 | - unsigned long pid; |
2362 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2363 | - check_connection(self); |
2364 | - Py_BEGIN_ALLOW_THREADS |
2365 | - pid = mysql_thread_id(&(self->connection)); |
2366 | - Py_END_ALLOW_THREADS |
2367 | - return PyInt_FromLong((long)pid); |
2368 | -} |
2369 | - |
2370 | -static char _mysql_ConnectionObject_use_result__doc__[] = |
2371 | -"Returns a result object acquired by mysql_use_result\n\ |
2372 | -(results stored in the server). If no results are available,\n\ |
2373 | -None is returned. Non-standard.\n\ |
2374 | -"; |
2375 | - |
2376 | -static PyObject * |
2377 | -_mysql_ConnectionObject_use_result( |
2378 | - _mysql_ConnectionObject *self, |
2379 | - PyObject *args) |
2380 | -{ |
2381 | - PyObject *arglist=NULL, *kwarglist=NULL, *result=NULL; |
2382 | - _mysql_ResultObject *r=NULL; |
2383 | - |
2384 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2385 | - check_connection(self); |
2386 | - arglist = Py_BuildValue("(OiO)", self, 1, self->converter); |
2387 | - if (!arglist) return NULL; |
2388 | - kwarglist = PyDict_New(); |
2389 | - if (!kwarglist) goto error; |
2390 | - r = MyAlloc(_mysql_ResultObject, _mysql_ResultObject_Type); |
2391 | - if (!r) goto error; |
2392 | - result = (PyObject *) r; |
2393 | - if (_mysql_ResultObject_Initialize(r, arglist, kwarglist)) |
2394 | - goto error; |
2395 | - if (!(r->result)) { |
2396 | - Py_DECREF(result); |
2397 | - Py_INCREF(Py_None); |
2398 | - result = Py_None; |
2399 | - } |
2400 | - error: |
2401 | - Py_DECREF(arglist); |
2402 | - Py_XDECREF(kwarglist); |
2403 | - return result; |
2404 | -} |
2405 | - |
2406 | -static void |
2407 | -_mysql_ConnectionObject_dealloc( |
2408 | - _mysql_ConnectionObject *self) |
2409 | -{ |
2410 | - PyObject *o; |
2411 | - |
2412 | - PyObject_GC_UnTrack(self); |
2413 | - if (self->open) { |
2414 | - o = _mysql_ConnectionObject_close(self, NULL); |
2415 | - Py_XDECREF(o); |
2416 | - } |
2417 | - MyFree(self); |
2418 | -} |
2419 | - |
2420 | -static PyObject * |
2421 | -_mysql_ConnectionObject_repr( |
2422 | - _mysql_ConnectionObject *self) |
2423 | -{ |
2424 | - char buf[300]; |
2425 | - if (self->open) |
2426 | - sprintf(buf, "<_mysql.connection open to '%.256s' at %lx>", |
2427 | - self->connection.host, |
2428 | - (long)self); |
2429 | - else |
2430 | - sprintf(buf, "<_mysql.connection closed at %lx>", |
2431 | - (long)self); |
2432 | - return PyString_FromString(buf); |
2433 | -} |
2434 | - |
2435 | -static char _mysql_ResultObject_data_seek__doc__[] = |
2436 | -"data_seek(n) -- seek to row n of result set"; |
2437 | -static PyObject * |
2438 | -_mysql_ResultObject_data_seek( |
2439 | - _mysql_ResultObject *self, |
2440 | - PyObject *args) |
2441 | -{ |
2442 | - unsigned int row; |
2443 | - if (!PyArg_ParseTuple(args, "i:data_seek", &row)) return NULL; |
2444 | - check_result_connection(self); |
2445 | - mysql_data_seek(self->result, row); |
2446 | - Py_INCREF(Py_None); |
2447 | - return Py_None; |
2448 | -} |
2449 | - |
2450 | -static char _mysql_ResultObject_row_seek__doc__[] = |
2451 | -"row_seek(n) -- seek by offset n rows of result set"; |
2452 | -static PyObject * |
2453 | -_mysql_ResultObject_row_seek( |
2454 | - _mysql_ResultObject *self, |
2455 | - PyObject *args) |
2456 | -{ |
2457 | - int offset; |
2458 | - MYSQL_ROW_OFFSET r; |
2459 | - if (!PyArg_ParseTuple(args, "i:row_seek", &offset)) return NULL; |
2460 | - check_result_connection(self); |
2461 | - if (self->use) { |
2462 | - PyErr_SetString(_mysql_ProgrammingError, |
2463 | - "cannot be used with connection.use_result()"); |
2464 | - return NULL; |
2465 | - } |
2466 | - r = mysql_row_tell(self->result); |
2467 | - mysql_row_seek(self->result, r+offset); |
2468 | - Py_INCREF(Py_None); |
2469 | - return Py_None; |
2470 | -} |
2471 | - |
2472 | -static char _mysql_ResultObject_row_tell__doc__[] = |
2473 | -"row_tell() -- return the current row number of the result set."; |
2474 | -static PyObject * |
2475 | -_mysql_ResultObject_row_tell( |
2476 | - _mysql_ResultObject *self, |
2477 | - PyObject *args) |
2478 | -{ |
2479 | - MYSQL_ROW_OFFSET r; |
2480 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
2481 | - check_result_connection(self); |
2482 | - if (self->use) { |
2483 | - PyErr_SetString(_mysql_ProgrammingError, |
2484 | - "cannot be used with connection.use_result()"); |
2485 | - return NULL; |
2486 | - } |
2487 | - r = mysql_row_tell(self->result); |
2488 | - return PyInt_FromLong(r-self->result->data->data); |
2489 | -} |
2490 | - |
2491 | -static void |
2492 | -_mysql_ResultObject_dealloc( |
2493 | - _mysql_ResultObject *self) |
2494 | -{ |
2495 | - PyObject_GC_UnTrack((PyObject *)self); |
2496 | - mysql_free_result(self->result); |
2497 | - _mysql_ResultObject_clear(self); |
2498 | - MyFree(self); |
2499 | -} |
2500 | - |
2501 | -static PyObject * |
2502 | -_mysql_ResultObject_repr( |
2503 | - _mysql_ResultObject *self) |
2504 | -{ |
2505 | - char buf[300]; |
2506 | - sprintf(buf, "<_mysql.result object at %lx>", |
2507 | - (long)self); |
2508 | - return PyString_FromString(buf); |
2509 | -} |
2510 | - |
2511 | -static PyMethodDef _mysql_ConnectionObject_methods[] = { |
2512 | - { |
2513 | - "affected_rows", |
2514 | - (PyCFunction)_mysql_ConnectionObject_affected_rows, |
2515 | - METH_VARARGS, |
2516 | - _mysql_ConnectionObject_affected_rows__doc__ |
2517 | - }, |
2518 | - { |
2519 | - "autocommit", |
2520 | - (PyCFunction)_mysql_ConnectionObject_autocommit, |
2521 | - METH_VARARGS, |
2522 | - _mysql_ConnectionObject_autocommit__doc__ |
2523 | - }, |
2524 | - { |
2525 | - "commit", |
2526 | - (PyCFunction)_mysql_ConnectionObject_commit, |
2527 | - METH_VARARGS, |
2528 | - _mysql_ConnectionObject_commit__doc__ |
2529 | - }, |
2530 | - { |
2531 | - "rollback", |
2532 | - (PyCFunction)_mysql_ConnectionObject_rollback, |
2533 | - METH_VARARGS, |
2534 | - _mysql_ConnectionObject_rollback__doc__ |
2535 | - }, |
2536 | - { |
2537 | - "next_result", |
2538 | - (PyCFunction)_mysql_ConnectionObject_next_result, |
2539 | - METH_VARARGS, |
2540 | - _mysql_ConnectionObject_next_result__doc__ |
2541 | - }, |
2542 | -#if MYSQL_VERSION_ID >= 40100 |
2543 | - { |
2544 | - "set_server_option", |
2545 | - (PyCFunction)_mysql_ConnectionObject_set_server_option, |
2546 | - METH_VARARGS, |
2547 | - _mysql_ConnectionObject_set_server_option__doc__ |
2548 | - }, |
2549 | - { |
2550 | - "sqlstate", |
2551 | - (PyCFunction)_mysql_ConnectionObject_sqlstate, |
2552 | - METH_VARARGS, |
2553 | - _mysql_ConnectionObject_sqlstate__doc__ |
2554 | - }, |
2555 | - { |
2556 | - "warning_count", |
2557 | - (PyCFunction)_mysql_ConnectionObject_warning_count, |
2558 | - METH_VARARGS, |
2559 | - _mysql_ConnectionObject_warning_count__doc__ |
2560 | - }, |
2561 | -#endif |
2562 | -#if MYSQL_VERSION_ID >= 32303 |
2563 | - { |
2564 | - "change_user", |
2565 | - (PyCFunction)_mysql_ConnectionObject_change_user, |
2566 | - METH_VARARGS | METH_KEYWORDS, |
2567 | - _mysql_ConnectionObject_change_user__doc__ |
2568 | - }, |
2569 | -#endif |
2570 | - { |
2571 | - "character_set_name", |
2572 | - (PyCFunction)_mysql_ConnectionObject_character_set_name, |
2573 | - METH_VARARGS, |
2574 | - _mysql_ConnectionObject_character_set_name__doc__ |
2575 | - }, |
2576 | -#if MYSQL_VERSION_ID >= 50007 |
2577 | - { |
2578 | - "set_character_set", |
2579 | - (PyCFunction)_mysql_ConnectionObject_set_character_set, |
2580 | - METH_VARARGS, |
2581 | - _mysql_ConnectionObject_set_character_set__doc__ |
2582 | - }, |
2583 | -#endif |
2584 | -#if MYSQL_VERSION_ID >= 50010 |
2585 | - { |
2586 | - "get_character_set_info", |
2587 | - (PyCFunction)_mysql_ConnectionObject_get_character_set_info, |
2588 | - METH_VARARGS, |
2589 | - _mysql_ConnectionObject_get_character_set_info__doc__ |
2590 | - }, |
2591 | -#endif |
2592 | - { |
2593 | - "close", |
2594 | - (PyCFunction)_mysql_ConnectionObject_close, |
2595 | - METH_VARARGS, |
2596 | - _mysql_ConnectionObject_close__doc__ |
2597 | - }, |
2598 | - { |
2599 | - "dump_debug_info", |
2600 | - (PyCFunction)_mysql_ConnectionObject_dump_debug_info, |
2601 | - METH_VARARGS, |
2602 | - _mysql_ConnectionObject_dump_debug_info__doc__ |
2603 | - }, |
2604 | - { |
2605 | - "escape", |
2606 | - (PyCFunction)_mysql_escape, |
2607 | - METH_VARARGS, |
2608 | - _mysql_escape__doc__ |
2609 | - }, |
2610 | - { |
2611 | - "escape_string", |
2612 | - (PyCFunction)_mysql_escape_string, |
2613 | - METH_VARARGS, |
2614 | - _mysql_escape_string__doc__ |
2615 | - }, |
2616 | - { |
2617 | - "error", |
2618 | - (PyCFunction)_mysql_ConnectionObject_error, |
2619 | - METH_VARARGS, |
2620 | - _mysql_ConnectionObject_error__doc__ |
2621 | - }, |
2622 | - { |
2623 | - "errno", |
2624 | - (PyCFunction)_mysql_ConnectionObject_errno, |
2625 | - METH_VARARGS, |
2626 | - _mysql_ConnectionObject_errno__doc__ |
2627 | - }, |
2628 | - { |
2629 | - "field_count", |
2630 | - (PyCFunction)_mysql_ConnectionObject_field_count, |
2631 | - METH_VARARGS, |
2632 | - _mysql_ConnectionObject_field_count__doc__ |
2633 | - }, |
2634 | - { |
2635 | - "get_host_info", |
2636 | - (PyCFunction)_mysql_ConnectionObject_get_host_info, |
2637 | - METH_VARARGS, |
2638 | - _mysql_ConnectionObject_get_host_info__doc__ |
2639 | - }, |
2640 | - { |
2641 | - "get_proto_info", |
2642 | - (PyCFunction)_mysql_ConnectionObject_get_proto_info, |
2643 | - METH_VARARGS, |
2644 | - _mysql_ConnectionObject_get_proto_info__doc__ |
2645 | - }, |
2646 | - { |
2647 | - "get_server_info", |
2648 | - (PyCFunction)_mysql_ConnectionObject_get_server_info, |
2649 | - METH_VARARGS, |
2650 | - _mysql_ConnectionObject_get_server_info__doc__ |
2651 | - }, |
2652 | - { |
2653 | - "info", |
2654 | - (PyCFunction)_mysql_ConnectionObject_info, |
2655 | - METH_VARARGS, |
2656 | - _mysql_ConnectionObject_info__doc__ |
2657 | - }, |
2658 | - { |
2659 | - "insert_id", |
2660 | - (PyCFunction)_mysql_ConnectionObject_insert_id, |
2661 | - METH_VARARGS, |
2662 | - _mysql_ConnectionObject_insert_id__doc__ |
2663 | - }, |
2664 | - { |
2665 | - "kill", |
2666 | - (PyCFunction)_mysql_ConnectionObject_kill, |
2667 | - METH_VARARGS, |
2668 | - _mysql_ConnectionObject_kill__doc__ |
2669 | - }, |
2670 | - { |
2671 | - "ping", |
2672 | - (PyCFunction)_mysql_ConnectionObject_ping, |
2673 | - METH_VARARGS, |
2674 | - _mysql_ConnectionObject_ping__doc__ |
2675 | - }, |
2676 | - { |
2677 | - "query", |
2678 | - (PyCFunction)_mysql_ConnectionObject_query, |
2679 | - METH_VARARGS, |
2680 | - _mysql_ConnectionObject_query__doc__ |
2681 | - }, |
2682 | - { |
2683 | - "select_db", |
2684 | - (PyCFunction)_mysql_ConnectionObject_select_db, |
2685 | - METH_VARARGS, |
2686 | - _mysql_ConnectionObject_select_db__doc__ |
2687 | - }, |
2688 | - { |
2689 | - "shutdown", |
2690 | - (PyCFunction)_mysql_ConnectionObject_shutdown, |
2691 | - METH_VARARGS, |
2692 | - _mysql_ConnectionObject_shutdown__doc__ |
2693 | - }, |
2694 | - { |
2695 | - "stat", |
2696 | - (PyCFunction)_mysql_ConnectionObject_stat, |
2697 | - METH_VARARGS, |
2698 | - _mysql_ConnectionObject_stat__doc__ |
2699 | - }, |
2700 | - { |
2701 | - "store_result", |
2702 | - (PyCFunction)_mysql_ConnectionObject_store_result, |
2703 | - METH_VARARGS, |
2704 | - _mysql_ConnectionObject_store_result__doc__ |
2705 | - }, |
2706 | - { |
2707 | - "string_literal", |
2708 | - (PyCFunction)_mysql_string_literal, |
2709 | - METH_VARARGS, |
2710 | - _mysql_string_literal__doc__}, |
2711 | - { |
2712 | - "thread_id", |
2713 | - (PyCFunction)_mysql_ConnectionObject_thread_id, |
2714 | - METH_VARARGS, |
2715 | - _mysql_ConnectionObject_thread_id__doc__ |
2716 | - }, |
2717 | - { |
2718 | - "use_result", |
2719 | - (PyCFunction)_mysql_ConnectionObject_use_result, |
2720 | - METH_VARARGS, |
2721 | - _mysql_ConnectionObject_use_result__doc__ |
2722 | - }, |
2723 | - {NULL, NULL} /* sentinel */ |
2724 | -}; |
2725 | - |
2726 | -static MyMemberlist(_mysql_ConnectionObject_memberlist)[] = { |
2727 | - MyMember( |
2728 | - "open", |
2729 | - T_INT, |
2730 | - offsetof(_mysql_ConnectionObject,open), |
2731 | - RO, |
2732 | - "True if connection is open" |
2733 | - ), |
2734 | - MyMember( |
2735 | - "converter", |
2736 | - T_OBJECT, |
2737 | - offsetof(_mysql_ConnectionObject,converter), |
2738 | - 0, |
2739 | - "Type conversion mapping" |
2740 | - ), |
2741 | - MyMember( |
2742 | - "server_capabilities", |
2743 | - T_UINT, |
2744 | - offsetof(_mysql_ConnectionObject,connection.server_capabilities), |
2745 | - RO, |
2746 | - "Capabilites of server; consult MySQLdb.constants.CLIENT" |
2747 | - ), |
2748 | - MyMember( |
2749 | - "port", |
2750 | - T_UINT, |
2751 | - offsetof(_mysql_ConnectionObject,connection.port), |
2752 | - RO, |
2753 | - "TCP/IP port of the server connection" |
2754 | - ), |
2755 | - MyMember( |
2756 | - "client_flag", |
2757 | - T_UINT, |
2758 | - RO, |
2759 | - offsetof(_mysql_ConnectionObject,connection.client_flag), |
2760 | - "Client flags; refer to MySQLdb.constants.CLIENT" |
2761 | - ), |
2762 | - {NULL} /* Sentinel */ |
2763 | -}; |
2764 | - |
2765 | -static PyMethodDef _mysql_ResultObject_methods[] = { |
2766 | - { |
2767 | - "data_seek", |
2768 | - (PyCFunction)_mysql_ResultObject_data_seek, |
2769 | - METH_VARARGS, |
2770 | - _mysql_ResultObject_data_seek__doc__ |
2771 | - }, |
2772 | - { |
2773 | - "row_seek", |
2774 | - (PyCFunction)_mysql_ResultObject_row_seek, |
2775 | - METH_VARARGS, |
2776 | - _mysql_ResultObject_row_seek__doc__ |
2777 | - }, |
2778 | - { |
2779 | - "row_tell", |
2780 | - (PyCFunction)_mysql_ResultObject_row_tell, |
2781 | - METH_VARARGS, |
2782 | - _mysql_ResultObject_row_tell__doc__ |
2783 | - }, |
2784 | - { |
2785 | - "describe", |
2786 | - (PyCFunction)_mysql_ResultObject_describe, |
2787 | - METH_VARARGS, |
2788 | - _mysql_ResultObject_describe__doc__ |
2789 | - }, |
2790 | - { |
2791 | - "fetch_row", |
2792 | - (PyCFunction)_mysql_ResultObject_fetch_row, |
2793 | - METH_VARARGS | METH_KEYWORDS, |
2794 | - _mysql_ResultObject_fetch_row__doc__ |
2795 | - }, |
2796 | - { |
2797 | - "field_flags", |
2798 | - (PyCFunction)_mysql_ResultObject_field_flags, |
2799 | - METH_VARARGS, |
2800 | - _mysql_ResultObject_field_flags__doc__ |
2801 | - }, |
2802 | - { |
2803 | - "num_fields", |
2804 | - (PyCFunction)_mysql_ResultObject_num_fields, |
2805 | - METH_VARARGS, |
2806 | - _mysql_ResultObject_num_fields__doc__ |
2807 | - }, |
2808 | - { |
2809 | - "num_rows", |
2810 | - (PyCFunction)_mysql_ResultObject_num_rows, |
2811 | - METH_VARARGS, |
2812 | - _mysql_ResultObject_num_rows__doc__ |
2813 | - }, |
2814 | - {NULL, NULL} /* sentinel */ |
2815 | -}; |
2816 | - |
2817 | -static MyMemberlist(_mysql_ResultObject_memberlist)[] = { |
2818 | - MyMember( |
2819 | - "converter", |
2820 | - T_OBJECT, |
2821 | - offsetof(_mysql_ResultObject,converter), |
2822 | - RO, |
2823 | - "Type conversion mapping" |
2824 | - ), |
2825 | - {NULL} /* Sentinel */ |
2826 | -}; |
2827 | - |
2828 | -static PyObject * |
2829 | -_mysql_ConnectionObject_getattr( |
2830 | - _mysql_ConnectionObject *self, |
2831 | - char *name) |
2832 | -{ |
2833 | - PyObject *res; |
2834 | - |
2835 | - res = Py_FindMethod(_mysql_ConnectionObject_methods, (PyObject *)self, name); |
2836 | - if (res != NULL) |
2837 | - return res; |
2838 | - PyErr_Clear(); |
2839 | - if (strcmp(name, "closed") == 0) |
2840 | - return PyInt_FromLong((long)!(self->open)); |
2841 | -#if PY_VERSION_HEX < 0x02020000 |
2842 | - return PyMember_Get((char *)self, _mysql_ConnectionObject_memberlist, name); |
2843 | -#else |
2844 | - { |
2845 | - MyMemberlist(*l); |
2846 | - for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++) { |
2847 | - if (strcmp(l->name, name) == 0) |
2848 | - return PyMember_GetOne((char *)self, l); |
2849 | - } |
2850 | - PyErr_SetString(PyExc_AttributeError, name); |
2851 | - return NULL; |
2852 | - } |
2853 | -#endif |
2854 | -} |
2855 | - |
2856 | -static PyObject * |
2857 | -_mysql_ResultObject_getattr( |
2858 | - _mysql_ResultObject *self, |
2859 | - char *name) |
2860 | -{ |
2861 | - PyObject *res; |
2862 | - |
2863 | - res = Py_FindMethod(_mysql_ResultObject_methods, (PyObject *)self, name); |
2864 | - if (res != NULL) |
2865 | - return res; |
2866 | - PyErr_Clear(); |
2867 | -#if PY_VERSION_HEX < 0x02020000 |
2868 | - return PyMember_Get((char *)self, _mysql_ResultObject_memberlist, name); |
2869 | -#else |
2870 | - { |
2871 | - MyMemberlist(*l); |
2872 | - for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++) { |
2873 | - if (strcmp(l->name, name) == 0) |
2874 | - return PyMember_GetOne((char *)self, l); |
2875 | - } |
2876 | - PyErr_SetString(PyExc_AttributeError, name); |
2877 | - return NULL; |
2878 | - } |
2879 | -#endif |
2880 | -} |
2881 | - |
2882 | -static int |
2883 | -_mysql_ConnectionObject_setattr( |
2884 | - _mysql_ConnectionObject *self, |
2885 | - char *name, |
2886 | - PyObject *v) |
2887 | -{ |
2888 | - if (v == NULL) { |
2889 | - PyErr_SetString(PyExc_AttributeError, |
2890 | - "can't delete connection attributes"); |
2891 | - return -1; |
2892 | - } |
2893 | -#if PY_VERSION_HEX < 0x02020000 |
2894 | - return PyMember_Set((char *)self, _mysql_ConnectionObject_memberlist, name, v); |
2895 | -#else |
2896 | - { |
2897 | - MyMemberlist(*l); |
2898 | - for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++) |
2899 | - if (strcmp(l->name, name) == 0) |
2900 | - return PyMember_SetOne((char *)self, l, v); |
2901 | - } |
2902 | - PyErr_SetString(PyExc_AttributeError, name); |
2903 | - return -1; |
2904 | -#endif |
2905 | -} |
2906 | - |
2907 | -static int |
2908 | -_mysql_ResultObject_setattr( |
2909 | - _mysql_ResultObject *self, |
2910 | - char *name, |
2911 | - PyObject *v) |
2912 | -{ |
2913 | - if (v == NULL) { |
2914 | - PyErr_SetString(PyExc_AttributeError, |
2915 | - "can't delete connection attributes"); |
2916 | - return -1; |
2917 | - } |
2918 | -#if PY_VERSION_HEX < 0x02020000 |
2919 | - return PyMember_Set((char *)self, _mysql_ResultObject_memberlist, name, v); |
2920 | -#else |
2921 | - { |
2922 | - MyMemberlist(*l); |
2923 | - for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++) |
2924 | - if (strcmp(l->name, name) == 0) |
2925 | - return PyMember_SetOne((char *)self, l, v); |
2926 | - } |
2927 | - PyErr_SetString(PyExc_AttributeError, name); |
2928 | - return -1; |
2929 | -#endif |
2930 | -} |
2931 | - |
2932 | -PyTypeObject _mysql_ConnectionObject_Type = { |
2933 | - PyObject_HEAD_INIT(NULL) |
2934 | - 0, |
2935 | - "_mysql.connection", /* (char *)tp_name For printing */ |
2936 | - sizeof(_mysql_ConnectionObject), |
2937 | - 0, |
2938 | - (destructor)_mysql_ConnectionObject_dealloc, /* tp_dealloc */ |
2939 | - 0, /*tp_print*/ |
2940 | - (getattrfunc)_mysql_ConnectionObject_getattr, /* tp_getattr */ |
2941 | - (setattrfunc)_mysql_ConnectionObject_setattr, /* tp_setattr */ |
2942 | - 0, /*tp_compare*/ |
2943 | - (reprfunc)_mysql_ConnectionObject_repr, /* tp_repr */ |
2944 | - |
2945 | - /* Method suites for standard classes */ |
2946 | - |
2947 | - 0, /* (PyNumberMethods *) tp_as_number */ |
2948 | - 0, /* (PySequenceMethods *) tp_as_sequence */ |
2949 | - 0, /* (PyMappingMethods *) tp_as_mapping */ |
2950 | - |
2951 | - /* More standard operations (here for binary compatibility) */ |
2952 | - |
2953 | - 0, /* (hashfunc) tp_hash */ |
2954 | - 0, /* (ternaryfunc) tp_call */ |
2955 | - 0, /* (reprfunc) tp_str */ |
2956 | - 0, /* (getattrofunc) tp_getattro */ |
2957 | - 0, /* (setattrofunc) tp_setattro */ |
2958 | - |
2959 | - /* Functions to access object as input/output buffer */ |
2960 | - 0, /* (PyBufferProcs *) tp_as_buffer */ |
2961 | - |
2962 | - /* Flags to define presence of optional/expanded features */ |
2963 | -#if PY_VERSION_HEX < 0x02020000 |
2964 | - Py_TPFLAGS_DEFAULT, /* (long) tp_flags */ |
2965 | -#else |
2966 | - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, |
2967 | -#endif |
2968 | - _mysql_connect__doc__, /* (char *) tp_doc Documentation string */ |
2969 | -#if PY_VERSION_HEX >= 0x02000000 |
2970 | - /* Assigned meaning in release 2.0 */ |
2971 | -#if PY_VERSION_HEX >= 0x02020000 |
2972 | - /* call function for all accessible objects */ |
2973 | - (traverseproc) _mysql_ConnectionObject_traverse, /* tp_traverse */ |
2974 | - |
2975 | - /* delete references to contained objects */ |
2976 | - (inquiry) _mysql_ConnectionObject_clear, /* tp_clear */ |
2977 | -#else |
2978 | - /* not supporting pre-2.2 GC */ |
2979 | - 0, |
2980 | - 0, |
2981 | -#endif |
2982 | -#if PY_VERSION_HEX >= 0x02010000 |
2983 | - /* Assigned meaning in release 2.1 */ |
2984 | - /* rich comparisons */ |
2985 | - 0, /* (richcmpfunc) tp_richcompare */ |
2986 | - |
2987 | - /* weak reference enabler */ |
2988 | - 0, /* (long) tp_weaklistoffset */ |
2989 | -#if PY_VERSION_HEX >= 0x02020000 |
2990 | - /* Added in release 2.2 */ |
2991 | - /* Iterators */ |
2992 | - 0, /* (getiterfunc) tp_iter */ |
2993 | - 0, /* (iternextfunc) tp_iternext */ |
2994 | - |
2995 | - /* Attribute descriptor and subclassing stuff */ |
2996 | - (struct PyMethodDef *)_mysql_ConnectionObject_methods, /* tp_methods */ |
2997 | - (MyMemberlist(*))_mysql_ConnectionObject_memberlist, /* tp_members */ |
2998 | - 0, /* (struct getsetlist *) tp_getset; */ |
2999 | - 0, /* (struct _typeobject *) tp_base; */ |
3000 | - 0, /* (PyObject *) tp_dict */ |
3001 | - 0, /* (descrgetfunc) tp_descr_get */ |
3002 | - 0, /* (descrsetfunc) tp_descr_set */ |
3003 | - 0, /* (long) tp_dictoffset */ |
3004 | - (initproc)_mysql_ConnectionObject_Initialize, /* tp_init */ |
3005 | - NULL, /* tp_alloc */ |
3006 | - NULL, /* tp_new */ |
3007 | - NULL, /* tp_free Low-level free-memory routine */ |
3008 | - 0, /* (PyObject *) tp_bases */ |
3009 | - 0, /* (PyObject *) tp_mro method resolution order */ |
3010 | - 0, /* (PyObject *) tp_defined */ |
3011 | -#endif /* python 2.2 */ |
3012 | -#endif /* python 2.1 */ |
3013 | -#endif /* python 2.0 */ |
3014 | -} ; |
3015 | - |
3016 | -PyTypeObject _mysql_ResultObject_Type = { |
3017 | - PyObject_HEAD_INIT(NULL) |
3018 | - 0, |
3019 | - "_mysql.result", |
3020 | - sizeof(_mysql_ResultObject), |
3021 | - 0, |
3022 | - (destructor)_mysql_ResultObject_dealloc, /* tp_dealloc */ |
3023 | - 0, /*tp_print*/ |
3024 | - (getattrfunc)_mysql_ResultObject_getattr, /* tp_getattr */ |
3025 | - (setattrfunc)_mysql_ResultObject_setattr, /* tp_setattr */ |
3026 | - 0, /*tp_compare*/ |
3027 | - (reprfunc)_mysql_ResultObject_repr, /* tp_repr */ |
3028 | - |
3029 | - /* Method suites for standard classes */ |
3030 | - |
3031 | - 0, /* (PyNumberMethods *) tp_as_number */ |
3032 | - 0, /* (PySequenceMethods *) tp_as_sequence */ |
3033 | - 0, /* (PyMappingMethods *) tp_as_mapping */ |
3034 | - |
3035 | - /* More standard operations (here for binary compatibility) */ |
3036 | - |
3037 | - 0, /* (hashfunc) tp_hash */ |
3038 | - 0, /* (ternaryfunc) tp_call */ |
3039 | - 0, /* (reprfunc) tp_str */ |
3040 | - 0, /* (getattrofunc) tp_getattro */ |
3041 | - 0, /* (setattrofunc) tp_setattro */ |
3042 | - |
3043 | - /* Functions to access object as input/output buffer */ |
3044 | - 0, /* (PyBufferProcs *) tp_as_buffer */ |
3045 | - |
3046 | - /* Flags to define presence of optional/expanded features */ |
3047 | -#if PY_VERSION_HEX < 0x02020000 |
3048 | - Py_TPFLAGS_DEFAULT, /* (long) tp_flags */ |
3049 | -#else |
3050 | - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, |
3051 | -#endif |
3052 | - |
3053 | - _mysql_ResultObject__doc__, /* (char *) tp_doc Documentation string */ |
3054 | -#if PY_VERSION_HEX >= 0x02000000 |
3055 | - /* Assigned meaning in release 2.0 */ |
3056 | -#if PY_VERSION_HEX >= 0x02020000 |
3057 | - /* call function for all accessible objects */ |
3058 | - (traverseproc) _mysql_ResultObject_traverse, /* tp_traverse */ |
3059 | - |
3060 | - /* delete references to contained objects */ |
3061 | - (inquiry) _mysql_ResultObject_clear, /* tp_clear */ |
3062 | -#else |
3063 | - /* not supporting pre-2.2 GC */ |
3064 | - 0, |
3065 | - 0, |
3066 | -#endif |
3067 | -#if PY_VERSION_HEX >= 0x02010000 |
3068 | - /* Assigned meaning in release 2.1 */ |
3069 | - /* rich comparisons */ |
3070 | - 0, /* (richcmpfunc) tp_richcompare */ |
3071 | - |
3072 | - /* weak reference enabler */ |
3073 | - 0, /* (long) tp_weaklistoffset */ |
3074 | -#if PY_VERSION_HEX >= 0x02020000 |
3075 | - /* Added in release 2.2 */ |
3076 | - /* Iterators */ |
3077 | - 0, /* (getiterfunc) tp_iter */ |
3078 | - 0, /* (iternextfunc) tp_iternext */ |
3079 | - |
3080 | - /* Attribute descriptor and subclassing stuff */ |
3081 | - (struct PyMethodDef *) _mysql_ResultObject_methods, /* tp_methods */ |
3082 | - (MyMemberlist(*)) _mysql_ResultObject_memberlist, /*tp_members */ |
3083 | - 0, /* (struct getsetlist *) tp_getset; */ |
3084 | - 0, /* (struct _typeobject *) tp_base; */ |
3085 | - 0, /* (PyObject *) tp_dict */ |
3086 | - 0, /* (descrgetfunc) tp_descr_get */ |
3087 | - 0, /* (descrsetfunc) tp_descr_set */ |
3088 | - 0, /* (long) tp_dictoffset */ |
3089 | - (initproc)_mysql_ResultObject_Initialize, /* tp_init */ |
3090 | - NULL, /* tp_alloc */ |
3091 | - NULL, /* tp_new */ |
3092 | - NULL, /* tp_free Low-level free-memory routine */ |
3093 | - 0, /* (PyObject *) tp_bases */ |
3094 | - 0, /* (PyObject *) tp_mro method resolution order */ |
3095 | - 0, /* (PyObject *) tp_defined */ |
3096 | -#endif /* python 2.2 */ |
3097 | -#endif /* python 2.1 */ |
3098 | -#endif /* python 2.0 */ |
3099 | -}; |
3100 | - |
3101 | -static PyMethodDef |
3102 | -_mysql_methods[] = { |
3103 | - { |
3104 | - "connect", |
3105 | - (PyCFunction)_mysql_connect, |
3106 | - METH_VARARGS | METH_KEYWORDS, |
3107 | - _mysql_connect__doc__ |
3108 | - }, |
3109 | - { |
3110 | - "debug", |
3111 | - (PyCFunction)_mysql_debug, |
3112 | - METH_VARARGS, |
3113 | - _mysql_debug__doc__ |
3114 | - }, |
3115 | - { |
3116 | - "escape", |
3117 | - (PyCFunction)_mysql_escape, |
3118 | - METH_VARARGS, |
3119 | - _mysql_escape__doc__ |
3120 | - }, |
3121 | - { |
3122 | - "escape_sequence", |
3123 | - (PyCFunction)_mysql_escape_sequence, |
3124 | - METH_VARARGS, |
3125 | - _mysql_escape_sequence__doc__ |
3126 | - }, |
3127 | - { |
3128 | - "escape_dict", |
3129 | - (PyCFunction)_mysql_escape_dict, |
3130 | - METH_VARARGS, |
3131 | - _mysql_escape_dict__doc__ |
3132 | - }, |
3133 | - { |
3134 | - "escape_string", |
3135 | - (PyCFunction)_mysql_escape_string, |
3136 | - METH_VARARGS, |
3137 | - _mysql_escape_string__doc__ |
3138 | - }, |
3139 | - { |
3140 | - "string_literal", |
3141 | - (PyCFunction)_mysql_string_literal, |
3142 | - METH_VARARGS, |
3143 | - _mysql_string_literal__doc__ |
3144 | - }, |
3145 | - { |
3146 | - "get_client_info", |
3147 | - (PyCFunction)_mysql_get_client_info, |
3148 | - METH_VARARGS, |
3149 | - _mysql_get_client_info__doc__ |
3150 | - }, |
3151 | -#if MYSQL_VERSION_ID >= 32314 |
3152 | - { |
3153 | - "thread_safe", |
3154 | - (PyCFunction)_mysql_thread_safe, |
3155 | - METH_VARARGS, |
3156 | - _mysql_thread_safe__doc__ |
3157 | - }, |
3158 | -#endif |
3159 | - { |
3160 | - "server_init", |
3161 | - (PyCFunction)_mysql_server_init, |
3162 | - METH_VARARGS | METH_KEYWORDS, |
3163 | - _mysql_server_init__doc__ |
3164 | - }, |
3165 | - { |
3166 | - "server_end", |
3167 | - (PyCFunction)_mysql_server_end, |
3168 | - METH_VARARGS, |
3169 | - _mysql_server_end__doc__ |
3170 | - }, |
3171 | - {NULL, NULL} /* sentinel */ |
3172 | -}; |
3173 | - |
3174 | -static PyObject * |
3175 | -_mysql_NewException( |
3176 | - PyObject *dict, |
3177 | - PyObject *edict, |
3178 | - char *name) |
3179 | -{ |
3180 | - PyObject *e; |
3181 | - |
3182 | - if (!(e = PyDict_GetItemString(edict, name))) |
3183 | - return NULL; |
3184 | - if (PyDict_SetItemString(dict, name, e)) return NULL; |
3185 | - return e; |
3186 | -} |
3187 | - |
3188 | -#define QUOTE(X) _QUOTE(X) |
3189 | -#define _QUOTE(X) #X |
3190 | - |
3191 | -static char _mysql___doc__[] = |
3192 | -"an adaptation of the MySQL C API (mostly)\n\ |
3193 | -\n\ |
3194 | -You probably are better off using MySQLdb instead of using this\n\ |
3195 | -module directly.\n\ |
3196 | -\n\ |
3197 | -In general, renaming goes from mysql_* to _mysql.*. _mysql.connect()\n\ |
3198 | -returns a connection object (MYSQL). Functions which expect MYSQL * as\n\ |
3199 | -an argument are now methods of the connection object. A number of things\n\ |
3200 | -return result objects (MYSQL_RES). Functions which expect MYSQL_RES * as\n\ |
3201 | -an argument are now methods of the result object. Deprecated functions\n\ |
3202 | -(as of 3.23) are NOT implemented.\n\ |
3203 | -"; |
3204 | - |
3205 | -DL_EXPORT(void) |
3206 | -init_mysql(void) |
3207 | -{ |
3208 | - PyObject *dict, *module, *emod, *edict; |
3209 | - module = Py_InitModule4("_mysql", _mysql_methods, _mysql___doc__, |
3210 | - (PyObject *)NULL, PYTHON_API_VERSION); |
3211 | - if (!module) return; /* this really should never happen */ |
3212 | - _mysql_ConnectionObject_Type.ob_type = &PyType_Type; |
3213 | - _mysql_ResultObject_Type.ob_type = &PyType_Type; |
3214 | -#if PY_VERSION_HEX >= 0x02020000 |
3215 | - _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc; |
3216 | - _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew; |
3217 | - _mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del; |
3218 | - _mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc; |
3219 | - _mysql_ResultObject_Type.tp_new = PyType_GenericNew; |
3220 | - _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del; |
3221 | -#endif |
3222 | - |
3223 | - if (!(dict = PyModule_GetDict(module))) goto error; |
3224 | - if (PyDict_SetItemString(dict, "version_info", |
3225 | - PyRun_String(QUOTE(version_info), Py_eval_input, |
3226 | - dict, dict))) |
3227 | - goto error; |
3228 | - if (PyDict_SetItemString(dict, "__version__", |
3229 | - PyString_FromString(QUOTE(__version__)))) |
3230 | - goto error; |
3231 | - if (PyDict_SetItemString(dict, "connection", |
3232 | - (PyObject *)&_mysql_ConnectionObject_Type)) |
3233 | - goto error; |
3234 | - Py_INCREF(&_mysql_ConnectionObject_Type); |
3235 | - if (PyDict_SetItemString(dict, "result", |
3236 | - (PyObject *)&_mysql_ResultObject_Type)) |
3237 | - goto error; |
3238 | - Py_INCREF(&_mysql_ResultObject_Type); |
3239 | - if (!(emod = PyImport_ImportModule("_mysql_exceptions"))) |
3240 | - goto error; |
3241 | - if (!(edict = PyModule_GetDict(emod))) goto error; |
3242 | - if (!(_mysql_MySQLError = |
3243 | - _mysql_NewException(dict, edict, "MySQLError"))) |
3244 | - goto error; |
3245 | - if (!(_mysql_Warning = |
3246 | - _mysql_NewException(dict, edict, "Warning"))) |
3247 | - goto error; |
3248 | - if (!(_mysql_Error = |
3249 | - _mysql_NewException(dict, edict, "Error"))) |
3250 | - goto error; |
3251 | - if (!(_mysql_InterfaceError = |
3252 | - _mysql_NewException(dict, edict, "InterfaceError"))) |
3253 | - goto error; |
3254 | - if (!(_mysql_DatabaseError = |
3255 | - _mysql_NewException(dict, edict, "DatabaseError"))) |
3256 | - goto error; |
3257 | - if (!(_mysql_DataError = |
3258 | - _mysql_NewException(dict, edict, "DataError"))) |
3259 | - goto error; |
3260 | - if (!(_mysql_OperationalError = |
3261 | - _mysql_NewException(dict, edict, "OperationalError"))) |
3262 | - goto error; |
3263 | - if (!(_mysql_IntegrityError = |
3264 | - _mysql_NewException(dict, edict, "IntegrityError"))) |
3265 | - goto error; |
3266 | - if (!(_mysql_InternalError = |
3267 | - _mysql_NewException(dict, edict, "InternalError"))) |
3268 | - goto error; |
3269 | - if (!(_mysql_ProgrammingError = |
3270 | - _mysql_NewException(dict, edict, "ProgrammingError"))) |
3271 | - goto error; |
3272 | - if (!(_mysql_NotSupportedError = |
3273 | - _mysql_NewException(dict, edict, "NotSupportedError"))) |
3274 | - goto error; |
3275 | - Py_DECREF(emod); |
3276 | - if (!(_mysql_NULL = PyString_FromString("NULL"))) |
3277 | - goto error; |
3278 | - if (PyDict_SetItemString(dict, "NULL", _mysql_NULL)) goto error; |
3279 | - error: |
3280 | - if (PyErr_Occurred()) |
3281 | - PyErr_SetString(PyExc_ImportError, |
3282 | - "_mysql: init failed"); |
3283 | - return; |
3284 | -} |
3285 | - |
3286 | - |
3287 | |
3288 | === removed directory '.pc/06_fix_error_checking.patch' |
3289 | === removed file '.pc/06_fix_error_checking.patch/_mysql.c' |
3290 | --- .pc/06_fix_error_checking.patch/_mysql.c 2013-03-11 18:03:06 +0000 |
3291 | +++ .pc/06_fix_error_checking.patch/_mysql.c 1970-01-01 00:00:00 +0000 |
3292 | @@ -1,2894 +0,0 @@ |
3293 | -/* |
3294 | -This program is free software; you can redistribute it and/or modify |
3295 | -it under the terms of the GNU General Public License as published by |
3296 | -the Free Software Foundation; either version 2, or (at your option) |
3297 | -any later version. Alternatively, you may use the original license |
3298 | -reproduced below. |
3299 | - |
3300 | -Copyright 1999 by Comstar.net, Inc., Atlanta, GA, US. |
3301 | - |
3302 | - All Rights Reserved |
3303 | - |
3304 | -Permission to use, copy, modify, and distribute this software and its |
3305 | -documentation for any purpose and without fee is hereby granted, |
3306 | -provided that the above copyright notice appear in all copies and that |
3307 | -both that copyright notice and this permission notice appear in |
3308 | -supporting documentation, and that the name of Comstar.net, Inc. |
3309 | -or COMSTAR not be used in advertising or publicity pertaining to |
3310 | -distribution of the software without specific, written prior permission. |
3311 | - |
3312 | -COMSTAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
3313 | -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
3314 | -EVENT SHALL COMSTAR BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
3315 | -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
3316 | -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
3317 | -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
3318 | -PERFORMANCE OF THIS SOFTWARE. |
3319 | -*/ |
3320 | - |
3321 | -#include "pymemcompat.h" |
3322 | -#include "structmember.h" |
3323 | -#if defined(MS_WINDOWS) |
3324 | -#include <winsock2.h> |
3325 | -#include <windows.h> |
3326 | -#include <config-win.h> |
3327 | -#else |
3328 | -#include "my_config.h" |
3329 | -#endif |
3330 | -#include "mysql.h" |
3331 | -#include "mysqld_error.h" |
3332 | -#include "errmsg.h" |
3333 | - |
3334 | -#if PY_VERSION_HEX < 0x02020000 |
3335 | -# define MyTuple_Resize(t,n,d) _PyTuple_Resize(t, n, d) |
3336 | -# define MyMember(a,b,c,d,e) {a,b,c,d} |
3337 | -# define MyMemberlist(x) struct memberlist x |
3338 | -# define MyAlloc(s,t) PyObject_New(s,&t) |
3339 | -# define MyFree(o) PyObject_Del(o) |
3340 | -#else |
3341 | -# define MyTuple_Resize(t,n,d) _PyTuple_Resize(t, n) |
3342 | -# define MyMember(a,b,c,d,e) {a,b,c,d,e} |
3343 | -# define MyMemberlist(x) struct PyMemberDef x |
3344 | -# define MyAlloc(s,t) (s *) t.tp_alloc(&t,0) |
3345 | -# define MyFree(ob) ob->ob_type->tp_free((PyObject *)ob) |
3346 | -#endif |
3347 | - |
3348 | -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) |
3349 | -typedef int Py_ssize_t; |
3350 | -#define PY_SSIZE_T_MAX INT_MAX |
3351 | -#define PY_SSIZE_T_MIN INT_MIN |
3352 | -#endif |
3353 | - |
3354 | -static PyObject *_mysql_MySQLError; |
3355 | -static PyObject *_mysql_Warning; |
3356 | -static PyObject *_mysql_Error; |
3357 | -static PyObject *_mysql_DatabaseError; |
3358 | -static PyObject *_mysql_InterfaceError; |
3359 | -static PyObject *_mysql_DataError; |
3360 | -static PyObject *_mysql_OperationalError; |
3361 | -static PyObject *_mysql_IntegrityError; |
3362 | -static PyObject *_mysql_InternalError; |
3363 | -static PyObject *_mysql_ProgrammingError; |
3364 | -static PyObject *_mysql_NotSupportedError; |
3365 | - |
3366 | -typedef struct { |
3367 | - PyObject_HEAD |
3368 | - MYSQL connection; |
3369 | - int open; |
3370 | - PyObject *converter; |
3371 | -} _mysql_ConnectionObject; |
3372 | - |
3373 | -#define check_connection(c) if (!(c->open)) return _mysql_Exception(c) |
3374 | -#define result_connection(r) ((_mysql_ConnectionObject *)r->conn) |
3375 | -#define check_result_connection(r) check_connection(result_connection(r)) |
3376 | - |
3377 | -extern PyTypeObject _mysql_ConnectionObject_Type; |
3378 | - |
3379 | -typedef struct { |
3380 | - PyObject_HEAD |
3381 | - PyObject *conn; |
3382 | - MYSQL_RES *result; |
3383 | - int nfields; |
3384 | - int use; |
3385 | - PyObject *converter; |
3386 | -} _mysql_ResultObject; |
3387 | - |
3388 | -extern PyTypeObject _mysql_ResultObject_Type; |
3389 | - |
3390 | -static int _mysql_server_init_done = 0; |
3391 | -#if MYSQL_VERSION_ID >= 40000 |
3392 | -#define check_server_init(x) if (!_mysql_server_init_done) { if (mysql_server_init(0, NULL, NULL)) { _mysql_Exception(NULL); return x; } else { _mysql_server_init_done = 1;} } |
3393 | -#else |
3394 | -#define check_server_init(x) if (!_mysql_server_init_done) _mysql_server_init_done = 1 |
3395 | -#endif |
3396 | - |
3397 | -#if MYSQL_VERSION_ID >= 50500 |
3398 | -#define HAVE_OPENSSL 1 |
3399 | -#endif |
3400 | - |
3401 | -PyObject * |
3402 | -_mysql_Exception(_mysql_ConnectionObject *c) |
3403 | -{ |
3404 | - PyObject *t, *e; |
3405 | - int merr; |
3406 | - |
3407 | - if (!(t = PyTuple_New(2))) return NULL; |
3408 | - if (!_mysql_server_init_done) { |
3409 | - e = _mysql_InternalError; |
3410 | - PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L)); |
3411 | - PyTuple_SET_ITEM(t, 1, PyString_FromString("server not initialized")); |
3412 | - PyErr_SetObject(e, t); |
3413 | - Py_DECREF(t); |
3414 | - return NULL; |
3415 | - } |
3416 | - merr = mysql_errno(&(c->connection)); |
3417 | - if (!merr) |
3418 | - e = _mysql_InterfaceError; |
3419 | - else if (merr > CR_MAX_ERROR) { |
3420 | - PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L)); |
3421 | - PyTuple_SET_ITEM(t, 1, PyString_FromString("error totally whack")); |
3422 | - PyErr_SetObject(_mysql_InterfaceError, t); |
3423 | - Py_DECREF(t); |
3424 | - return NULL; |
3425 | - } |
3426 | - else switch (merr) { |
3427 | - case CR_COMMANDS_OUT_OF_SYNC: |
3428 | - case ER_DB_CREATE_EXISTS: |
3429 | - case ER_SYNTAX_ERROR: |
3430 | - case ER_PARSE_ERROR: |
3431 | - case ER_NO_SUCH_TABLE: |
3432 | - case ER_WRONG_DB_NAME: |
3433 | - case ER_WRONG_TABLE_NAME: |
3434 | - case ER_FIELD_SPECIFIED_TWICE: |
3435 | - case ER_INVALID_GROUP_FUNC_USE: |
3436 | - case ER_UNSUPPORTED_EXTENSION: |
3437 | - case ER_TABLE_MUST_HAVE_COLUMNS: |
3438 | -#ifdef ER_CANT_DO_THIS_DURING_AN_TRANSACTION |
3439 | - case ER_CANT_DO_THIS_DURING_AN_TRANSACTION: |
3440 | -#endif |
3441 | - e = _mysql_ProgrammingError; |
3442 | - break; |
3443 | -#ifdef WARN_DATA_TRUNCATED |
3444 | - case WARN_DATA_TRUNCATED: |
3445 | -#ifdef WARN_NULL_TO_NOTNULL |
3446 | - case WARN_NULL_TO_NOTNULL: |
3447 | -#endif |
3448 | -#ifdef ER_WARN_DATA_OUT_OF_RANGE |
3449 | - case ER_WARN_DATA_OUT_OF_RANGE: |
3450 | -#endif |
3451 | -#ifdef ER_NO_DEFAULT |
3452 | - case ER_NO_DEFAULT: |
3453 | -#endif |
3454 | -#ifdef ER_PRIMARY_CANT_HAVE_NULL |
3455 | - case ER_PRIMARY_CANT_HAVE_NULL: |
3456 | -#endif |
3457 | -#ifdef ER_DATA_TOO_LONG |
3458 | - case ER_DATA_TOO_LONG: |
3459 | -#endif |
3460 | -#ifdef ER_DATETIME_FUNCTION_OVERFLOW |
3461 | - case ER_DATETIME_FUNCTION_OVERFLOW: |
3462 | -#endif |
3463 | - e = _mysql_DataError; |
3464 | - break; |
3465 | -#endif |
3466 | - case ER_DUP_ENTRY: |
3467 | -#ifdef ER_DUP_UNIQUE |
3468 | - case ER_DUP_UNIQUE: |
3469 | -#endif |
3470 | -#ifdef ER_NO_REFERENCED_ROW |
3471 | - case ER_NO_REFERENCED_ROW: |
3472 | -#endif |
3473 | -#ifdef ER_NO_REFERENCED_ROW_2 |
3474 | - case ER_NO_REFERENCED_ROW_2: |
3475 | -#endif |
3476 | -#ifdef ER_ROW_IS_REFERENCED |
3477 | - case ER_ROW_IS_REFERENCED: |
3478 | -#endif |
3479 | -#ifdef ER_ROW_IS_REFERENCED_2 |
3480 | - case ER_ROW_IS_REFERENCED_2: |
3481 | -#endif |
3482 | -#ifdef ER_CANNOT_ADD_FOREIGN |
3483 | - case ER_CANNOT_ADD_FOREIGN: |
3484 | -#endif |
3485 | - e = _mysql_IntegrityError; |
3486 | - break; |
3487 | -#ifdef ER_WARNING_NOT_COMPLETE_ROLLBACK |
3488 | - case ER_WARNING_NOT_COMPLETE_ROLLBACK: |
3489 | -#endif |
3490 | -#ifdef ER_NOT_SUPPORTED_YET |
3491 | - case ER_NOT_SUPPORTED_YET: |
3492 | -#endif |
3493 | -#ifdef ER_FEATURE_DISABLED |
3494 | - case ER_FEATURE_DISABLED: |
3495 | -#endif |
3496 | -#ifdef ER_UNKNOWN_STORAGE_ENGINE |
3497 | - case ER_UNKNOWN_STORAGE_ENGINE: |
3498 | -#endif |
3499 | - e = _mysql_NotSupportedError; |
3500 | - break; |
3501 | - default: |
3502 | - if (merr < 1000) |
3503 | - e = _mysql_InternalError; |
3504 | - else |
3505 | - e = _mysql_OperationalError; |
3506 | - break; |
3507 | - } |
3508 | - PyTuple_SET_ITEM(t, 0, PyInt_FromLong((long)merr)); |
3509 | - PyTuple_SET_ITEM(t, 1, PyString_FromString(mysql_error(&(c->connection)))); |
3510 | - PyErr_SetObject(e, t); |
3511 | - Py_DECREF(t); |
3512 | - return NULL; |
3513 | -} |
3514 | - |
3515 | -static char _mysql_server_init__doc__[] = |
3516 | -"Initialize embedded server. If this client is not linked against\n\ |
3517 | -the embedded server library, this function does nothing.\n\ |
3518 | -\n\ |
3519 | -args -- sequence of command-line arguments\n\ |
3520 | -groups -- sequence of groups to use in defaults files\n\ |
3521 | -"; |
3522 | - |
3523 | -static PyObject *_mysql_server_init( |
3524 | - PyObject *self, |
3525 | - PyObject *args, |
3526 | - PyObject *kwargs) { |
3527 | - static char *kwlist[] = {"args", "groups", NULL}; |
3528 | - char **cmd_args_c=NULL, **groups_c=NULL, *s; |
3529 | - int cmd_argc=0, i, groupc; |
3530 | - PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item; |
3531 | - |
3532 | - if (_mysql_server_init_done) { |
3533 | - PyErr_SetString(_mysql_ProgrammingError, |
3534 | - "already initialized"); |
3535 | - return NULL; |
3536 | - } |
3537 | - |
3538 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist, |
3539 | - &cmd_args, &groups)) |
3540 | - return NULL; |
3541 | - |
3542 | -#if MYSQL_VERSION_ID >= 40000 |
3543 | - if (cmd_args) { |
3544 | - if (!PySequence_Check(cmd_args)) { |
3545 | - PyErr_SetString(PyExc_TypeError, |
3546 | - "args must be a sequence"); |
3547 | - goto finish; |
3548 | - } |
3549 | - cmd_argc = PySequence_Size(cmd_args); |
3550 | - if (cmd_argc == -1) { |
3551 | - PyErr_SetString(PyExc_TypeError, |
3552 | - "args could not be sized"); |
3553 | - goto finish; |
3554 | - } |
3555 | - cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *)); |
3556 | - for (i=0; i< cmd_argc; i++) { |
3557 | - item = PySequence_GetItem(cmd_args, i); |
3558 | - s = PyString_AsString(item); |
3559 | - Py_DECREF(item); |
3560 | - if (!s) { |
3561 | - PyErr_SetString(PyExc_TypeError, |
3562 | - "args must contain strings"); |
3563 | - goto finish; |
3564 | - } |
3565 | - cmd_args_c[i] = s; |
3566 | - } |
3567 | - } |
3568 | - if (groups) { |
3569 | - if (!PySequence_Check(groups)) { |
3570 | - PyErr_SetString(PyExc_TypeError, |
3571 | - "groups must be a sequence"); |
3572 | - goto finish; |
3573 | - } |
3574 | - groupc = PySequence_Size(groups); |
3575 | - if (groupc == -1) { |
3576 | - PyErr_SetString(PyExc_TypeError, |
3577 | - "groups could not be sized"); |
3578 | - goto finish; |
3579 | - } |
3580 | - groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *)); |
3581 | - for (i=0; i< groupc; i++) { |
3582 | - item = PySequence_GetItem(groups, i); |
3583 | - s = PyString_AsString(item); |
3584 | - Py_DECREF(item); |
3585 | - if (!s) { |
3586 | - PyErr_SetString(PyExc_TypeError, |
3587 | - "groups must contain strings"); |
3588 | - goto finish; |
3589 | - } |
3590 | - groups_c[i] = s; |
3591 | - } |
3592 | - groups_c[groupc] = (char *)NULL; |
3593 | - } |
3594 | - /* even though this may block, don't give up the interpreter lock |
3595 | - so that the server can't be initialized multiple times. */ |
3596 | - if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) { |
3597 | - _mysql_Exception(NULL); |
3598 | - goto finish; |
3599 | - } |
3600 | -#endif |
3601 | - ret = Py_None; |
3602 | - Py_INCREF(Py_None); |
3603 | - _mysql_server_init_done = 1; |
3604 | - finish: |
3605 | - PyMem_Free(groups_c); |
3606 | - PyMem_Free(cmd_args_c); |
3607 | - return ret; |
3608 | -} |
3609 | - |
3610 | -static char _mysql_server_end__doc__[] = |
3611 | -"Shut down embedded server. If not using an embedded server, this\n\ |
3612 | -does nothing."; |
3613 | - |
3614 | -static PyObject *_mysql_server_end( |
3615 | - PyObject *self, |
3616 | - PyObject *args) { |
3617 | - if (_mysql_server_init_done) { |
3618 | -#if MYSQL_VERSION_ID >= 40000 |
3619 | - mysql_server_end(); |
3620 | -#endif |
3621 | - _mysql_server_init_done = 0; |
3622 | - Py_INCREF(Py_None); |
3623 | - return Py_None; |
3624 | - } |
3625 | - return _mysql_Exception(NULL); |
3626 | -} |
3627 | - |
3628 | -#if MYSQL_VERSION_ID >= 32314 |
3629 | -static char _mysql_thread_safe__doc__[] = |
3630 | -"Indicates whether the client is compiled as thread-safe."; |
3631 | - |
3632 | -static PyObject *_mysql_thread_safe( |
3633 | - PyObject *self, |
3634 | - PyObject *args) { |
3635 | - PyObject *flag; |
3636 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
3637 | - check_server_init(NULL); |
3638 | - if (!(flag=PyInt_FromLong((long)mysql_thread_safe()))) return NULL; |
3639 | - return flag; |
3640 | -} |
3641 | -#endif |
3642 | - |
3643 | -static char _mysql_ResultObject__doc__[] = |
3644 | -"result(connection, use=0, converter={}) -- Result set from a query.\n\ |
3645 | -\n\ |
3646 | -Creating instances of this class directly is an excellent way to\n\ |
3647 | -shoot yourself in the foot. If using _mysql.connection directly,\n\ |
3648 | -use connection.store_result() or connection.use_result() instead.\n\ |
3649 | -If using MySQLdb.Connection, this is done by the cursor class.\n\ |
3650 | -Just forget you ever saw this. Forget... FOR-GET..."; |
3651 | - |
3652 | -static int |
3653 | -_mysql_ResultObject_Initialize( |
3654 | - _mysql_ResultObject *self, |
3655 | - PyObject *args, |
3656 | - PyObject *kwargs) |
3657 | -{ |
3658 | - static char *kwlist[] = {"connection", "use", "converter", NULL}; |
3659 | - MYSQL_RES *result; |
3660 | - _mysql_ConnectionObject *conn=NULL; |
3661 | - int use=0; |
3662 | - PyObject *conv=NULL; |
3663 | - int n, i; |
3664 | - MYSQL_FIELD *fields; |
3665 | - |
3666 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist, |
3667 | - &conn, &use, &conv)) |
3668 | - return -1; |
3669 | - if (!conv) conv = PyDict_New(); |
3670 | - if (!conv) return -1; |
3671 | - self->conn = (PyObject *) conn; |
3672 | - Py_INCREF(conn); |
3673 | - self->use = use; |
3674 | - Py_BEGIN_ALLOW_THREADS ; |
3675 | - if (use) |
3676 | - result = mysql_use_result(&(conn->connection)); |
3677 | - else |
3678 | - result = mysql_store_result(&(conn->connection)); |
3679 | - self->result = result; |
3680 | - Py_END_ALLOW_THREADS ; |
3681 | - if (!result) { |
3682 | - self->converter = PyTuple_New(0); |
3683 | - return 0; |
3684 | - } |
3685 | - n = mysql_num_fields(result); |
3686 | - self->nfields = n; |
3687 | - if (!(self->converter = PyTuple_New(n))) return -1; |
3688 | - fields = mysql_fetch_fields(result); |
3689 | - for (i=0; i<n; i++) { |
3690 | - PyObject *tmp, *fun; |
3691 | - tmp = PyInt_FromLong((long) fields[i].type); |
3692 | - if (!tmp) return -1; |
3693 | - fun = PyObject_GetItem(conv, tmp); |
3694 | - Py_DECREF(tmp); |
3695 | - if (!fun) { |
3696 | - PyErr_Clear(); |
3697 | - fun = Py_None; |
3698 | - Py_INCREF(Py_None); |
3699 | - } |
3700 | - if (PySequence_Check(fun)) { |
3701 | - int j, n2=PySequence_Size(fun); |
3702 | - PyObject *fun2=NULL; |
3703 | - for (j=0; j<n2; j++) { |
3704 | - PyObject *t = PySequence_GetItem(fun, j); |
3705 | - if (!t) continue; |
3706 | - if (!PyTuple_Check(t)) goto cleanup; |
3707 | - if (PyTuple_GET_SIZE(t) == 2) { |
3708 | - long mask; |
3709 | - PyObject *pmask=NULL; |
3710 | - pmask = PyTuple_GET_ITEM(t, 0); |
3711 | - fun2 = PyTuple_GET_ITEM(t, 1); |
3712 | - if (PyInt_Check(pmask)) { |
3713 | - mask = PyInt_AS_LONG(pmask); |
3714 | - if (mask & fields[i].flags) { |
3715 | - Py_DECREF(t); |
3716 | - break; |
3717 | - } |
3718 | - else { |
3719 | - goto cleanup; |
3720 | - } |
3721 | - } else { |
3722 | - Py_DECREF(t); |
3723 | - break; |
3724 | - } |
3725 | - } |
3726 | - cleanup: |
3727 | - Py_DECREF(t); |
3728 | - } |
3729 | - if (!fun2) fun2 = Py_None; |
3730 | - Py_INCREF(fun2); |
3731 | - Py_DECREF(fun); |
3732 | - fun = fun2; |
3733 | - } |
3734 | - PyTuple_SET_ITEM(self->converter, i, fun); |
3735 | - } |
3736 | - return 0; |
3737 | -} |
3738 | - |
3739 | -#if PY_VERSION_HEX >= 0x02020000 |
3740 | -static int _mysql_ResultObject_traverse( |
3741 | - _mysql_ResultObject *self, |
3742 | - visitproc visit, |
3743 | - void *arg) |
3744 | -{ |
3745 | - int r; |
3746 | - if (self->converter) { |
3747 | - if (!(r = visit(self->converter, arg))) return r; |
3748 | - } |
3749 | - if (self->conn) |
3750 | - return visit(self->conn, arg); |
3751 | - return 0; |
3752 | -} |
3753 | -#endif |
3754 | - |
3755 | -static int _mysql_ResultObject_clear( |
3756 | - _mysql_ResultObject *self) |
3757 | -{ |
3758 | - Py_XDECREF(self->converter); |
3759 | - self->converter = NULL; |
3760 | - Py_XDECREF(self->conn); |
3761 | - self->conn = NULL; |
3762 | - return 0; |
3763 | -} |
3764 | - |
3765 | -static int |
3766 | -_mysql_ConnectionObject_Initialize( |
3767 | - _mysql_ConnectionObject *self, |
3768 | - PyObject *args, |
3769 | - PyObject *kwargs) |
3770 | -{ |
3771 | - MYSQL *conn = NULL; |
3772 | - PyObject *conv = NULL; |
3773 | - PyObject *ssl = NULL; |
3774 | -#if HAVE_OPENSSL |
3775 | - char *key = NULL, *cert = NULL, *ca = NULL, |
3776 | - *capath = NULL, *cipher = NULL; |
3777 | -#endif |
3778 | - char *host = NULL, *user = NULL, *passwd = NULL, |
3779 | - *db = NULL, *unix_socket = NULL; |
3780 | - unsigned int port = 0; |
3781 | - unsigned int client_flag = 0; |
3782 | - static char *kwlist[] = { "host", "user", "passwd", "db", "port", |
3783 | - "unix_socket", "conv", |
3784 | - "connect_timeout", "compress", |
3785 | - "named_pipe", "init_command", |
3786 | - "read_default_file", "read_default_group", |
3787 | - "client_flag", "ssl", |
3788 | - "local_infile", |
3789 | - NULL } ; |
3790 | - int connect_timeout = 0; |
3791 | - int compress = -1, named_pipe = -1, local_infile = -1; |
3792 | - char *init_command=NULL, |
3793 | - *read_default_file=NULL, |
3794 | - *read_default_group=NULL; |
3795 | - |
3796 | - self->converter = NULL; |
3797 | - self->open = 0; |
3798 | - check_server_init(-1); |
3799 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ssssisOiiisssiOi:connect", |
3800 | - kwlist, |
3801 | - &host, &user, &passwd, &db, |
3802 | - &port, &unix_socket, &conv, |
3803 | - &connect_timeout, |
3804 | - &compress, &named_pipe, |
3805 | - &init_command, &read_default_file, |
3806 | - &read_default_group, |
3807 | - &client_flag, &ssl, |
3808 | - &local_infile /* DO NOT PATCH FOR RECONNECT, IDIOTS |
3809 | - IF YOU DO THIS, I WILL NOT SUPPORT YOUR PACKAGES. */ |
3810 | - )) |
3811 | - return -1; |
3812 | - |
3813 | -#define _stringsuck(d,t,s) {t=PyMapping_GetItemString(s,#d);\ |
3814 | - if(t){d=PyString_AsString(t);Py_DECREF(t);}\ |
3815 | - PyErr_Clear();} |
3816 | - |
3817 | - if (ssl) { |
3818 | -#if HAVE_OPENSSL |
3819 | - PyObject *value = NULL; |
3820 | - _stringsuck(ca, value, ssl); |
3821 | - _stringsuck(capath, value, ssl); |
3822 | - _stringsuck(cert, value, ssl); |
3823 | - _stringsuck(key, value, ssl); |
3824 | - _stringsuck(cipher, value, ssl); |
3825 | -#else |
3826 | - PyErr_SetString(_mysql_NotSupportedError, |
3827 | - "client library does not have SSL support"); |
3828 | - return -1; |
3829 | -#endif |
3830 | - } |
3831 | - |
3832 | - Py_BEGIN_ALLOW_THREADS ; |
3833 | - conn = mysql_init(&(self->connection)); |
3834 | - if (connect_timeout) { |
3835 | - unsigned int timeout = connect_timeout; |
3836 | - mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT, |
3837 | - (char *)&timeout); |
3838 | - } |
3839 | - if (compress != -1) { |
3840 | - mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0); |
3841 | - client_flag |= CLIENT_COMPRESS; |
3842 | - } |
3843 | - if (named_pipe != -1) |
3844 | - mysql_options(&(self->connection), MYSQL_OPT_NAMED_PIPE, 0); |
3845 | - if (init_command != NULL) |
3846 | - mysql_options(&(self->connection), MYSQL_INIT_COMMAND, init_command); |
3847 | - if (read_default_file != NULL) |
3848 | - mysql_options(&(self->connection), MYSQL_READ_DEFAULT_FILE, read_default_file); |
3849 | - if (read_default_group != NULL) |
3850 | - mysql_options(&(self->connection), MYSQL_READ_DEFAULT_GROUP, read_default_group); |
3851 | - |
3852 | - if (local_infile != -1) |
3853 | - mysql_options(&(self->connection), MYSQL_OPT_LOCAL_INFILE, (char *) &local_infile); |
3854 | - |
3855 | -#if HAVE_OPENSSL |
3856 | - if (ssl) |
3857 | - mysql_ssl_set(&(self->connection), |
3858 | - key, cert, ca, capath, cipher); |
3859 | -#endif |
3860 | - |
3861 | - conn = mysql_real_connect(&(self->connection), host, user, passwd, db, |
3862 | - port, unix_socket, client_flag); |
3863 | - |
3864 | - Py_END_ALLOW_THREADS ; |
3865 | - |
3866 | - if (!conn) { |
3867 | - _mysql_Exception(self); |
3868 | - return -1; |
3869 | - } |
3870 | - |
3871 | - /* Internal references to python-land objects */ |
3872 | - if (!conv) |
3873 | - conv = PyDict_New(); |
3874 | - else |
3875 | - Py_INCREF(conv); |
3876 | - |
3877 | - if (!conv) |
3878 | - return -1; |
3879 | - self->converter = conv; |
3880 | - |
3881 | - /* |
3882 | - PyType_GenericAlloc() automatically sets up GC allocation and |
3883 | - tracking for GC objects, at least in 2.2.1, so it does not need to |
3884 | - be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(), |
3885 | - however. |
3886 | - */ |
3887 | - self->open = 1; |
3888 | - return 0; |
3889 | -} |
3890 | - |
3891 | -static char _mysql_connect__doc__[] = |
3892 | -"Returns a MYSQL connection object. Exclusive use of\n\ |
3893 | -keyword parameters strongly recommended. Consult the\n\ |
3894 | -MySQL C API documentation for more details.\n\ |
3895 | -\n\ |
3896 | -host\n\ |
3897 | - string, host to connect\n\ |
3898 | -\n\ |
3899 | -user\n\ |
3900 | - string, user to connect as\n\ |
3901 | -\n\ |
3902 | -passwd\n\ |
3903 | - string, password to use\n\ |
3904 | -\n\ |
3905 | -db\n\ |
3906 | - string, database to use\n\ |
3907 | -\n\ |
3908 | -port\n\ |
3909 | - integer, TCP/IP port to connect to\n\ |
3910 | -\n\ |
3911 | -unix_socket\n\ |
3912 | - string, location of unix_socket (UNIX-ish only)\n\ |
3913 | -\n\ |
3914 | -conv\n\ |
3915 | - mapping, maps MySQL FIELD_TYPE.* to Python functions which\n\ |
3916 | - convert a string to the appropriate Python type\n\ |
3917 | -\n\ |
3918 | -connect_timeout\n\ |
3919 | - number of seconds to wait before the connection\n\ |
3920 | - attempt fails.\n\ |
3921 | -\n\ |
3922 | -compress\n\ |
3923 | - if set, gzip compression is enabled\n\ |
3924 | -\n\ |
3925 | -named_pipe\n\ |
3926 | - if set, connect to server via named pipe (Windows only)\n\ |
3927 | -\n\ |
3928 | -init_command\n\ |
3929 | - command which is run once the connection is created\n\ |
3930 | -\n\ |
3931 | -read_default_file\n\ |
3932 | - see the MySQL documentation for mysql_options()\n\ |
3933 | -\n\ |
3934 | -read_default_group\n\ |
3935 | - see the MySQL documentation for mysql_options()\n\ |
3936 | -\n\ |
3937 | -client_flag\n\ |
3938 | - client flags from MySQLdb.constants.CLIENT\n\ |
3939 | -\n\ |
3940 | -load_infile\n\ |
3941 | - int, non-zero enables LOAD LOCAL INFILE, zero disables\n\ |
3942 | -\n\ |
3943 | -"; |
3944 | - |
3945 | -static PyObject * |
3946 | -_mysql_connect( |
3947 | - PyObject *self, |
3948 | - PyObject *args, |
3949 | - PyObject *kwargs) |
3950 | -{ |
3951 | - _mysql_ConnectionObject *c=NULL; |
3952 | - |
3953 | - c = MyAlloc(_mysql_ConnectionObject, _mysql_ConnectionObject_Type); |
3954 | - if (c == NULL) return NULL; |
3955 | - if (_mysql_ConnectionObject_Initialize(c, args, kwargs)) { |
3956 | - Py_DECREF(c); |
3957 | - c = NULL; |
3958 | - } |
3959 | - return (PyObject *) c; |
3960 | -} |
3961 | - |
3962 | -#if PY_VERSION_HEX >= 0x02020000 |
3963 | -static int _mysql_ConnectionObject_traverse( |
3964 | - _mysql_ConnectionObject *self, |
3965 | - visitproc visit, |
3966 | - void *arg) |
3967 | -{ |
3968 | - if (self->converter) |
3969 | - return visit(self->converter, arg); |
3970 | - return 0; |
3971 | -} |
3972 | -#endif |
3973 | - |
3974 | -static int _mysql_ConnectionObject_clear( |
3975 | - _mysql_ConnectionObject *self) |
3976 | -{ |
3977 | - Py_XDECREF(self->converter); |
3978 | - self->converter = NULL; |
3979 | - return 0; |
3980 | -} |
3981 | - |
3982 | -static char _mysql_ConnectionObject_close__doc__[] = |
3983 | -"Close the connection. No further activity possible."; |
3984 | - |
3985 | -static PyObject * |
3986 | -_mysql_ConnectionObject_close( |
3987 | - _mysql_ConnectionObject *self, |
3988 | - PyObject *args) |
3989 | -{ |
3990 | - if (args) { |
3991 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
3992 | - } |
3993 | - if (self->open) { |
3994 | - Py_BEGIN_ALLOW_THREADS |
3995 | - mysql_close(&(self->connection)); |
3996 | - Py_END_ALLOW_THREADS |
3997 | - self->open = 0; |
3998 | - } else { |
3999 | - PyErr_SetString(_mysql_ProgrammingError, |
4000 | - "closing a closed connection"); |
4001 | - return NULL; |
4002 | - } |
4003 | - _mysql_ConnectionObject_clear(self); |
4004 | - Py_INCREF(Py_None); |
4005 | - return Py_None; |
4006 | -} |
4007 | - |
4008 | -static char _mysql_ConnectionObject_affected_rows__doc__ [] = |
4009 | -"Return number of rows affected by the last query.\n\ |
4010 | -Non-standard. Use Cursor.rowcount.\n\ |
4011 | -"; |
4012 | - |
4013 | -static PyObject * |
4014 | -_mysql_ConnectionObject_affected_rows( |
4015 | - _mysql_ConnectionObject *self, |
4016 | - PyObject *args) |
4017 | -{ |
4018 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4019 | - check_connection(self); |
4020 | - return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection))); |
4021 | -} |
4022 | - |
4023 | -static char _mysql_debug__doc__[] = |
4024 | -"Does a DBUG_PUSH with the given string.\n\ |
4025 | -mysql_debug() uses the Fred Fish debug library.\n\ |
4026 | -To use this function, you must compile the client library to\n\ |
4027 | -support debugging.\n\ |
4028 | -"; |
4029 | -static PyObject * |
4030 | -_mysql_debug( |
4031 | - PyObject *self, |
4032 | - PyObject *args) |
4033 | -{ |
4034 | - char *debug; |
4035 | - if (!PyArg_ParseTuple(args, "s", &debug)) return NULL; |
4036 | - mysql_debug(debug); |
4037 | - Py_INCREF(Py_None); |
4038 | - return Py_None; |
4039 | -} |
4040 | - |
4041 | -static char _mysql_ConnectionObject_dump_debug_info__doc__[] = |
4042 | -"Instructs the server to write some debug information to the\n\ |
4043 | -log. The connected user must have the process privilege for\n\ |
4044 | -this to work. Non-standard.\n\ |
4045 | -"; |
4046 | - |
4047 | -static PyObject * |
4048 | -_mysql_ConnectionObject_dump_debug_info( |
4049 | - _mysql_ConnectionObject *self, |
4050 | - PyObject *args) |
4051 | -{ |
4052 | - int err; |
4053 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4054 | - check_connection(self); |
4055 | - Py_BEGIN_ALLOW_THREADS |
4056 | - err = mysql_dump_debug_info(&(self->connection)); |
4057 | - Py_END_ALLOW_THREADS |
4058 | - if (err) return _mysql_Exception(self); |
4059 | - Py_INCREF(Py_None); |
4060 | - return Py_None; |
4061 | -} |
4062 | - |
4063 | -static char _mysql_ConnectionObject_autocommit__doc__[] = |
4064 | -"Set the autocommit mode. True values enable; False value disable.\n\ |
4065 | -"; |
4066 | -static PyObject * |
4067 | -_mysql_ConnectionObject_autocommit( |
4068 | - _mysql_ConnectionObject *self, |
4069 | - PyObject *args) |
4070 | -{ |
4071 | - int flag, err; |
4072 | - if (!PyArg_ParseTuple(args, "i", &flag)) return NULL; |
4073 | - Py_BEGIN_ALLOW_THREADS |
4074 | -#if MYSQL_VERSION_ID >= 40100 |
4075 | - err = mysql_autocommit(&(self->connection), flag); |
4076 | -#else |
4077 | - { |
4078 | - char query[256]; |
4079 | - snprintf(query, 256, "SET AUTOCOMMIT=%d", flag); |
4080 | - err = mysql_query(&(self->connection), query); |
4081 | - } |
4082 | -#endif |
4083 | - Py_END_ALLOW_THREADS |
4084 | - if (err) return _mysql_Exception(self); |
4085 | - Py_INCREF(Py_None); |
4086 | - return Py_None; |
4087 | -} |
4088 | - |
4089 | -static char _mysql_ConnectionObject_commit__doc__[] = |
4090 | -"Commits the current transaction\n\ |
4091 | -"; |
4092 | -static PyObject * |
4093 | -_mysql_ConnectionObject_commit( |
4094 | - _mysql_ConnectionObject *self, |
4095 | - PyObject *args) |
4096 | -{ |
4097 | - int err; |
4098 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4099 | - Py_BEGIN_ALLOW_THREADS |
4100 | -#if MYSQL_VERSION_ID >= 40100 |
4101 | - err = mysql_commit(&(self->connection)); |
4102 | -#else |
4103 | - err = mysql_query(&(self->connection), "COMMIT"); |
4104 | -#endif |
4105 | - Py_END_ALLOW_THREADS |
4106 | - if (err) return _mysql_Exception(self); |
4107 | - Py_INCREF(Py_None); |
4108 | - return Py_None; |
4109 | -} |
4110 | - |
4111 | -static char _mysql_ConnectionObject_rollback__doc__[] = |
4112 | -"Rolls backs the current transaction\n\ |
4113 | -"; |
4114 | -static PyObject * |
4115 | -_mysql_ConnectionObject_rollback( |
4116 | - _mysql_ConnectionObject *self, |
4117 | - PyObject *args) |
4118 | -{ |
4119 | - int err; |
4120 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4121 | - Py_BEGIN_ALLOW_THREADS |
4122 | -#if MYSQL_VERSION_ID >= 40100 |
4123 | - err = mysql_rollback(&(self->connection)); |
4124 | -#else |
4125 | - err = mysql_query(&(self->connection), "ROLLBACK"); |
4126 | -#endif |
4127 | - Py_END_ALLOW_THREADS |
4128 | - if (err) return _mysql_Exception(self); |
4129 | - Py_INCREF(Py_None); |
4130 | - return Py_None; |
4131 | -} |
4132 | - |
4133 | -static char _mysql_ConnectionObject_next_result__doc__[] = |
4134 | -"If more query results exist, next_result() reads the next query\n\ |
4135 | -results and returns the status back to application.\n\ |
4136 | -\n\ |
4137 | -After calling next_result() the state of the connection is as if\n\ |
4138 | -you had called query() for the next query. This means that you can\n\ |
4139 | -now call store_result(), warning_count(), affected_rows()\n\ |
4140 | -, and so forth. \n\ |
4141 | -\n\ |
4142 | -Returns 0 if there are more results; -1 if there are no more results\n\ |
4143 | -\n\ |
4144 | -Non-standard.\n\ |
4145 | -"; |
4146 | -static PyObject * |
4147 | -_mysql_ConnectionObject_next_result( |
4148 | - _mysql_ConnectionObject *self, |
4149 | - PyObject *args) |
4150 | -{ |
4151 | - int err; |
4152 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4153 | - Py_BEGIN_ALLOW_THREADS |
4154 | -#if MYSQL_VERSION_ID >= 40100 |
4155 | - err = mysql_next_result(&(self->connection)); |
4156 | -#else |
4157 | - err = -1; |
4158 | -#endif |
4159 | - Py_END_ALLOW_THREADS |
4160 | - if (err > 0) return _mysql_Exception(self); |
4161 | - return PyInt_FromLong(err); |
4162 | -} |
4163 | - |
4164 | -#if MYSQL_VERSION_ID >= 40100 |
4165 | - |
4166 | -static char _mysql_ConnectionObject_set_server_option__doc__[] = |
4167 | -"set_server_option(option) -- Enables or disables an option\n\ |
4168 | -for the connection.\n\ |
4169 | -\n\ |
4170 | -Non-standard.\n\ |
4171 | -"; |
4172 | -static PyObject * |
4173 | -_mysql_ConnectionObject_set_server_option( |
4174 | - _mysql_ConnectionObject *self, |
4175 | - PyObject *args) |
4176 | -{ |
4177 | - int err, flags=0; |
4178 | - if (!PyArg_ParseTuple(args, "i", &flags)) |
4179 | - return NULL; |
4180 | - Py_BEGIN_ALLOW_THREADS |
4181 | - err = mysql_set_server_option(&(self->connection), flags); |
4182 | - Py_END_ALLOW_THREADS |
4183 | - if (err) return _mysql_Exception(self); |
4184 | - return PyInt_FromLong(err); |
4185 | -} |
4186 | - |
4187 | -static char _mysql_ConnectionObject_sqlstate__doc__[] = |
4188 | -"Returns a string containing the SQLSTATE error code\n\ |
4189 | -for the last error. The error code consists of five characters.\n\ |
4190 | -'00000' means \"no error.\" The values are specified by ANSI SQL\n\ |
4191 | -and ODBC. For a list of possible values, see section 23\n\ |
4192 | -Error Handling in MySQL in the MySQL Manual.\n\ |
4193 | -\n\ |
4194 | -Note that not all MySQL errors are yet mapped to SQLSTATE's.\n\ |
4195 | -The value 'HY000' (general error) is used for unmapped errors.\n\ |
4196 | -\n\ |
4197 | -Non-standard.\n\ |
4198 | -"; |
4199 | -static PyObject * |
4200 | -_mysql_ConnectionObject_sqlstate( |
4201 | - _mysql_ConnectionObject *self, |
4202 | - PyObject *args) |
4203 | -{ |
4204 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4205 | - return PyString_FromString(mysql_sqlstate(&(self->connection))); |
4206 | -} |
4207 | - |
4208 | -static char _mysql_ConnectionObject_warning_count__doc__[] = |
4209 | -"Returns the number of warnings generated during execution\n\ |
4210 | -of the previous SQL statement.\n\ |
4211 | -\n\ |
4212 | -Non-standard.\n\ |
4213 | -"; |
4214 | -static PyObject * |
4215 | -_mysql_ConnectionObject_warning_count( |
4216 | - _mysql_ConnectionObject *self, |
4217 | - PyObject *args) |
4218 | -{ |
4219 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4220 | - return PyInt_FromLong(mysql_warning_count(&(self->connection))); |
4221 | -} |
4222 | - |
4223 | -#endif |
4224 | - |
4225 | -static char _mysql_ConnectionObject_errno__doc__[] = |
4226 | -"Returns the error code for the most recently invoked API function\n\ |
4227 | -that can succeed or fail. A return value of zero means that no error\n\ |
4228 | -occurred.\n\ |
4229 | -"; |
4230 | - |
4231 | -static PyObject * |
4232 | -_mysql_ConnectionObject_errno( |
4233 | - _mysql_ConnectionObject *self, |
4234 | - PyObject *args) |
4235 | -{ |
4236 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4237 | - check_connection(self); |
4238 | - return PyInt_FromLong((long)mysql_errno(&(self->connection))); |
4239 | -} |
4240 | - |
4241 | -static char _mysql_ConnectionObject_error__doc__[] = |
4242 | -"Returns the error message for the most recently invoked API function\n\ |
4243 | -that can succeed or fail. An empty string ("") is returned if no error\n\ |
4244 | -occurred.\n\ |
4245 | -"; |
4246 | - |
4247 | -static PyObject * |
4248 | -_mysql_ConnectionObject_error( |
4249 | - _mysql_ConnectionObject *self, |
4250 | - PyObject *args) |
4251 | -{ |
4252 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4253 | - check_connection(self); |
4254 | - return PyString_FromString(mysql_error(&(self->connection))); |
4255 | -} |
4256 | - |
4257 | -static char _mysql_escape_string__doc__[] = |
4258 | -"escape_string(s) -- quote any SQL-interpreted characters in string s.\n\ |
4259 | -\n\ |
4260 | -Use connection.escape_string(s), if you use it at all.\n\ |
4261 | -_mysql.escape_string(s) cannot handle character sets. You are\n\ |
4262 | -probably better off using connection.escape(o) instead, since\n\ |
4263 | -it will escape entire sequences as well as strings."; |
4264 | - |
4265 | -static PyObject * |
4266 | -_mysql_escape_string( |
4267 | - _mysql_ConnectionObject *self, |
4268 | - PyObject *args) |
4269 | -{ |
4270 | - PyObject *str; |
4271 | - char *in, *out; |
4272 | - int len, size; |
4273 | - if (!PyArg_ParseTuple(args, "s#:escape_string", &in, &size)) return NULL; |
4274 | - str = PyString_FromStringAndSize((char *) NULL, size*2+1); |
4275 | - if (!str) return PyErr_NoMemory(); |
4276 | - out = PyString_AS_STRING(str); |
4277 | -#if MYSQL_VERSION_ID < 32321 |
4278 | - len = mysql_escape_string(out, in, size); |
4279 | -#else |
4280 | - check_server_init(NULL); |
4281 | - if (self && self->open) |
4282 | - len = mysql_real_escape_string(&(self->connection), out, in, size); |
4283 | - else |
4284 | - len = mysql_escape_string(out, in, size); |
4285 | -#endif |
4286 | - if (_PyString_Resize(&str, len) < 0) return NULL; |
4287 | - return (str); |
4288 | -} |
4289 | - |
4290 | -static char _mysql_string_literal__doc__[] = |
4291 | -"string_literal(obj) -- converts object obj into a SQL string literal.\n\ |
4292 | -This means, any special SQL characters are escaped, and it is enclosed\n\ |
4293 | -within single quotes. In other words, it performs:\n\ |
4294 | -\n\ |
4295 | -\"'%s'\" % escape_string(str(obj))\n\ |
4296 | -\n\ |
4297 | -Use connection.string_literal(obj), if you use it at all.\n\ |
4298 | -_mysql.string_literal(obj) cannot handle character sets."; |
4299 | - |
4300 | -static PyObject * |
4301 | -_mysql_string_literal( |
4302 | - _mysql_ConnectionObject *self, |
4303 | - PyObject *args) |
4304 | -{ |
4305 | - PyObject *str, *s, *o, *d; |
4306 | - char *in, *out; |
4307 | - int len, size; |
4308 | - if (!PyArg_ParseTuple(args, "O|O:string_literal", &o, &d)) return NULL; |
4309 | - s = PyObject_Str(o); |
4310 | - if (!s) return NULL; |
4311 | - in = PyString_AsString(s); |
4312 | - size = PyString_GET_SIZE(s); |
4313 | - str = PyString_FromStringAndSize((char *) NULL, size*2+3); |
4314 | - if (!str) return PyErr_NoMemory(); |
4315 | - out = PyString_AS_STRING(str); |
4316 | -#if MYSQL_VERSION_ID < 32321 |
4317 | - len = mysql_escape_string(out+1, in, size); |
4318 | -#else |
4319 | - check_server_init(NULL); |
4320 | - if (self && self->open) |
4321 | - len = mysql_real_escape_string(&(self->connection), out+1, in, size); |
4322 | - else |
4323 | - len = mysql_escape_string(out+1, in, size); |
4324 | -#endif |
4325 | - *out = *(out+len+1) = '\''; |
4326 | - if (_PyString_Resize(&str, len+2) < 0) return NULL; |
4327 | - Py_DECREF(s); |
4328 | - return (str); |
4329 | -} |
4330 | - |
4331 | -static PyObject *_mysql_NULL; |
4332 | - |
4333 | -static PyObject * |
4334 | -_escape_item( |
4335 | - PyObject *item, |
4336 | - PyObject *d) |
4337 | -{ |
4338 | - PyObject *quoted=NULL, *itemtype, *itemconv; |
4339 | - if (!(itemtype = PyObject_Type(item))) |
4340 | - goto error; |
4341 | - itemconv = PyObject_GetItem(d, itemtype); |
4342 | - Py_DECREF(itemtype); |
4343 | - if (!itemconv) { |
4344 | - PyErr_Clear(); |
4345 | - itemconv = PyObject_GetItem(d, |
4346 | - (PyObject *) &PyString_Type); |
4347 | - } |
4348 | - if (!itemconv) { |
4349 | - PyErr_SetString(PyExc_TypeError, |
4350 | - "no default type converter defined"); |
4351 | - goto error; |
4352 | - } |
4353 | - quoted = PyObject_CallFunction(itemconv, "OO", item, d); |
4354 | - Py_DECREF(itemconv); |
4355 | -error: |
4356 | - return quoted; |
4357 | -} |
4358 | - |
4359 | -static char _mysql_escape__doc__[] = |
4360 | -"escape(obj, dict) -- escape any special characters in object obj\n\ |
4361 | -using mapping dict to provide quoting functions for each type.\n\ |
4362 | -Returns a SQL literal string."; |
4363 | -static PyObject * |
4364 | -_mysql_escape( |
4365 | - PyObject *self, |
4366 | - PyObject *args) |
4367 | -{ |
4368 | - PyObject *o=NULL, *d=NULL; |
4369 | - if (!PyArg_ParseTuple(args, "O|O:escape", &o, &d)) |
4370 | - return NULL; |
4371 | - if (d) { |
4372 | - if (!PyMapping_Check(d)) { |
4373 | - PyErr_SetString(PyExc_TypeError, |
4374 | - "argument 2 must be a mapping"); |
4375 | - return NULL; |
4376 | - } |
4377 | - return _escape_item(o, d); |
4378 | - } else { |
4379 | - if (!self) { |
4380 | - PyErr_SetString(PyExc_TypeError, |
4381 | - "argument 2 must be a mapping"); |
4382 | - return NULL; |
4383 | - } |
4384 | - return _escape_item(o, |
4385 | - ((_mysql_ConnectionObject *) self)->converter); |
4386 | - } |
4387 | -} |
4388 | - |
4389 | -static char _mysql_escape_sequence__doc__[] = |
4390 | -"escape_sequence(seq, dict) -- escape any special characters in sequence\n\ |
4391 | -seq using mapping dict to provide quoting functions for each type.\n\ |
4392 | -Returns a tuple of escaped items."; |
4393 | -static PyObject * |
4394 | -_mysql_escape_sequence( |
4395 | - PyObject *self, |
4396 | - PyObject *args) |
4397 | -{ |
4398 | - PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted; |
4399 | - int i, n; |
4400 | - if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d)) |
4401 | - goto error; |
4402 | - if (!PyMapping_Check(d)) { |
4403 | - PyErr_SetString(PyExc_TypeError, |
4404 | - "argument 2 must be a mapping"); |
4405 | - return NULL; |
4406 | - } |
4407 | - if ((n = PyObject_Length(o)) == -1) goto error; |
4408 | - if (!(r = PyTuple_New(n))) goto error; |
4409 | - for (i=0; i<n; i++) { |
4410 | - item = PySequence_GetItem(o, i); |
4411 | - if (!item) goto error; |
4412 | - quoted = _escape_item(item, d); |
4413 | - Py_DECREF(item); |
4414 | - if (!quoted) goto error; |
4415 | - PyTuple_SET_ITEM(r, i, quoted); |
4416 | - } |
4417 | - return r; |
4418 | - error: |
4419 | - Py_XDECREF(r); |
4420 | - return NULL; |
4421 | -} |
4422 | - |
4423 | -static char _mysql_escape_dict__doc__[] = |
4424 | -"escape_sequence(d, dict) -- escape any special characters in\n\ |
4425 | -dictionary d using mapping dict to provide quoting functions for each type.\n\ |
4426 | -Returns a dictionary of escaped items."; |
4427 | -static PyObject * |
4428 | -_mysql_escape_dict( |
4429 | - PyObject *self, |
4430 | - PyObject *args) |
4431 | -{ |
4432 | - PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey; |
4433 | - Py_ssize_t ppos = 0; |
4434 | - if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d)) |
4435 | - goto error; |
4436 | - if (!PyMapping_Check(d)) { |
4437 | - PyErr_SetString(PyExc_TypeError, |
4438 | - "argument 2 must be a mapping"); |
4439 | - return NULL; |
4440 | - } |
4441 | - if (!(r = PyDict_New())) goto error; |
4442 | - while (PyDict_Next(o, &ppos, &pkey, &item)) { |
4443 | - quoted = _escape_item(item, d); |
4444 | - if (!quoted) goto error; |
4445 | - if (PyDict_SetItem(r, pkey, quoted)==-1) goto error; |
4446 | - Py_DECREF(quoted); |
4447 | - } |
4448 | - return r; |
4449 | - error: |
4450 | - Py_XDECREF(r); |
4451 | - return NULL; |
4452 | -} |
4453 | - |
4454 | -static char _mysql_ResultObject_describe__doc__[] = |
4455 | -"Returns the sequence of 7-tuples required by the DB-API for\n\ |
4456 | -the Cursor.description attribute.\n\ |
4457 | -"; |
4458 | - |
4459 | -static PyObject * |
4460 | -_mysql_ResultObject_describe( |
4461 | - _mysql_ResultObject *self, |
4462 | - PyObject *args) |
4463 | -{ |
4464 | - PyObject *d; |
4465 | - MYSQL_FIELD *fields; |
4466 | - unsigned int i, n; |
4467 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4468 | - check_result_connection(self); |
4469 | - n = mysql_num_fields(self->result); |
4470 | - fields = mysql_fetch_fields(self->result); |
4471 | - if (!(d = PyTuple_New(n))) return NULL; |
4472 | - for (i=0; i<n; i++) { |
4473 | - PyObject *t; |
4474 | - t = Py_BuildValue("(siiiiii)", |
4475 | - fields[i].name, |
4476 | - (long) fields[i].type, |
4477 | - (long) fields[i].max_length, |
4478 | - (long) fields[i].length, |
4479 | - (long) fields[i].length, |
4480 | - (long) fields[i].decimals, |
4481 | - (long) !(IS_NOT_NULL(fields[i].flags))); |
4482 | - if (!t) goto error; |
4483 | - PyTuple_SET_ITEM(d, i, t); |
4484 | - } |
4485 | - return d; |
4486 | - error: |
4487 | - Py_XDECREF(d); |
4488 | - return NULL; |
4489 | -} |
4490 | - |
4491 | -static char _mysql_ResultObject_field_flags__doc__[] = |
4492 | -"Returns a tuple of field flags, one for each column in the result.\n\ |
4493 | -" ; |
4494 | - |
4495 | -static PyObject * |
4496 | -_mysql_ResultObject_field_flags( |
4497 | - _mysql_ResultObject *self, |
4498 | - PyObject *args) |
4499 | -{ |
4500 | - PyObject *d; |
4501 | - MYSQL_FIELD *fields; |
4502 | - unsigned int i, n; |
4503 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4504 | - check_result_connection(self); |
4505 | - n = mysql_num_fields(self->result); |
4506 | - fields = mysql_fetch_fields(self->result); |
4507 | - if (!(d = PyTuple_New(n))) return NULL; |
4508 | - for (i=0; i<n; i++) { |
4509 | - PyObject *f; |
4510 | - if (!(f = PyInt_FromLong((long)fields[i].flags))) goto error; |
4511 | - PyTuple_SET_ITEM(d, i, f); |
4512 | - } |
4513 | - return d; |
4514 | - error: |
4515 | - Py_XDECREF(d); |
4516 | - return NULL; |
4517 | -} |
4518 | - |
4519 | -static PyObject * |
4520 | -_mysql_field_to_python( |
4521 | - PyObject *converter, |
4522 | - char *rowitem, |
4523 | - unsigned long length) |
4524 | -{ |
4525 | - PyObject *v; |
4526 | - if (rowitem) { |
4527 | - if (converter != Py_None) |
4528 | - v = PyObject_CallFunction(converter, |
4529 | - "s#", |
4530 | - rowitem, |
4531 | - (int)length); |
4532 | - else |
4533 | - v = PyString_FromStringAndSize(rowitem, |
4534 | - (int)length); |
4535 | - if (!v) |
4536 | - return NULL; |
4537 | - } else { |
4538 | - Py_INCREF(Py_None); |
4539 | - v = Py_None; |
4540 | - } |
4541 | - return v; |
4542 | -} |
4543 | - |
4544 | -static PyObject * |
4545 | -_mysql_row_to_tuple( |
4546 | - _mysql_ResultObject *self, |
4547 | - MYSQL_ROW row) |
4548 | -{ |
4549 | - unsigned int n, i; |
4550 | - unsigned long *length; |
4551 | - PyObject *r, *c; |
4552 | - |
4553 | - n = mysql_num_fields(self->result); |
4554 | - if (!(r = PyTuple_New(n))) return NULL; |
4555 | - length = mysql_fetch_lengths(self->result); |
4556 | - for (i=0; i<n; i++) { |
4557 | - PyObject *v; |
4558 | - c = PyTuple_GET_ITEM(self->converter, i); |
4559 | - v = _mysql_field_to_python(c, row[i], length[i]); |
4560 | - if (!v) goto error; |
4561 | - PyTuple_SET_ITEM(r, i, v); |
4562 | - } |
4563 | - return r; |
4564 | - error: |
4565 | - Py_XDECREF(r); |
4566 | - return NULL; |
4567 | -} |
4568 | - |
4569 | -static PyObject * |
4570 | -_mysql_row_to_dict( |
4571 | - _mysql_ResultObject *self, |
4572 | - MYSQL_ROW row) |
4573 | -{ |
4574 | - unsigned int n, i; |
4575 | - unsigned long *length; |
4576 | - PyObject *r, *c; |
4577 | - MYSQL_FIELD *fields; |
4578 | - |
4579 | - n = mysql_num_fields(self->result); |
4580 | - if (!(r = PyDict_New())) return NULL; |
4581 | - length = mysql_fetch_lengths(self->result); |
4582 | - fields = mysql_fetch_fields(self->result); |
4583 | - for (i=0; i<n; i++) { |
4584 | - PyObject *v; |
4585 | - c = PyTuple_GET_ITEM(self->converter, i); |
4586 | - v = _mysql_field_to_python(c, row[i], length[i]); |
4587 | - if (!v) goto error; |
4588 | - if (!PyMapping_HasKeyString(r, fields[i].name)) { |
4589 | - PyMapping_SetItemString(r, fields[i].name, v); |
4590 | - } else { |
4591 | - int len; |
4592 | - char buf[256]; |
4593 | - strncpy(buf, fields[i].table, 256); |
4594 | - len = strlen(buf); |
4595 | - strncat(buf, ".", 256-len); |
4596 | - len = strlen(buf); |
4597 | - strncat(buf, fields[i].name, 256-len); |
4598 | - PyMapping_SetItemString(r, buf, v); |
4599 | - } |
4600 | - Py_DECREF(v); |
4601 | - } |
4602 | - return r; |
4603 | - error: |
4604 | - Py_XDECREF(r); |
4605 | - return NULL; |
4606 | -} |
4607 | - |
4608 | -static PyObject * |
4609 | -_mysql_row_to_dict_old( |
4610 | - _mysql_ResultObject *self, |
4611 | - MYSQL_ROW row) |
4612 | -{ |
4613 | - unsigned int n, i; |
4614 | - unsigned long *length; |
4615 | - PyObject *r, *c; |
4616 | - MYSQL_FIELD *fields; |
4617 | - |
4618 | - n = mysql_num_fields(self->result); |
4619 | - if (!(r = PyDict_New())) return NULL; |
4620 | - length = mysql_fetch_lengths(self->result); |
4621 | - fields = mysql_fetch_fields(self->result); |
4622 | - for (i=0; i<n; i++) { |
4623 | - PyObject *v; |
4624 | - c = PyTuple_GET_ITEM(self->converter, i); |
4625 | - v = _mysql_field_to_python(c, row[i], length[i]); |
4626 | - if (!v) goto error; |
4627 | - { |
4628 | - int len=0; |
4629 | - char buf[256]=""; |
4630 | - if (strlen(fields[i].table)) { |
4631 | - strncpy(buf, fields[i].table, 256); |
4632 | - len = strlen(buf); |
4633 | - strncat(buf, ".", 256-len); |
4634 | - len = strlen(buf); |
4635 | - } |
4636 | - strncat(buf, fields[i].name, 256-len); |
4637 | - PyMapping_SetItemString(r, buf, v); |
4638 | - } |
4639 | - Py_DECREF(v); |
4640 | - } |
4641 | - return r; |
4642 | - error: |
4643 | - Py_XDECREF(r); |
4644 | - return NULL; |
4645 | -} |
4646 | - |
4647 | -typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW); |
4648 | - |
4649 | -int |
4650 | -_mysql__fetch_row( |
4651 | - _mysql_ResultObject *self, |
4652 | - PyObject **r, |
4653 | - int skiprows, |
4654 | - int maxrows, |
4655 | - _PYFUNC *convert_row) |
4656 | -{ |
4657 | - unsigned int i; |
4658 | - MYSQL_ROW row; |
4659 | - |
4660 | - for (i = skiprows; i<(skiprows+maxrows); i++) { |
4661 | - PyObject *v; |
4662 | - if (!self->use) |
4663 | - row = mysql_fetch_row(self->result); |
4664 | - else { |
4665 | - Py_BEGIN_ALLOW_THREADS; |
4666 | - row = mysql_fetch_row(self->result); |
4667 | - Py_END_ALLOW_THREADS; |
4668 | - } |
4669 | - if (!row && mysql_errno(&(((_mysql_ConnectionObject *)(self->conn))->connection))) { |
4670 | - _mysql_Exception((_mysql_ConnectionObject *)self->conn); |
4671 | - goto error; |
4672 | - } |
4673 | - if (!row) { |
4674 | - if (MyTuple_Resize(r, i, 0) == -1) goto error; |
4675 | - break; |
4676 | - } |
4677 | - v = convert_row(self, row); |
4678 | - if (!v) goto error; |
4679 | - PyTuple_SET_ITEM(*r, i, v); |
4680 | - } |
4681 | - return i-skiprows; |
4682 | - error: |
4683 | - return -1; |
4684 | -} |
4685 | - |
4686 | -static char _mysql_ResultObject_fetch_row__doc__[] = |
4687 | -"fetch_row([maxrows, how]) -- Fetches up to maxrows as a tuple.\n\ |
4688 | -The rows are formatted according to how:\n\ |
4689 | -\n\ |
4690 | - 0 -- tuples (default)\n\ |
4691 | - 1 -- dictionaries, key=column or table.column if duplicated\n\ |
4692 | - 2 -- dictionaries, key=table.column\n\ |
4693 | -"; |
4694 | - |
4695 | -static PyObject * |
4696 | -_mysql_ResultObject_fetch_row( |
4697 | - _mysql_ResultObject *self, |
4698 | - PyObject *args, |
4699 | - PyObject *kwargs) |
4700 | -{ |
4701 | - typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW); |
4702 | - static char *kwlist[] = { "maxrows", "how", NULL }; |
4703 | - static _PYFUNC *row_converters[] = |
4704 | - { |
4705 | - _mysql_row_to_tuple, |
4706 | - _mysql_row_to_dict, |
4707 | - _mysql_row_to_dict_old |
4708 | - }; |
4709 | - _PYFUNC *convert_row; |
4710 | - unsigned int maxrows=1, how=0, skiprows=0, rowsadded; |
4711 | - PyObject *r=NULL; |
4712 | - |
4713 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii:fetch_row", kwlist, |
4714 | - &maxrows, &how)) |
4715 | - return NULL; |
4716 | - check_result_connection(self); |
4717 | - if (how < 0 || how >= sizeof(row_converters)) { |
4718 | - PyErr_SetString(PyExc_ValueError, "how out of range"); |
4719 | - return NULL; |
4720 | - } |
4721 | - convert_row = row_converters[how]; |
4722 | - if (maxrows) { |
4723 | - if (!(r = PyTuple_New(maxrows))) goto error; |
4724 | - rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows, |
4725 | - convert_row); |
4726 | - if (rowsadded == -1) goto error; |
4727 | - } else { |
4728 | - if (self->use) { |
4729 | - maxrows = 1000; |
4730 | - if (!(r = PyTuple_New(maxrows))) goto error; |
4731 | - while (1) { |
4732 | - rowsadded = _mysql__fetch_row(self, &r, skiprows, |
4733 | - maxrows, convert_row); |
4734 | - if (rowsadded == -1) goto error; |
4735 | - skiprows += rowsadded; |
4736 | - if (rowsadded < maxrows) break; |
4737 | - if (MyTuple_Resize(&r, skiprows+maxrows, 0) == -1) |
4738 | - goto error; |
4739 | - } |
4740 | - } else { |
4741 | - /* XXX if overflow, maxrows<0? */ |
4742 | - maxrows = (int) mysql_num_rows(self->result); |
4743 | - if (!(r = PyTuple_New(maxrows))) goto error; |
4744 | - rowsadded = _mysql__fetch_row(self, &r, 0, |
4745 | - maxrows, convert_row); |
4746 | - if (rowsadded == -1) goto error; |
4747 | - } |
4748 | - } |
4749 | - return r; |
4750 | - error: |
4751 | - Py_XDECREF(r); |
4752 | - return NULL; |
4753 | -} |
4754 | - |
4755 | -#if MYSQL_VERSION_ID >= 32303 |
4756 | - |
4757 | -static char _mysql_ConnectionObject_change_user__doc__[] = |
4758 | -"Changes the user and causes the database specified by db to\n\ |
4759 | -become the default (current) database on the connection\n\ |
4760 | -specified by mysql. In subsequent queries, this database is\n\ |
4761 | -the default for table references that do not include an\n\ |
4762 | -explicit database specifier.\n\ |
4763 | -\n\ |
4764 | -This function was introduced in MySQL Version 3.23.3.\n\ |
4765 | -\n\ |
4766 | -Fails unless the connected user can be authenticated or if he\n\ |
4767 | -doesn't have permission to use the database. In this case the\n\ |
4768 | -user and database are not changed.\n\ |
4769 | -\n\ |
4770 | -The db parameter may be set to None if you don't want to have\n\ |
4771 | -a default database.\n\ |
4772 | -"; |
4773 | - |
4774 | -static PyObject * |
4775 | -_mysql_ConnectionObject_change_user( |
4776 | - _mysql_ConnectionObject *self, |
4777 | - PyObject *args, |
4778 | - PyObject *kwargs) |
4779 | -{ |
4780 | - char *user, *pwd=NULL, *db=NULL; |
4781 | - int r; |
4782 | - static char *kwlist[] = { "user", "passwd", "db", NULL } ; |
4783 | - |
4784 | - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ss:change_user", |
4785 | - kwlist, &user, &pwd, &db)) |
4786 | - return NULL; |
4787 | - check_connection(self); |
4788 | - Py_BEGIN_ALLOW_THREADS |
4789 | - r = mysql_change_user(&(self->connection), user, pwd, db); |
4790 | - Py_END_ALLOW_THREADS |
4791 | - if (r) return _mysql_Exception(self); |
4792 | - Py_INCREF(Py_None); |
4793 | - return Py_None; |
4794 | -} |
4795 | -#endif |
4796 | - |
4797 | -static char _mysql_ConnectionObject_character_set_name__doc__[] = |
4798 | -"Returns the default character set for the current connection.\n\ |
4799 | -Non-standard.\n\ |
4800 | -"; |
4801 | - |
4802 | -static PyObject * |
4803 | -_mysql_ConnectionObject_character_set_name( |
4804 | - _mysql_ConnectionObject *self, |
4805 | - PyObject *args) |
4806 | -{ |
4807 | - const char *s; |
4808 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4809 | - check_connection(self); |
4810 | -#if MYSQL_VERSION_ID >= 32321 |
4811 | - s = mysql_character_set_name(&(self->connection)); |
4812 | -#else |
4813 | - s = "latin1"; |
4814 | -#endif |
4815 | - return PyString_FromString(s); |
4816 | -} |
4817 | - |
4818 | -#if MYSQL_VERSION_ID >= 50007 |
4819 | -static char _mysql_ConnectionObject_set_character_set__doc__[] = |
4820 | -"Sets the default character set for the current connection.\n\ |
4821 | -Non-standard.\n\ |
4822 | -"; |
4823 | - |
4824 | -static PyObject * |
4825 | -_mysql_ConnectionObject_set_character_set( |
4826 | - _mysql_ConnectionObject *self, |
4827 | - PyObject *args) |
4828 | -{ |
4829 | - const char *s; |
4830 | - int err; |
4831 | - if (!PyArg_ParseTuple(args, "s", &s)) return NULL; |
4832 | - check_connection(self); |
4833 | - Py_BEGIN_ALLOW_THREADS |
4834 | - err = mysql_set_character_set(&(self->connection), s); |
4835 | - Py_END_ALLOW_THREADS |
4836 | - if (err) return _mysql_Exception(self); |
4837 | - Py_INCREF(Py_None); |
4838 | - return Py_None; |
4839 | -} |
4840 | -#endif |
4841 | - |
4842 | -#if MYSQL_VERSION_ID >= 50010 |
4843 | -static char _mysql_ConnectionObject_get_character_set_info__doc__[] = |
4844 | -"Returns a dict with information about the current character set:\n\ |
4845 | -\n\ |
4846 | -collation\n\ |
4847 | - collation name\n\ |
4848 | -name\n\ |
4849 | - character set name\n\ |
4850 | -comment\n\ |
4851 | - comment or descriptive name\n\ |
4852 | -dir\n\ |
4853 | - character set directory\n\ |
4854 | -mbminlen\n\ |
4855 | - min. length for multibyte string\n\ |
4856 | -mbmaxlen\n\ |
4857 | - max. length for multibyte string\n\ |
4858 | -\n\ |
4859 | -Not all keys may be present, particularly dir.\n\ |
4860 | -\n\ |
4861 | -Non-standard.\n\ |
4862 | -"; |
4863 | - |
4864 | -static PyObject * |
4865 | -_mysql_ConnectionObject_get_character_set_info( |
4866 | - _mysql_ConnectionObject *self, |
4867 | - PyObject *args) |
4868 | -{ |
4869 | - PyObject *result; |
4870 | - MY_CHARSET_INFO cs; |
4871 | - |
4872 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4873 | - check_connection(self); |
4874 | - mysql_get_character_set_info(&(self->connection), &cs); |
4875 | - if (!(result = PyDict_New())) return NULL; |
4876 | - if (cs.csname) |
4877 | - PyDict_SetItemString(result, "name", PyString_FromString(cs.csname)); |
4878 | - if (cs.name) |
4879 | - PyDict_SetItemString(result, "collation", PyString_FromString(cs.name)); |
4880 | - if (cs.comment) |
4881 | - PyDict_SetItemString(result, "comment", PyString_FromString(cs.comment)); |
4882 | - if (cs.dir) |
4883 | - PyDict_SetItemString(result, "dir", PyString_FromString(cs.dir)); |
4884 | - PyDict_SetItemString(result, "mbminlen", PyInt_FromLong(cs.mbminlen)); |
4885 | - PyDict_SetItemString(result, "mbmaxlen", PyInt_FromLong(cs.mbmaxlen)); |
4886 | - return result; |
4887 | -} |
4888 | -#endif |
4889 | - |
4890 | -static char _mysql_get_client_info__doc__[] = |
4891 | -"get_client_info() -- Returns a string that represents\n\ |
4892 | -the client library version."; |
4893 | -static PyObject * |
4894 | -_mysql_get_client_info( |
4895 | - PyObject *self, |
4896 | - PyObject *args) |
4897 | -{ |
4898 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4899 | - check_server_init(NULL); |
4900 | - return PyString_FromString(mysql_get_client_info()); |
4901 | -} |
4902 | - |
4903 | -static char _mysql_ConnectionObject_get_host_info__doc__[] = |
4904 | -"Returns a string that represents the MySQL client library\n\ |
4905 | -version. Non-standard.\n\ |
4906 | -"; |
4907 | - |
4908 | -static PyObject * |
4909 | -_mysql_ConnectionObject_get_host_info( |
4910 | - _mysql_ConnectionObject *self, |
4911 | - PyObject *args) |
4912 | -{ |
4913 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4914 | - check_connection(self); |
4915 | - return PyString_FromString(mysql_get_host_info(&(self->connection))); |
4916 | -} |
4917 | - |
4918 | -static char _mysql_ConnectionObject_get_proto_info__doc__[] = |
4919 | -"Returns an unsigned integer representing the protocol version\n\ |
4920 | -used by the current connection. Non-standard.\n\ |
4921 | -"; |
4922 | - |
4923 | -static PyObject * |
4924 | -_mysql_ConnectionObject_get_proto_info( |
4925 | - _mysql_ConnectionObject *self, |
4926 | - PyObject *args) |
4927 | -{ |
4928 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4929 | - check_connection(self); |
4930 | - return PyInt_FromLong((long)mysql_get_proto_info(&(self->connection))); |
4931 | -} |
4932 | - |
4933 | -static char _mysql_ConnectionObject_get_server_info__doc__[] = |
4934 | -"Returns a string that represents the server version number.\n\ |
4935 | -Non-standard.\n\ |
4936 | -"; |
4937 | - |
4938 | -static PyObject * |
4939 | -_mysql_ConnectionObject_get_server_info( |
4940 | - _mysql_ConnectionObject *self, |
4941 | - PyObject *args) |
4942 | -{ |
4943 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4944 | - check_connection(self); |
4945 | - return PyString_FromString(mysql_get_server_info(&(self->connection))); |
4946 | -} |
4947 | - |
4948 | -static char _mysql_ConnectionObject_info__doc__[] = |
4949 | -"Retrieves a string providing information about the most\n\ |
4950 | -recently executed query. Non-standard. Use messages or\n\ |
4951 | -Cursor.messages.\n\ |
4952 | -"; |
4953 | - |
4954 | -static PyObject * |
4955 | -_mysql_ConnectionObject_info( |
4956 | - _mysql_ConnectionObject *self, |
4957 | - PyObject *args) |
4958 | -{ |
4959 | - const char *s; |
4960 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4961 | - check_connection(self); |
4962 | - s = mysql_info(&(self->connection)); |
4963 | - if (s) return PyString_FromString(s); |
4964 | - Py_INCREF(Py_None); |
4965 | - return Py_None; |
4966 | -} |
4967 | - |
4968 | -static char _mysql_ConnectionObject_insert_id__doc__[] = |
4969 | -"Returns the ID generated for an AUTO_INCREMENT column by the previous\n\ |
4970 | -query. Use this function after you have performed an INSERT query into a\n\ |
4971 | -table that contains an AUTO_INCREMENT field.\n\ |
4972 | -\n\ |
4973 | -Note that this returns 0 if the previous query does not\n\ |
4974 | -generate an AUTO_INCREMENT value. If you need to save the value for\n\ |
4975 | -later, be sure to call this immediately after the query\n\ |
4976 | -that generates the value.\n\ |
4977 | -\n\ |
4978 | -The ID is updated after INSERT and UPDATE statements that generate\n\ |
4979 | -an AUTO_INCREMENT value or that set a column value to\n\ |
4980 | -LAST_INSERT_ID(expr). See section 6.3.5.2 Miscellaneous Functions\n\ |
4981 | -in the MySQL documentation.\n\ |
4982 | -\n\ |
4983 | -Also note that the value of the SQL LAST_INSERT_ID() function always\n\ |
4984 | -contains the most recently generated AUTO_INCREMENT value, and is not\n\ |
4985 | -reset between queries because the value of that function is maintained\n\ |
4986 | -in the server.\n\ |
4987 | -" ; |
4988 | - |
4989 | -static PyObject * |
4990 | -_mysql_ConnectionObject_insert_id( |
4991 | - _mysql_ConnectionObject *self, |
4992 | - PyObject *args) |
4993 | -{ |
4994 | - my_ulonglong r; |
4995 | - if (!PyArg_ParseTuple(args, "")) return NULL; |
4996 | - check_connection(self); |
4997 | - Py_BEGIN_ALLOW_THREADS |
4998 | - r = mysql_insert_id(&(self->connection)); |
4999 | - Py_END_ALLOW_THREADS |
5000 | - return PyLong_FromUnsignedLongLong(r); |
The diff has been truncated for viewing.
Hey David, it looks like 06_fix_ error_checking. patch was dropped in debian as well so if that's the only difference we might be able to sync this package over and drop our delta. What do you think?