Mercurial > p > mysql-python > mysqldb-2
diff MySQLdb/cursors.py @ 67:98d968f5af11 MySQLdb
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.
author | adustman |
---|---|
date | Mon, 30 Mar 2009 20:21:24 +0000 |
parents | 5a7c30cd9de2 |
children | 29b4cfd9af07 |
line wrap: on
line diff
--- a/MySQLdb/cursors.py Sun Mar 29 16:26:30 2009 +0000 +++ b/MySQLdb/cursors.py Mon Mar 30 20:21:24 2009 +0000 @@ -45,7 +45,7 @@ _defer_warnings = False _fetch_type = None - def __init__(self, connection, decoders, encoders): + def __init__(self, connection, encoders): from MySQLdb.converters import default_decoders self.connection = weakref.proxy(connection) self.description = None @@ -60,7 +60,7 @@ self._warnings = 0 self._info = None self.rownumber = None - self._decoders = decoders + self._encoders = encoders def __del__(self): self.close() @@ -117,25 +117,10 @@ self._warning_check() return True - def _lookup_decoder(self, field): - from MySQLdb.converters import filter_NULL - for plugin in self._decoders: - f = plugin(field) - if f: - return filter_NULL(f) - return None # this should never happen - def _do_get_result(self): """Get the result from the last query.""" connection = self._get_db() self._result = self._get_result() - if self._result: - self.sql_to_python = [ - self._lookup_decoder(f) - for f in self._result.fields() - ] - else: - self.sql_to_python = [] self.rowcount = connection.affected_rows() self.rownumber = 0 self.description = self._result and self._result.describe() or None @@ -176,9 +161,9 @@ charset = db.character_set_name() if isinstance(query, unicode): query = query.encode(charset) - if args is not None: - query = query % self.connection.literal(args) try: + if args is not None: + query = query % tuple(map(self.connection.literal, args)) result = self._query(query) except TypeError, msg: if msg.args[0] in ("not enough arguments for format string", @@ -235,7 +220,11 @@ values = matched.group('values') try: - sql_params = [ values % self.connection.literal(arg) for arg in args ] + sql_params = ( values % tuple(map(self.connection.literal, row)) for row in args ) + multirow_query = '\n'.join([start, ',\n'.join(sql_params), end]) + self._executed = multirow_query + self.rowcount = int(self._query(multirow_query)) + except TypeError, msg: if msg.args[0] in ("not enough arguments for format string", "not all arguments converted"): @@ -248,9 +237,7 @@ exc, value, traceback = sys.exc_info() del traceback self.errorhandler(self, exc, value) - self.rowcount = int(self._query( - '\n'.join([start, ',\n'.join(sql_params), end, - ]))) + if not self._defer_warnings: self._warning_check() return self.rowcount @@ -319,14 +306,7 @@ """Low-level fetch_row wrapper.""" if not self._result: return () - # unfortunately it is necessary to wrap these generators up as tuples - # as the rows are expected to be subscriptable. - return tuple( - ( - tuple( ( f(x) for f, x in zip(self.sql_to_python, row) ) ) - for row in self._result.fetch_row(size, self._fetch_type) - ) - ) + return self._result.fetch_row(size, self._fetch_type) def __iter__(self): return iter(self.fetchone, None)