Mercurial > p > mysql-python > mysqldb-2
annotate MySQLdb/connections.py @ 75:3b03cb566032 MySQLdb
More serious restructuring and cleaning, especially in the handling
of result sets. All tests pass.
author | adustman |
---|---|
date | Mon, 22 Feb 2010 03:56:44 +0000 |
parents | 80164eb2f090 |
children | 228a45771d14 |
rev | line source |
---|---|
0 | 1 """ |
14 | 2 MySQLdb Connections |
3 ------------------- | |
0 | 4 |
5 This module implements connections for MySQLdb. Presently there is | |
6 only one class: Connection. Others are unlikely. However, you might | |
7 want to make your own subclasses. In most cases, you will probably | |
8 override Connection.default_cursor with a non-standard Cursor class. | |
9 | |
10 """ | |
14 | 11 |
12 __revision__ = "$Revision$"[11:-2] | |
13 __author__ = "$Author$"[9:-2] | |
14 | |
0 | 15 |
16 def defaulterrorhandler(connection, cursor, errorclass, errorvalue): | |
17 """ | |
14 | 18 If cursor is not None, (errorclass, errorvalue) is appended to |
19 cursor.messages; otherwise it is appended to connection.messages. Then | |
20 errorclass is raised with errorvalue as the value. | |
0 | 21 |
14 | 22 You can override this with your own error handler by assigning it to the |
23 instance. | |
0 | 24 """ |
25 error = errorclass, errorvalue | |
26 if cursor: | |
27 cursor.messages.append(error) | |
28 else: | |
29 connection.messages.append(error) | |
30 del cursor | |
31 del connection | |
62 | 32 raise errorclass, errorvalue |
0 | 33 |
34 | |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
35 class Connection(object): |
0 | 36 |
37 """MySQL Database Connection Object""" | |
38 | |
14 | 39 errorhandler = defaulterrorhandler |
0 | 40 |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
41 from MySQLdb.exceptions import Warning, Error, InterfaceError, DataError, \ |
14 | 42 DatabaseError, OperationalError, IntegrityError, InternalError, \ |
43 NotSupportedError, ProgrammingError | |
44 | |
0 | 45 def __init__(self, *args, **kwargs): |
46 """ | |
14 | 47 Create a connection to the database. It is strongly recommended that |
48 you only use keyword parameters. Consult the MySQL C API documentation | |
49 for more information. | |
0 | 50 |
51 host | |
52 string, host to connect | |
53 | |
54 user | |
55 string, user to connect as | |
56 | |
57 passwd | |
58 string, password to use | |
59 | |
60 db | |
61 string, database to use | |
62 | |
63 port | |
64 integer, TCP/IP port to connect to | |
65 | |
66 unix_socket | |
67 string, location of unix_socket to use | |
68 | |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
69 decoders |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
70 list, SQL decoder stack |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
71 |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
72 encoders |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
73 list, SQL encoder stack |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
74 |
4 | 75 connect_timeout |
0 | 76 number of seconds to wait before the connection attempt |
77 fails. | |
78 | |
79 compress | |
80 if set, compression is enabled | |
81 | |
82 named_pipe | |
83 if set, a named pipe is used to connect (Windows only) | |
84 | |
85 init_command | |
86 command which is run once the connection is created | |
87 | |
88 read_default_file | |
89 file from which default client values are read | |
90 | |
91 read_default_group | |
92 configuration group to use from the default file | |
93 | |
94 use_unicode | |
95 If True, text-like columns are returned as unicode objects | |
96 using the connection's character set. Otherwise, text-like | |
97 columns are returned as strings. columns are returned as | |
98 normal strings. Unicode objects will always be encoded to | |
99 the connection's character set regardless of this setting. | |
100 | |
101 charset | |
102 If supplied, the connection character set will be changed | |
103 to this character set (MySQL-4.1 and newer). This implies | |
104 use_unicode=True. | |
105 | |
106 sql_mode | |
107 If supplied, the session SQL mode will be changed to this | |
108 setting (MySQL-4.1 and newer). For more details and legal | |
109 values, see the MySQL documentation. | |
110 | |
111 client_flag | |
112 integer, flags to use or 0 | |
113 (see MySQL docs or constants/CLIENTS.py) | |
114 | |
115 ssl | |
116 dictionary or mapping, contains SSL connection parameters; | |
117 see the MySQL documentation for more details | |
118 (mysql_ssl_set()). If this is set, and the client does not | |
1 | 119 support SSL, NotSupportedError will be raised. |
0 | 120 |
121 local_infile | |
122 integer, non-zero enables LOAD LOCAL INFILE; zero disables | |
123 | |
124 There are a number of undocumented, non-standard methods. See the | |
125 documentation for the MySQL C API for some hints on what they do. | |
126 | |
127 """ | |
14 | 128 from MySQLdb.constants import CLIENT, FIELD_TYPE |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
129 from MySQLdb.converters import default_decoders, default_encoders, default_row_formatter |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
130 from MySQLdb.cursors import Cursor |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
131 import _mysql |
46
4093fb968cb7
Bring back conversions for the time being, until we can get trunk actually
kylev
parents:
35
diff
changeset
|
132 |
0 | 133 kwargs2 = kwargs.copy() |
22
597efa4e0311
Trivial patch for dict.has_key() being deprecated going forward.
kylev
parents:
18
diff
changeset
|
134 |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
135 self.cursorclass = Cursor |
0 | 136 charset = kwargs2.pop('charset', '') |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
137 |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
138 self.encoders = kwargs2.pop('encoders', default_encoders) |
74
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
139 self.decoders = kwargs2.pop('decoders', default_decoders) |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
140 self.row_formatter = kwargs2.pop('row_formatter', default_row_formatter) |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
141 |
0 | 142 client_flag = kwargs.get('client_flag', 0) |
14 | 143 client_version = tuple( |
144 [ int(n) for n in _mysql.get_client_info().split('.')[:2] ]) | |
0 | 145 if client_version >= (4, 1): |
146 client_flag |= CLIENT.MULTI_STATEMENTS | |
147 if client_version >= (5, 0): | |
148 client_flag |= CLIENT.MULTI_RESULTS | |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
149 |
0 | 150 kwargs2['client_flag'] = client_flag |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
151 |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
152 sql_mode = kwargs2.pop('sql_mode', None) |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
153 |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
154 self._db = _mysql.connection(*args, **kwargs2) |
0 | 155 |
14 | 156 self._server_version = tuple( |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
157 [ int(n) for n in self._db.get_server_info().split('.')[:2] ]) |
0 | 158 |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
159 if charset: |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
160 self._db.set_character_set(charset) |
0 | 161 |
162 if sql_mode: | |
163 self.set_sql_mode(sql_mode) | |
164 | |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
165 self._transactional = bool(self._db.server_capabilities & CLIENT.TRANSACTIONS) |
0 | 166 if self._transactional: |
167 # PEP-249 requires autocommit to be initially off | |
168 self.autocommit(False) | |
169 self.messages = [] | |
74
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
170 self._active_cursor = None |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
171 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
172 def autocommit(self, do_autocommit): |
72 | 173 self._autocommit = do_autocommit |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
174 return self._db.autocommit(do_autocommit) |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
175 |
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
176 def ping(self, reconnect=False): |
72 | 177 if reconnect and not self._autocommit: |
178 raise ProgrammingError("autocommit must be enabled before enabling auto-reconnect; consider the consequences") | |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
179 return self._db.ping(reconnect) |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
180 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
181 def commit(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
182 return self._db.commit() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
183 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
184 def rollback(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
185 return self._db.rollback() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
186 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
187 def close(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
188 return self._db.close() |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
189 |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
190 def escape_string(self, s): |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
191 return self._db.escape_string(s) |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
192 |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
193 def string_literal(self, s): |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
194 return self._db.string_literal(s) |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
195 |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
196 def cursor(self, encoders=None, decoders=None, row_formatter=None): |
0 | 197 """ |
14 | 198 Create a cursor on which queries may be performed. The optional |
199 cursorclass parameter is used to create the Cursor. By default, | |
200 self.cursorclass=cursors.Cursor is used. | |
0 | 201 """ |
74
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
202 if self._active_cursor: |
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
203 self._active_cursor._flush() |
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
204 |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
205 if not encoders: |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
206 encoders = self.encoders[:] |
64
2d6a35051f64
Cursor MixIns: DEAD. More of the new type conversion scheme exposed. Two tests failing because encoding hasn't been finished yet.
adustman
parents:
62
diff
changeset
|
207 |
74
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
208 if not decoders: |
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
209 decoders = self.decoders[:] |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
210 |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
211 if not row_formatter: |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
212 row_formatter = self.row_formatter |
74
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
213 |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
214 self._active_cursor = self.cursorclass(self, encoders, decoders, row_formatter) |
74
80164eb2f090
This passes all test, yet is still broken and ugly in many ways.
adustman
parents:
72
diff
changeset
|
215 return self._active_cursor |
0 | 216 |
14 | 217 def __enter__(self): |
218 return self.cursor() | |
9
0e37ee00beb7
Merge changes from 1.2 branch (r470:483): Mostly build-related.
adustman
parents:
5
diff
changeset
|
219 |
14 | 220 def __exit__(self, exc, value, traceback): |
9
0e37ee00beb7
Merge changes from 1.2 branch (r470:483): Mostly build-related.
adustman
parents:
5
diff
changeset
|
221 if exc: |
0e37ee00beb7
Merge changes from 1.2 branch (r470:483): Mostly build-related.
adustman
parents:
5
diff
changeset
|
222 self.rollback() |
0e37ee00beb7
Merge changes from 1.2 branch (r470:483): Mostly build-related.
adustman
parents:
5
diff
changeset
|
223 else: |
0e37ee00beb7
Merge changes from 1.2 branch (r470:483): Mostly build-related.
adustman
parents:
5
diff
changeset
|
224 self.commit() |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
225 |
14 | 226 def literal(self, obj): |
0 | 227 """ |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
228 Given an object obj, returns an SQL literal as a string. |
0 | 229 |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
230 Non-standard. |
14 | 231 """ |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
232 for encoder in self.encoders: |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
233 f = encoder(obj) |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
234 if f: |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
235 return f(self, obj) |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
236 |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
64
diff
changeset
|
237 raise self.NotSupportedError("could not encode as SQL", obj) |
0 | 238 |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
239 def character_set_name(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
240 return self._db.character_set_name() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
241 |
0 | 242 def set_character_set(self, charset): |
14 | 243 """Set the connection character set to charset. The character set can |
244 only be changed in MySQL-4.1 and newer. If you try to change the | |
245 character set from the current value in an older version, | |
15 | 246 NotSupportedError will be raised. |
247 | |
248 Non-standard. It is better to set the character set when creating the | |
249 connection using the charset parameter.""" | |
1 | 250 if self.character_set_name() != charset: |
251 try: | |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
252 self._db.set_character_set(charset) |
1 | 253 except AttributeError: |
254 if self._server_version < (4, 1): | |
35
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
22
diff
changeset
|
255 raise self.NotSupportedError("server is too old to set charset") |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
256 self._db.query('SET NAMES %s' % charset) |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
257 self._db.get_result() |
0 | 258 |
259 def set_sql_mode(self, sql_mode): | |
14 | 260 """Set the connection sql_mode. See MySQL documentation for legal |
15 | 261 values. |
262 | |
263 Non-standard. It is better to set this when creating the connection | |
264 using the sql_mode parameter.""" | |
0 | 265 if self._server_version < (4, 1): |
35
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
22
diff
changeset
|
266 raise self.NotSupportedError("server is too old to set sql_mode") |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
267 self._db.query("SET SESSION sql_mode='%s'" % sql_mode) |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
268 self._db.get_result() |
0 | 269 |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
270 def _warning_count(self): |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
271 """Return the number of warnings generated from the last query.""" |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
272 if hasattr(self._db, "warning_count"): |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
273 return self._db.warning_count() |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
274 else: |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
275 info = self._db.info() |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
276 if info: |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
277 return int(info.split()[-1]) |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
278 else: |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
279 return 0 |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
280 |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
281 def _show_warnings(self): |
14 | 282 """Return detailed information about warnings as a sequence of tuples |
283 of (Level, Code, Message). This is only supported in MySQL-4.1 and up. | |
15 | 284 If your server is an earlier version, an empty sequence is returned. |
285 | |
286 Non-standard. This is invoked automatically after executing a query, | |
287 so you should not usually call it yourself.""" | |
14 | 288 if self._server_version < (4, 1): return () |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
15
diff
changeset
|
289 self._db.query("SHOW WARNINGS") |
75
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
290 return tuple(self._db.get_result()) |
3b03cb566032
More serious restructuring and cleaning, especially in the handling
adustman
parents:
74
diff
changeset
|
291 |
0 | 292 |