[SQL-CVS] r3373 - in SQLObject/trunk: docs sqlobject/firebird sqlobject/mysql sqlobject/postgres sq
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2008-04-09 13:19:37
|
Author: phd Date: 2008-04-09 07:19:11 -0600 (Wed, 09 Apr 2008) New Revision: 3373 Modified: SQLObject/trunk/docs/News.txt SQLObject/trunk/sqlobject/firebird/firebirdconnection.py SQLObject/trunk/sqlobject/mysql/mysqlconnection.py SQLObject/trunk/sqlobject/postgres/pgconnection.py SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py Log: SQLObject can now create and drop a database in MySQL, PostgreSQL, SQLite and Firebird/Interbase. Modified: SQLObject/trunk/docs/News.txt =================================================================== --- SQLObject/trunk/docs/News.txt 2008-04-02 21:36:45 UTC (rev 3372) +++ SQLObject/trunk/docs/News.txt 2008-04-09 13:19:11 UTC (rev 3373) @@ -22,6 +22,9 @@ * New magic attribute 'j' similar to 'q' was added that automagically does join with the other table in MultipleJoin or RelatedJoin. +* SQLObject can now create and drop a database in MySQL, PostgreSQL, SQLite + and Firebird/Interbase. + Minor features -------------- Modified: SQLObject/trunk/sqlobject/firebird/firebirdconnection.py =================================================================== --- SQLObject/trunk/sqlobject/firebird/firebirdconnection.py 2008-04-02 21:36:45 UTC (rev 3372) +++ SQLObject/trunk/sqlobject/firebird/firebirdconnection.py 2008-04-09 13:19:11 UTC (rev 3373) @@ -226,3 +226,10 @@ return col.DateTimeCol, {} else: return col.Col, {} + + def createEmptyDatabase(self): + self.module.create_database("CREATE DATABASE '%s' user '%s' password '%s'" % \ + (self.db, self.user, self.password)) + + def dropDatabase(self): + self.module.drop_database() Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py =================================================================== --- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2008-04-02 21:36:45 UTC (rev 3372) +++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2008-04-09 13:19:11 UTC (rev 3373) @@ -292,3 +292,12 @@ return col.StringCol, {"length": 2**32, "varchar": True} else: return col.Col, {} + + def _createOrDropDatabase(self, op="CREATE"): + self.query('%s DATABASE %s' % (op, self.db)) + + def createEmptyDatabase(self): + self._createOrDropDatabase() + + def dropDatabase(self): + self._createOrDropDatabase(op="DROP") Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py =================================================================== --- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2008-04-02 21:36:45 UTC (rev 3372) +++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2008-04-09 13:19:11 UTC (rev 3373) @@ -292,7 +292,7 @@ return True return getattr(sqlbuilder.const, defaultstr) - def createEmptyDatabase(self): + def _createOrDropDatabase(self, op="CREATE"): # We have to connect to *some* database, so we'll connect to # template1, which is a common open database. # @@: This doesn't use self.use_dsn or self.dsn_dict @@ -312,11 +312,17 @@ # We must close the transaction with a commit so that # the CREATE DATABASE can work (which can't be in a transaction): cur.execute('COMMIT') - cur.execute('CREATE DATABASE %s' % self.db) + cur.execute('%s DATABASE %s' % (op, self.db)) cur.close() conn.close() + def createEmptyDatabase(self): + self._createOrDropDatabase() + def dropDatabase(self): + self._createOrDropDatabase(op="DROP") + + # Converter for psycopg Binary type. def PsycoBinaryConverter(value, db): assert db == 'postgres' Modified: SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py =================================================================== --- SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2008-04-02 21:36:45 UTC (rev 3372) +++ SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2008-04-09 13:19:11 UTC (rev 3373) @@ -1,8 +1,9 @@ import base64 +import os +import thread from sqlobject.dbconnection import DBAPI from sqlobject import col, sqlbuilder from sqlobject.dberrors import * -import thread sqlite = None using_sqlite2 = False @@ -357,5 +358,16 @@ else: return col.Col, {} + def createEmptyDatabase(self): + if self._memory: + return + open(self.filename, 'w').close() + + def dropDatabase(self): + if self._memory: + return + os.unlink(self.filename) + + def stop_pysqlite2_converting_strings(s): return s |