Hi guys,

I'd like to use an in-memory sqlite database for testing, and I have a
problem where I don't seem to be able to let go of a database which was
once created. Here's a test that shows what I mean:

class Foo(sqlobject.SQLObject):
  bar = sqlobject.UnicodeCol(length=250, unique=True)

db_uri = 'sqlite:/:memory:'
conn = sqlobject.connectionForURI(db_uri)
sqlobject.sqlhub.processConnection = conn
Foo.createTable()
# All is good so far. Now let's drop the database.
conn.close()
del conn
# From http://www.sqlite.org/inmemorydb.html:
# "The database is automatically deleted and memory is reclaimed when the
last connection to the database closes."
# Let's create a fresh in-memory database.
conn = sqlobject.connectionForURI(db_uri)
sqlobject.sqlhub.processConnection = conn
Foo.createTable()
# Here, an exception is thrown:
sqlobject.dberrors.OperationalError: table foo already exists

I must have somehow gotten a connection to the same in-memory database that
was created on the first call to connectionForURI(). After looking at
dbconnection.py, I came up with an invasive method:

sqlobject.dbconnection.TheURIOpener.cachedURIs = {}
conn = sqlobject.connectionForURI(db_uri)
sqlobject.sqlhub.processConnection = conn
Foo.createTable()

It does what I need, but it doesn't seem like it's what SQLObject
developers intended. Do you have any recommendations?

Maciej
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to