diff --git a/MySQLdb/MySQLdb/connections.py b/MySQLdb/MySQLdb/connections.py index e47e45d..04307ec 100644 --- a/MySQLdb/MySQLdb/connections.py +++ b/MySQLdb/MySQLdb/connections.py @@ -253,7 +253,7 @@ class Connection(_mysql.connection): self.query("SHOW WARNINGS") r = self.store_result() warnings = r.fetch_row(0) - return [ (level.tostring(), int(code), message.tostring()) + return [ (level, code, message) for level, code, message in warnings ] Warning = Warning diff --git a/MySQLdb/MySQLdb/cursors.py b/MySQLdb/MySQLdb/cursors.py index e0c37f7..9d8433e 100644 --- a/MySQLdb/MySQLdb/cursors.py +++ b/MySQLdb/MySQLdb/cursors.py @@ -16,10 +16,20 @@ class BaseCursor(object): """A base for Cursor classes. Useful attributes: - description -- DB API 7-tuple describing columns in last query - arraysize -- default number of rows fetchmany() will fetch + description + A tuple of DB API 7-tuples describing the columns in + the last executed query; see PEP-249 for details. + + description_flags + Tuple of column flags for last query, one entry per column + in the result set. Values correspond to those in + MySQLdb.constants.FLAG. See MySQL documentation (C API) + for more information. Non-standard extension. - See the MySQL docs for more information.""" + arraysize + default number of rows fetchmany() will fetch + + """ from _mysql_exceptions import MySQLError, Warning, Error, InterfaceError, \ DatabaseError, DataError, OperationalError, IntegrityError, \ @@ -28,6 +38,7 @@ class BaseCursor(object): def __init__(self, connection): self.connection = connection self.description = None + self.description_flags = None self.rowcount = -1 self.arraysize = 1 self._executed = None @@ -95,6 +106,7 @@ class BaseCursor(object): self.rowcount = db.affected_rows() self.rownumber = 0 self.description = self._result and self._result.describe() or None + self.description_flags = self._result and self._result.field_flags() or None self.lastrowid = db.insert_id() self._warnings = db.warning_count() self._info = db.info() diff --git a/MySQLdb/metadata.cfg b/MySQLdb/metadata.cfg index a15e6ce..ef2a13a 100644 --- a/MySQLdb/metadata.cfg +++ b/MySQLdb/metadata.cfg @@ -1,6 +1,6 @@ [metadata] -version: 1.2.1c6 -version_info: (1,2,1,'gamma',6) +version: 1.2.1c7 +version_info: (1,2,1,'gamma',7) description: Python interface to MySQL long_description: ========================= diff --git a/MySQLdb/setup.cfg b/MySQLdb/setup.cfg index e5b5642..b543bba 100644 --- a/MySQLdb/setup.cfg +++ b/MySQLdb/setup.cfg @@ -1,7 +1,7 @@ [bdist_rpm] -doc_files = README doc/*.html doc/*.txt doc/*.css doc/private doc/public ChangeLog +doc_files = README doc/*.txt ChangeLog vendor = MySQL-python SourceForge Project packager = Andy Dustman distribution-name = Red Hat Linux requires = python -build-requires = python-devel mysql-devel zlib-devel +build-requires = python-devel mysql-devel zlib-devel openssl-devel diff --git a/MySQLdb/setup.py b/MySQLdb/setup.py index 64cfaae..8569132 100644 --- a/MySQLdb/setup.py +++ b/MySQLdb/setup.py @@ -31,7 +31,7 @@ def mysql_config(what): # of mysql_config def dequote(s): - if (s[0] == "'" or s[0] == '"') and (s[0] == s[-1]): + if s[0] in "\"'" and s[0] == s[-1]: s = s[1:-1] return s @@ -45,10 +45,6 @@ def enabled(option): else: raise Abort, "Unknown value %s for option %s" % (value, option) -include_dirs = [ dequote(i[2:]) - for i in mysql_config('include') - if i.startswith('-i') ] - extra_objects = [] static = enabled('static') if enabled('embedded'): @@ -69,7 +65,16 @@ metadata['name'] = name library_dirs = [ dequote(i[2:]) for i in libs if i.startswith("-L") ] libraries = [ dequote(i[2:]) for i in libs if i.startswith("-l") ] -extra_compile_args = mysql_config("cflags") +removable_compile_args = '-I -L -l'.split() +extra_compile_args = [ i for i in mysql_config("cflags") + if i[:2] not in removable_compile_args ] +include_dirs = [ dequote(i[2:]) + for i in mysql_config('include') + if i.startswith('-I') ] +if not include_dirs: # fix for MySQL-3.23 + include_dirs = [ dequote(i[2:]) + for i in mysql_config('cflags') + if i.startswith('-I') ] if static: extra_objects.append(os.path.join( diff --git a/MySQLdb/test_capabilities.py b/MySQLdb/test_capabilities.py index 6b9bf35..0bf3144 100644 --- a/MySQLdb/test_capabilities.py +++ b/MySQLdb/test_capabilities.py @@ -97,11 +97,9 @@ class DatabaseTest(unittest.TestCase): insert_statement = ('INSERT INTO %s VALUES (%s)' % (self.table, ','.join(['%s'] * len(columndefs)))) - for i in range(self.rows): - data = [] - for j in range(len(columndefs)): - data.append(generator(i,j)) - self.cursor.execute(insert_statement,tuple(data)) + data = [ [ generator(i,j) for j in range(len(columndefs)) ] + for i in range(self.rows) ] + self.cursor.executemany(insert_statement, data) # verify self.connection.commit() self.cursor.execute('select * from %s' % self.table) @@ -123,6 +121,50 @@ class DatabaseTest(unittest.TestCase): self.failUnless(len(l) == 1, "ROLLBACK didn't work") self.cursor.execute('drop table %s' % (self.table)) + def test_truncation(self): + columndefs = ( 'col1 INT', 'col2 VARCHAR(255)') + def generator(row, col): + if col == 0: return row + else: return ('%i' % (row%10))*((255-self.rows/2)+row) + self.create_table(columndefs) + insert_statement = ('INSERT INTO %s VALUES (%s)' % + (self.table, + ','.join(['%s'] * len(columndefs)))) + + try: + self.cursor.execute(insert_statement, (0, '0'*256)) + except Warning: + if self.debug: print self.cursor.messages + else: + self.fail("Over-long column did not generate warnings with single insert") + + self.connection.rollback() + + try: + for i in range(self.rows): + data = [] + for j in range(len(columndefs)): + data.append(generator(i,j)) + self.cursor.execute(insert_statement,tuple(data)) + except Warning: + if self.debug: print self.cursor.messages + else: + self.fail("Over-long columns did not generate warnings with execute()") + + self.connection.rollback() + + try: + data = [ [ generator(i,j) for j in range(len(columndefs)) ] + for i in range(self.rows) ] + self.cursor.executemany(insert_statement, data) + except Warning: + if self.debug: print self.cursor.messages + else: + self.fail("Over-long columns did not generate warnings with executemany()") + + self.connection.rollback() + self.cursor.execute('drop table %s' % (self.table)) + def test_CHAR(self): # Character data def generator(row,col):