diff --git a/MySQLdb/MySQLdb/__init__.py b/MySQLdb/MySQLdb/__init__.py index e17d2d8..f1f2bdd 100644 --- a/MySQLdb/MySQLdb/__init__.py +++ b/MySQLdb/MySQLdb/__init__.py @@ -66,8 +66,7 @@ DATETIME = TIMESTAMP ROWID = DBAPISet() def Binary(x): - from array import array - return array('c', x) + return str(x) def Connect(*args, **kwargs): """Factory function for connections.Connection.""" diff --git a/MySQLdb/MySQLdb/connections.py b/MySQLdb/MySQLdb/connections.py index 77949c7..21bd588 100644 --- a/MySQLdb/MySQLdb/connections.py +++ b/MySQLdb/MySQLdb/connections.py @@ -69,7 +69,7 @@ class Connection(_mysql.connection): conv conversion dictionary, see MySQLdb.converters - connect_time + connect_timeout number of seconds to wait before the connection attempt fails. @@ -195,9 +195,10 @@ class Connection(_mysql.connection): self.set_sql_mode(sql_mode) if use_unicode: - self.converter[FIELD_TYPE.STRING].insert(-1, (None, string_decoder)) - self.converter[FIELD_TYPE.VAR_STRING].insert(-1, (None, string_decoder)) - self.converter[FIELD_TYPE.BLOB].insert(-1, (None, string_decoder)) + self.converter[FIELD_TYPE.STRING].append((None, string_decoder)) + self.converter[FIELD_TYPE.VAR_STRING].append((None, string_decoder)) + self.converter[FIELD_TYPE.VARCHAR].append((None, string_decoder)) + self.converter[FIELD_TYPE.BLOB].append((None, string_decoder)) self.encoders[types.StringType] = string_literal self.encoders[types.UnicodeType] = unicode_literal diff --git a/MySQLdb/MySQLdb/constants/FIELD_TYPE.py b/MySQLdb/MySQLdb/constants/FIELD_TYPE.py index e72cf01..8a57b17 100644 --- a/MySQLdb/MySQLdb/constants/FIELD_TYPE.py +++ b/MySQLdb/MySQLdb/constants/FIELD_TYPE.py @@ -20,6 +20,8 @@ TIME = 11 DATETIME = 12 YEAR = 13 NEWDATE = 14 +VARCHAR = 15 +BIT = 16 NEWDECIMAL = 246 ENUM = 247 SET = 248 diff --git a/MySQLdb/MySQLdb/converters.py b/MySQLdb/MySQLdb/converters.py index 902b0a4..652417b 100644 --- a/MySQLdb/MySQLdb/converters.py +++ b/MySQLdb/MySQLdb/converters.py @@ -143,17 +143,18 @@ conversions = { FIELD_TYPE.TIME: TimeDelta_or_None, FIELD_TYPE.DATE: Date_or_None, FIELD_TYPE.BLOB: [ - (FLAG.BINARY, char_array), - (None, None), - ], + (FLAG.BINARY, str), + ], FIELD_TYPE.STRING: [ + (FLAG.BINARY, str), (FLAG.SET, Str2Set), - (None, None), - ], + ], FIELD_TYPE.VAR_STRING: [ - (FLAG.SET, Str2Set), - (None, None), - ], + (FLAG.BINARY, str), + ], + FIELD_TYPE.VARCHAR: [ + (FLAG.BINARY, str), + ], } try: diff --git a/MySQLdb/MySQLdb/cursors.py b/MySQLdb/MySQLdb/cursors.py index 0ee0955..789cfe2 100644 --- a/MySQLdb/MySQLdb/cursors.py +++ b/MySQLdb/MySQLdb/cursors.py @@ -34,7 +34,9 @@ class BaseCursor(object): from _mysql_exceptions import MySQLError, Warning, Error, InterfaceError, \ DatabaseError, DataError, OperationalError, IntegrityError, \ InternalError, ProgrammingError, NotSupportedError - + + _defer_warnings = False + def __init__(self, connection): from weakref import proxy @@ -143,7 +145,8 @@ class BaseCursor(object): del self.messages[:] db = self._get_db() charset = db.character_set_name() - query = query.encode(charset) + if isinstance(query, unicode): + query = query.encode(charset) if args is not None: query = query % db.literal(args) try: @@ -162,7 +165,7 @@ class BaseCursor(object): self.messages.append((exc, value)) self.errorhandler(self, exc, value) self._executed = query - self._warning_check() + if not self._defer_warnings: self._warning_check() return r def executemany(self, query, args): @@ -214,7 +217,7 @@ class BaseCursor(object): del tb self.errorhandler(self, exc, value) r = self._query(',\n'.join(q)) - self._warning_check() + if not self._defer_warnings: self._warning_check() return r def callproc(self, procname, args=()): @@ -253,7 +256,7 @@ class BaseCursor(object): for index, arg in enumerate(args): q = "SET @_%s_%d=%s" % (procname, index, db.literal(arg)) - if type(q) is UnicodeType: + if isinstance(q, unicode): q = q.encode(charset) self._query(q) self.nextset() @@ -264,7 +267,8 @@ class BaseCursor(object): if type(q) is UnicodeType: q = q.encode(charset) self._query(q) - self._warning_check() + self._executed = q + if not self._defer_warnings: self._warning_check() return args def _do_query(self, q): @@ -375,13 +379,17 @@ class CursorUseResultMixIn(object): close() the cursor before additional queries can be peformed on the connection.""" + _defer_warnings = True + def _get_result(self): return self._get_db().use_result() def fetchone(self): """Fetches a single row from the cursor.""" self._check_executed() r = self._fetch_row(1) - if not r: return None + if not r: + self._warning_check() + return None self.rownumber = self.rownumber + 1 return r[0] @@ -391,6 +399,8 @@ class CursorUseResultMixIn(object): self._check_executed() r = self._fetch_row(size or self.arraysize) self.rownumber = self.rownumber + len(r) + if not r: + self._warning_check() return r def fetchall(self): @@ -398,6 +408,7 @@ class CursorUseResultMixIn(object): self._check_executed() r = self._fetch_row(0) self.rownumber = self.rownumber + len(r) + self._warning_check() return r def __iter__(self): diff --git a/MySQLdb/MySQLdb/times.py b/MySQLdb/MySQLdb/times.py index 1664a76..bb1c75c 100644 --- a/MySQLdb/MySQLdb/times.py +++ b/MySQLdb/MySQLdb/times.py @@ -30,6 +30,12 @@ def TimestampFromTicks(ticks): format_TIME = format_DATE = str +def format_TIMEDELTA(v): + seconds = int(v.seconds) % 60 + minutes = int(v.seconds / 60) % 60 + hours = int(v.seconds / 3600) % 24 + return '%d %d:%d:%d' % (v.days, hours, minutes, seconds) + def format_TIMESTAMP(d): return d.strftime("%Y-%m-%d %H:%M:%S") @@ -80,7 +86,7 @@ def DateTime2literal(d, c): def DateTimeDelta2literal(d, c): """Format a DateTimeDelta object as a time.""" - return string_literal(format_TIME(d),c) + return string_literal(format_TIMEDELTA(d),c) def mysql_timestamp_converter(s): """Convert a MySQL TIMESTAMP to a Timestamp object.""" diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c index 3f7925a..11e5916 100644 --- a/MySQLdb/_mysql.c +++ b/MySQLdb/_mysql.c @@ -170,9 +170,15 @@ _mysql_Exception(_mysql_ConnectionObject *c) #ifdef ER_NO_REFERENCED_ROW case ER_NO_REFERENCED_ROW: #endif +#ifdef ER_NO_REFERENCED_ROW_2 + case ER_NO_REFERENCED_ROW_2: +#endif #ifdef ER_ROW_IS_REFERENCED case ER_ROW_IS_REFERENCED: #endif +#ifdef ER_ROW_IS_REFERENCED_2 + case ER_ROW_IS_REFERENCED_2: +#endif #ifdef ER_CANNOT_ADD_FOREIGN case ER_CANNOT_ADD_FOREIGN: #endif diff --git a/MySQLdb/metadata.cfg b/MySQLdb/metadata.cfg index 79bf4a2..a7553fd 100644 --- a/MySQLdb/metadata.cfg +++ b/MySQLdb/metadata.cfg @@ -1,6 +1,6 @@ [metadata] -version: 1.2.1_p2 -version_info: (1,2,1,'final',2) +version: 1.2.2b1 +version_info: (1,2,2,'beta',1) description: Python interface to MySQL long_description: ========================= diff --git a/MySQLdb/test_MySQLdb_capabilities.py b/MySQLdb/test_MySQLdb_capabilities.py index 52d078a..5a6871e 100644 --- a/MySQLdb/test_MySQLdb_capabilities.py +++ b/MySQLdb/test_MySQLdb_capabilities.py @@ -49,7 +49,7 @@ class test_MySQLdb(test_capabilities.DatabaseTest): self.check_data_integrity( ('col1 SET(%s)' % ','.join(["'%s'" % t for t in things]),), generator) - + def test_stored_procedures(self): db = self.connection c = self.cursor