From 2452cebc23c527ec9361468bb698e279e739d71d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 27 Nov 2005 05:32:13 +0000 Subject: [PATCH] rowcount doesnt work on MySQL, so disabled concurrency check with mysql --- lib/sqlalchemy/databases/mysql.py | 31 +++++++++++++++++-------------- lib/sqlalchemy/engine.py | 4 ++++ lib/sqlalchemy/mapper.py | 4 ++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index bf1b19575c..e7f64c9b4d 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -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: diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py index 82aaf7b03b..f32f7ba42f 100644 --- a/lib/sqlalchemy/engine.py +++ b/lib/sqlalchemy/engine.py @@ -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)) diff --git a/lib/sqlalchemy/mapper.py b/lib/sqlalchemy/mapper.py index 5203199425..ce3cb05669 100644 --- a/lib/sqlalchemy/mapper.py +++ b/lib/sqlalchemy/mapper.py @@ -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): -- 2.47.2