Mercurial > p > mysql-python > mysqldb-2
comparison MySQLdb/cursors.py @ 5:b70cce9bd065 MySQLdb
Merge changes from 1.2 branch r456-468
author | adustman |
---|---|
date | Sun, 11 Feb 2007 04:37:29 +0000 |
parents | b5a377255eea |
children | fa8974a41c76 |
comparison
equal
deleted
inserted
replaced
4:b5a377255eea | 5:b70cce9bd065 |
---|---|
4 default, MySQLdb uses the Cursor class. | 4 default, MySQLdb uses the Cursor class. |
5 | 5 |
6 """ | 6 """ |
7 | 7 |
8 import re | 8 import re |
9 insert_values = re.compile(r'\svalues\s*(\(.+\))', re.IGNORECASE) | 9 insert_values = re.compile(r"\svalues\s*(\(((?<!\\)'.*?\).*(?<!\\)?'|.)+?\))", re.IGNORECASE) |
10 from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \ | 10 from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \ |
11 DatabaseError, OperationalError, IntegrityError, InternalError, \ | 11 DatabaseError, OperationalError, IntegrityError, InternalError, \ |
12 NotSupportedError, ProgrammingError | 12 NotSupportedError, ProgrammingError |
13 | 13 |
14 | 14 |
187 | 187 |
188 """ | 188 """ |
189 del self.messages[:] | 189 del self.messages[:] |
190 db = self._get_db() | 190 db = self._get_db() |
191 if not args: return | 191 if not args: return |
192 charset = db.character_set_name() | |
193 if isinstance(query, unicode): query = query.encode(charset) | |
192 m = insert_values.search(query) | 194 m = insert_values.search(query) |
193 if not m: | 195 if not m: |
194 r = 0 | 196 r = 0 |
195 for a in args: | 197 for a in args: |
196 r = r + self.execute(query, a) | 198 r = r + self.execute(query, a) |
197 return r | 199 return r |
198 p = m.start(1) | 200 p = m.start(1) |
199 charset = db.character_set_name() | 201 e = m.end(1) |
200 query = query.encode(charset) | 202 qv = m.group(1) |
201 qv = query[p:] | |
202 qargs = db.literal(args) | 203 qargs = db.literal(args) |
203 try: | 204 try: |
204 q = [ query % qargs[0] ] | 205 q = [ qv % a for a in qargs ] |
205 q.extend([ qv % a for a in qargs[1:] ]) | |
206 except TypeError, msg: | 206 except TypeError, msg: |
207 if msg.args[0] in ("not enough arguments for format string", | 207 if msg.args[0] in ("not enough arguments for format string", |
208 "not all arguments converted"): | 208 "not all arguments converted"): |
209 self.messages.append((ProgrammingError, msg.args[0])) | 209 self.messages.append((ProgrammingError, msg.args[0])) |
210 self.errorhandler(self, ProgrammingError, msg.args[0]) | 210 self.errorhandler(self, ProgrammingError, msg.args[0]) |
214 except: | 214 except: |
215 from sys import exc_info | 215 from sys import exc_info |
216 exc, value, tb = exc_info() | 216 exc, value, tb = exc_info() |
217 del tb | 217 del tb |
218 self.errorhandler(self, exc, value) | 218 self.errorhandler(self, exc, value) |
219 r = self._query(',\n'.join(q)) | 219 r = self._query('\n'.join([query[:p], ',\n'.join(q), query[e:]])) |
220 if not self._defer_warnings: self._warning_check() | 220 if not self._defer_warnings: self._warning_check() |
221 return r | 221 return r |
222 | 222 |
223 def callproc(self, procname, args=()): | 223 def callproc(self, procname, args=()): |
224 | 224 |