# HG changeset patch # User cmlenz # Date 1121760325 0 # Node ID 0ae9a10f9d884b3acb0c67450bd2432034f251a0 # Parent bb5bcf5939f6e3e667a72b4f5c82ebbe984c999c More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility. diff --git a/bitten/model.py b/bitten/model.py --- a/bitten/model.py +++ b/bitten/model.py @@ -173,10 +173,12 @@ cursor = db.cursor() cursor.execute("INSERT INTO bitten_platform (config,name) " "VALUES (%s,%s)", (self.config, self.name)) - self.id = db.get_last_id('bitten_platform') - cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)", - [(self.id, propname, pattern, idx) for - idx, (propname, pattern) in enumerate(self.rules)]) + self.id = db.get_last_id(cursor, 'bitten_platform') + if self.rules: + cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)", + [(self.id, propname, pattern, idx) + for idx, (propname, pattern) + in enumerate(self.rules)]) if handle_ta: db.commit() @@ -195,10 +197,12 @@ cursor = db.cursor() cursor.execute("UPDATE bitten_platform SET name=%s WHERE id=%s", (self.name, self.id)) - cursor.execute("DELETE FROM bitten_rule WHERE id=%s", (self.id)) - cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)", - [(self.id, propname, pattern, idx) for - idx, (propname, pattern) in enumerate(self.rules)]) + cursor.execute("DELETE FROM bitten_rule WHERE id=%s", (self.id,)) + if self.rules: + cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)", + [(self.id, propname, pattern, idx) + for idx, (propname, pattern) + in enumerate(self.rules)]) if handle_ta: db.commit() @@ -328,10 +332,11 @@ (self.config, self.rev, self.rev_time, self.platform, self.slave or '', self.started or 0, self.stopped or 0, self.status)) - self.id = db.get_last_id('bitten_build') - cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)", - [(self.id, name, value) for name, value - in self.slave_info.items()]) + self.id = db.get_last_id(cursor, 'bitten_build') + if self.slave_info: + cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)", + [(self.id, name, value) for name, value + in self.slave_info.items()]) if handle_ta: db.commit() diff --git a/bitten/tests/model.py b/bitten/tests/model.py --- a/bitten/tests/model.py +++ b/bitten/tests/model.py @@ -31,7 +31,8 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in BuildConfig._schema: - cursor.execute(db.to_sql(table)) + for stmt in db.to_sql(table): + cursor.execute(stmt) db.commit() def test_new_config(self): @@ -72,7 +73,8 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in TargetPlatform._schema: - cursor.execute(db.to_sql(table)) + for stmt in db.to_sql(table): + cursor.execute(stmt) db.commit() def test_new(self): @@ -102,7 +104,7 @@ cursor = db.cursor() cursor.execute("INSERT INTO bitten_platform (config,name) " "VALUES (%s,%s)", ('test', 'Windows')) - id = db.get_last_id('bitten_platform') + id = db.get_last_id(cursor, 'bitten_platform') platform = TargetPlatform.fetch(self.env, id) assert platform.exists self.assertEqual('test', platform.config) @@ -125,7 +127,8 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in Build._schema: - cursor.execute(db.to_sql(table)) + for stmt in db.to_sql(table): + cursor.execute(stmt) db.commit() def test_new(self): @@ -195,7 +198,7 @@ "VALUES (%s,%s,%s,%s,%s,%s,%s,%s)", ('test', '42', 12039, 1, 'tehbox', 15006, 16007, Build.SUCCESS)) - build_id = db.get_last_id('bitten_build') + build_id = db.get_last_id(cursor, 'bitten_build') cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)", [(build_id, Build.IP_ADDRESS, '127.0.0.1'), (build_id, Build.MAINTAINER, 'joe@example.org')]) @@ -213,7 +216,8 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in BuildStep._schema: - cursor.execute(db.to_sql(table)) + for stmt in db.to_sql(table): + cursor.execute(stmt) db.commit() def test_new(self): diff --git a/bitten/trac_ext/tests/web_ui.py b/bitten/trac_ext/tests/web_ui.py --- a/bitten/trac_ext/tests/web_ui.py +++ b/bitten/trac_ext/tests/web_ui.py @@ -19,7 +19,8 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - cursor.execute(db.to_sql(table)) + for stmt in db.to_sql(table): + cursor.execute(stmt) # Set up permissions self.env.config.set('trac', 'permission_store',