[Modeling-cvs] ProjectModeling/Modeling/DatabaseAdaptors/SQLiteAdaptorLayer SQLiteAdaptor.py,1.1,1.2
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-08-02 08:58:49
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/SQLiteAdaptorLayer In directory sc8-pr-cvs1:/tmp/cvs-serv8223/DatabaseAdaptors/SQLiteAdaptorLayer Modified Files: SQLiteAdaptor.py SQLiteSchemaGeneration.py Log Message: Fixed bug #781884: SQLiteAdaptorLayer: dropping and creating a database was not possible (and was failing w/ an ugly traceback) Index: SQLiteAdaptor.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/SQLiteAdaptorLayer/SQLiteAdaptor.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SQLiteAdaptor.py 11 Jun 2003 11:10:14 -0000 1.1 --- SQLiteAdaptor.py 2 Aug 2003 08:07:15 -0000 1.2 *************** *** 57,60 **** --- 57,68 ---- return concreteAdaptorContext + def createDatabaseWithAdministrativeConnectionDictionary(self, administrativeConnectionDictionary, createUserFlag=0): + """ + Overrides AbstractDBAPI2Adaptor's method and does nothing except opening + a connection to the new database, which is enough to create a database + with sqlite + """ + self.dbAPI_gimmeCnxAndCursorForDBAdmin(administrativeConnectionDictionary) + def defaultExpressionClass(self): "Returns Modeling.SQLExpression.SQLExpression" *************** *** 62,65 **** --- 70,87 ---- return SQLiteSQLExpression + def dropDatabaseWithAdministrativeConnectionDictionary(self, administrativeConnectionDictionary, dropUserFlag=0): + """ + Overrides AbstractDBAPI2Adaptor's method and os.unlink() the database + file. Parameter administrativeConnectionDictionary cannot be omitted here, + even if there's no such connection dictionary for sqlite: the database + to be removed is extracted from the dictionary's 'database' key (this is + also to prevent the accidental destruction of valuable data). + + Unlike other adaptors, this method does NOT call + SQLiteSchemaGeneration.dropDatabaseStatementsForConnectionDictionary() + """ + import os + os.unlink(administrativeConnectionDictionary['database']) + def expressionFactory(self): "See Modeling.interfaces.Adaptor for details" *************** *** 81,87 **** def dbAPI_gimmeCnxAndCursorForDBAdmin(self, administrativeConnectionDictionary): cnxDict=self.dbAPI_connectionDictionaryForConnect(administrativeConnectionDictionary) ! ! cnx.autocommit() return cnx, cnx.cursor() --- 103,110 ---- def dbAPI_gimmeCnxAndCursorForDBAdmin(self, administrativeConnectionDictionary): + # Opening a connection to a new database is sufficient to create it + # However we return both a cnx and a cursor to be consistent w/ the API cnxDict=self.dbAPI_connectionDictionaryForConnect(administrativeConnectionDictionary) ! cnx=apply(self.underlying_py_adaptor_module().connect, (), cnxDict) return cnx, cnx.cursor() Index: SQLiteSchemaGeneration.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/SQLiteAdaptorLayer/SQLiteSchemaGeneration.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SQLiteSchemaGeneration.py 11 Jun 2003 11:10:17 -0000 1.1 --- SQLiteSchemaGeneration.py 2 Aug 2003 08:07:15 -0000 1.2 *************** *** 65,84 **** def createDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, createUserFlag=0): """ See also: interfaces.SchemaGeneration for details """ ! createDB='CREATE DATABASE %(database)s'%connectionDictionary ! createUser='CREATE USER %(user)s NOCREATEUSER NOCREATEDB'%connectionDictionary ! ! sqlExprs=[] ! sqlExpr=self._adaptor.expressionClass()(None) ! sqlExpr.setStatement(createDB) ! sqlExprs.append(sqlExpr) ! # Create user ! if createUserFlag: ! sqlExpr=self._adaptor.expressionClass()(None) ! sqlExpr.setStatement(createUser) ! sqlExprs.append(sqlExpr) ! return tuple(sqlExprs) ! def createTableStatementsForEntityGroup(self, entityGroup): --- 65,74 ---- def createDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, createUserFlag=0): """ + Returns an empty list: connecting to a non existent database is sufficient + to create it. + See also: interfaces.SchemaGeneration for details """ ! return () def createTableStatementsForEntityGroup(self, entityGroup): *************** *** 113,131 **** def dropDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, dropUserFlag=0): ! "See Modeling.interfaces.SchemaGeneration for details" ! dropDB='DROP DATABASE %(database)s'%connectionDictionary ! dropUser='DROP USER %(user)s'%connectionDictionary - sqlExprs=[] - sqlExpr=self._adaptor.expressionClass()(None) - sqlExpr.setStatement(dropDB) - sqlExprs.append(sqlExpr) - # Create user - if dropUserFlag: - sqlExpr=self._adaptor.expressionClass()(None) - sqlExpr.setStatement(dropUser) - sqlExprs.append(sqlExpr) - return tuple(sqlExprs) - def dropForeignKeyConstraintStatementsForRelationship(self, relationship): """returns an empty list TBD""" --- 103,116 ---- def dropDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, dropUserFlag=0): ! """ ! Returns an empty list, since there's no way to drop a database within ! sqlite. The only thing to do is to os.unlink() the database file. ! ! See also: SQLiteAdaptor.dropDatabaseWithAdministrativeConnectionDictionary ! ! See Modeling.interfaces.SchemaGeneration for details ! """ ! return () def dropForeignKeyConstraintStatementsForRelationship(self, relationship): """returns an empty list TBD""" |