]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
rowcount doesnt work on MySQL, so disabled concurrency check with mysql
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Nov 2005 05:32:13 +0000 (05:32 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Nov 2005 05:32:13 +0000 (05:32 +0000)
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/engine.py
lib/sqlalchemy/mapper.py

index bf1b19575cf4d31964f9d3af73877896c823a51e..e7f64c9b4d19aa91dac322a73c42913136b8f252 100644 (file)
@@ -108,8 +108,15 @@ class MySQLEngine(ansisql.ANSISQLEngine):
 
     def rowid_column_name(self):
         """returns the ROWID column name for this engine."""
+        
+        # well, for MySQL cant really count on this being there, surprise (not).
+        # so we do some silly hack down below in MySQLTableImpl to provide
+        # something for an OID column
         return "_rowid"
 
+    def supports_sane_rowcount(self):
+        return False
+
     def tableimpl(self, table):
         """returns a new sql.TableImpl object to correspond to the given Table object."""
         return MySQLTableImpl(table)
@@ -132,15 +139,16 @@ class MySQLEngine(ansisql.ANSISQLEngine):
         if compiled is None: return
         if getattr(compiled, "isinsert", False):
             self.context.last_inserted_ids = [cursor.lastrowid]
-
-    def _executemany(self, c, statement, parameters):
-        """we need accurate rowcounts for updates, inserts and deletes.  mysql is *also* is not nice enough
-        to produce this correctly for an executemany, so we do our own executemany here."""
-        rowcount = 0
-        for param in parameters:
-            c.execute(statement, param)
-            rowcount += c.rowcount
-        self.context.rowcount = rowcount
+    
+    # executemany just runs normally, since we arent using rowcount at all with mysql
+#    def _executemany(self, c, statement, parameters):
+ #       """we need accurate rowcounts for updates, inserts and deletes.  mysql is *also* is not nice enough
+ #       to produce this correctly for an executemany, so we do our own executemany here."""
+  #      rowcount = 0
+  #      for param in parameters:
+  #          c.execute(statement, param)
+  #          rowcount += c.rowcount
+  #      self.context.rowcount = rowcount
 
     def dbapi(self):
         return self.module
@@ -152,11 +160,6 @@ class MySQLTableImpl(sql.TableImpl):
     """attached to a schema.Table to provide it with a Selectable interface
     as well as other functions
     """
-
-#    def __init__(self, table):
- #       self.table = table
-  #      self.id = self.table.name
-
     def _rowid_col(self):
         if getattr(self, '_mysql_rowid_column', None) is None:
             if len(self.table.primary_keys) > 0:
index 82aaf7b03b0a0d3911dddd84d50f7909c827bf87..f32f7ba42f259b054a70d4db24221afce48e25e1 100644 (file)
@@ -109,6 +109,10 @@ class SQLEngine(schema.SchemaEngine):
         """returns the ROWID column name for this engine."""
         return "oid"
 
+    def supports_sane_rowcount(self):
+        """ill give everyone one guess which database warrants this method."""
+        return True
+        
     def create(self, table, **params):
         """creates a table given a schema.Table object."""
         table.accept_visitor(self.schemagenerator(self.proxy(), **params))
index 5203199425d3feda2d1fdd8810ec610a93c27393..ce3cb0566904e6c6f3b4f81b597c0ed026fc2a51 100644 (file)
@@ -506,7 +506,7 @@ class Mapper(object):
                     clause.clauses.append(col == sql.bindparam(col.table.name + "_" + col.key))
                 statement = table.update(clause)
                 c = statement.execute(*update)
-                if c.rowcount != len(update):
+                if table.engine.supports_sane_rowcount() and c.rowcount != len(update):
                     raise "ConcurrencyError - updated rowcount %d does not match number of objects updated %d" % (c.cursor.rowcount, len(update))
             if len(insert):
                 import sys
@@ -545,7 +545,7 @@ class Mapper(object):
                     clause.clauses.append(col == sql.bindparam(col.key))
                 statement = table.delete(clause)
                 c = statement.execute(*delete)
-                if c.rowcount != len(delete):
+                if table.engine.supports_sane_rowcount() and c.rowcount != len(delete):
                     raise "ConcurrencyError - updated rowcount %d does not match number of objects updated %d" % (c.cursor.rowcount, len(delete))
 
     def register_dependencies(self, *args, **kwargs):