Thread: [Modeling-users] leaving the database open
Status: Abandoned
Brought to you by:
sbigaret
From: Ernesto R. <er...@si...> - 2004-02-25 23:57:34
|
Hi all, strange thing (for me) that the AdaptorContext does not define a close = operation. Working with SQLite, I only see code to close the database when all = channels are closed and the = os.environ.get('MDL_TRANSIENT_DB_CONNECTION') is set (to something = different as '' and 0). The problem arose when I executed the mdl_create_DB_schema.py with = execfile from within my PyModel definition with execfile with the -R = option. The database was open (after running a schema creation). So = rerunning the script with some changes in the model, didn't drop the DB. So I have the following questions: * does loading the model open the database? * is it possible to close explicitly the database, i.e. context, so that = after the creation of the schema the database is closed? * what does the MDL_TRANSIENT_DB_CONNECTION mean: a) do not close the DB when all cursor have closed, or b) the opposite, close the DB when all channels are closed? If mdl_generate_DB_schema.py is invoked with the -R option, using = SQLiteAptor, and the file does not exist, an error is rosen. Perhaps = this could be ignored. (-R is: drop the database if it exists). This = could be done with the following code in = dropDatabaseWithAdministrativeConnectionDictionary: try: os.unlink(administrativeConnectionDictionary['database']) except OSError, exc: # ignore if file does not exist, else, reraise exception if not exc.errno=3D=3D2: raise with best regards, Erny |
From: Ernesto R. <er...@si...> - 2004-02-26 12:50:42
|
Dear all, * how do I query for DateTime fields? * modeling validates mx.DateTime.DateTime and mx.DateTime.Date objects, = but not mx.DateTime.Time. (efectively DateTimeDelta). Is it possible to = handle these? Best regards, Erny |
From: Sebastien B. <sbi...@us...> - 2004-02-29 13:29:44
|
"Ernesto Revilla" <er...@si...> wrote: > Dear all, >=20 > * how do I query for DateTime fields? Example: ec.fetch('Writer', 'birthday =3D=3D "1939-10-27 08:31:15"') or ec.fetch('Writer', 'birthday like "1939-10-27*"') > * modeling validates mx.DateTime.DateTime and mx.DateTime.Date objects, b= ut > not mx.DateTime.Time. (efectively DateTimeDelta). Is it possible to handle > these? Yes it is: try the attached patch! -- S=E9bastien. ------------------------------------------------------------------------ diff -u -r1.21 Attribute.py --- Attribute.py 22 Feb 2004 17:31:37 -0000 1.21 +++ Attribute.py 29 Feb 2004 13:10:39 -0000 @@ -56,7 +56,7 @@ # python import types, string, sys, time from cgi import escape -from mx.DateTime import DateTime, DateFrom +from mx.DateTime import DateTime, DateFrom, Time =20 # Module constants # useless, should be dropped @@ -76,7 +76,7 @@ =20 def date_types(): "Returns the set of valid date types" - avail_types=3D[ type(DateTime(0)) ] + avail_types=3D[ type(DateTime(0)), type(Time(0)) ] try: import DCOracle2 avail_types.append(type(DCOracle2.Date(0,0,0))) ------------------------------------------------------------------------ |
From: Sebastien B. <sbi...@us...> - 2004-02-29 12:53:19
|
Hi and sorry for the delay in the answer, "Ernesto Revilla" <er...@si...> wrote: > Hi all, >=20 > strange thing (for me) that the AdaptorContext does not define a close > operation. >=20 > Working with SQLite, I only see code to close the database when all chann= els > are closed and the os.environ.get('MDL_TRANSIENT_DB_CONNECTION') is set (= to > something different as '' and 0). You're right: the connection to the db is only closed in this situation. So, if you need to close it after an operation, you have to set MDL_TRANSIENT_DB_CONNECTION to true before that operation. The mechanism will probably change however in the near future; maybe a delegate can handle those situations. Now if you need a method to close the database connection after some operations took place, this can be made the way it is in AbstractDBAPI2AdaptorContext.adaptorChannelDidClose() -- the important thing is to set self._cnx to None so that it automatically reconnects when needed. If you're doing this in a multi-thread environment with many ECs, you should lock the ObjectStoreCoordinator (which is any EC's rootObjectStore()) before closing the connection. > The problem arose when I executed the mdl_create_DB_schema.py with > execfile from within my PyModel definition with execfile with the -R > option. The database was open (after running a schema creation). So > rerunning the script with some changes in the model, didn't drop the > DB. >=20 > So I have the following questions: > * does loading the model open the database? Not at all --if you want to see when the db connection is opened you can MDL_ENABLE_DATABASE_LOGGING to "yes". > * is it possible to close explicitly the database, i.e. context, so > that after the creation of the schema the database is closed? I'll suggest setting MDL_TRANSIENT_DB_CONNECTION > * what does the MDL_TRANSIENT_DB_CONNECTION mean: > a) do not close the DB when all cursor have closed, or > b) the opposite, close the DB when all channels are closed? If set to true, it closes the db when the last opened channel is closed. The default behaviour is now to keep the db connection opened. BTW I've just realized that the User's Guide says exactly the opposite, this should be fixed. >=20 > If mdl_generate_DB_schema.py is invoked with the -R option, using > SQLiteAptor, and the file does not exist, an error is rosen. Perhaps this > could be ignored. (-R is: drop the database if it exists). This could be > done with the following code in > dropDatabaseWithAdministrativeConnectionDictionary: >=20 > try: > os.unlink(administrativeConnectionDictionary['database']) > except OSError, exc: > # ignore if file does not exist, else, reraise exception > if not exc.errno=3D=3D2: > raise Well, the error shouldn't be ignored when the file does not exist to be consistent with other adaptors which also raise when an attempt is made to drop an non-existing database. In the script, -R is: drop the db and recreate it and agreed, it fails if the database does not exist; if you want to ignore the error, the option -i/--ignore-errors is your friend :) Now if you want to explictly ask for DB creation (not re-creation), then you want to use -C. I'm not sure I fully understood your use-case with executing the script, hopefully this answers your question. -- S=E9bastien. |