From 5dd9dbc86fb88f2520b315e3ec978382ac5c22e6 Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 8 Oct 2008 02:28:18 +0800 Subject: [PATCH] Fix residual bugs in table droping and creation Add Regression test for recreating_tables in mysql --- pyfpdb/RegressionTest.py | 10 ++++++++-- pyfpdb/fpdb_db.py | 21 +++++---------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/pyfpdb/RegressionTest.py b/pyfpdb/RegressionTest.py index 10bf071d..da03c350 100644 --- a/pyfpdb/RegressionTest.py +++ b/pyfpdb/RegressionTest.py @@ -43,8 +43,14 @@ class TestSequenceFunctions(unittest.TestCase): def testDatabaseConnection(self): """Test all supported DBs""" - result = self.mysql_db.cursor.execute("SHOW TABLES") - self.failUnless(result==13, "Number of tables in database incorrect. Expected 13 got " + str(result)) + self.result = self.mysql_db.cursor.execute("SHOW TABLES") + self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result)) + + def testMySQLRecreateTables(self): + """Test droping then recreating fpdb table schema""" + self.mysql_db.recreate_tables() + self.result = self.mysql_db.cursor.execute("SHOW TABLES") + self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result)) if __name__ == '__main__': unittest.main() diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index c5507bf6..6605aef6 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -61,20 +61,6 @@ class fpdb_db: self.wrongDbVersion=True #end def connect - def create_table(self, string): - """creates a table for the given string - The string should the name of the table followed by the column list - in brackets as if it were an SQL command. Do NOT include the "CREATE TABLES" - bit at the beginning nor the ";" or ENGINE= at the end""" - string="CREATE TABLE "+string - if (self.backend==self.MYSQL_INNODB): - string+=" ENGINE=INNODB" - string+=";" - #print "create_table, string:", string - self.cursor.execute(string) - self.db.commit() - #end def create_table - def disconnect(self, due_to_error=False): """Disconnects the DB""" if due_to_error: @@ -107,17 +93,18 @@ class fpdb_db: self.cursor.execute(self.sql.query['createHandsActionsTable']) self.cursor.execute(self.sql.query['createHudCacheTable']) self.fillDefaultData() + self.db.commit() #end def disconnect def drop_tables(self): """Drops the fpdb tables from the current db""" if(self.get_backend_name() == 'MySQL InnoDB'): - # Query the DB to see what tables exist - self.cursor.execute('SHOW TABLES') #Databases with FOREIGN KEY support need this switched of before you can drop tables self.drop_referencial_integrity() + # Query the DB to see what tables exist + self.cursor.execute('SHOW TABLES') for table in self.cursor: self.cursor.execute(self.sql.query['drop_table'] + table[0]) elif(self.get_backend_name() == 'PostgreSQL'): @@ -126,6 +113,8 @@ class fpdb_db: elif(self.get_backend_name() == 'SQLite'): #todo: sqlite version here print "Empty function here" + + self.db.commit() #end def drop_tables def drop_referencial_integrity(self):