|
From: Daniel B. <da...@cs...> - 2004-06-13 22:30:23
|
I'm playing with today's svn, and the db connection URIs (used with
connectForURI) for sqlite don't seem to handle the special
memory-resident target, which sqlite calls :memory:.
Normally, if you tell sqlite to use a file named :memory:, it will keep
the database in memory instead of using a file on disk. This worked fine
with the SQLiteConnection(file=':memory:') interface, but the current
URI parsing can't handle it (DBConnection._parseURI).
Some examples:
URI: sqlite:/:memory:
_parseURI: user=None password=None host=None path=/:memory: args={}
URI: sqlite://:memory:
_parseURI: user=None password=None host=:memory: path=/ args={}
URI: sqlite:///:memory:
_parseURI: user=None password=None host=None path=/:memory: args={}
In none of these does the path come out as :memory:. Moreover, the first
and third examples should probably be considered correct, since those
URIs identify the file /:memory: , and not SQLite's pseudo-thing that
indicates the lack of a file.
But in the second URI, the parser interprets an identifer after
schema:// as the host, and expects the path to follow another '/' (which
isn't supplied, in this example).
Since hosts have no other meaning in sqlite URIs, maybe accepting a host
named :memory: would be an acceptable hack?
Here is a (line-broken) `svn diff` of my implementation of this idea. I
also removed the addition of an extra leading '/', which
DBConnection._parseURI already provides:
danb
Index: sqlobject/sqlite/sqliteconnection.py
===================================================================
--- sqlobject/sqlite/sqliteconnection.py (revision 126)
+++ sqlobject/sqlite/sqliteconnection.py (working copy)
@@ -21,10 +21,14 @@
DBAPI.__init__(self, **kw)
def connectionFromURI(cls, uri):
+ magic_host = ':memory:'
user, password, host, path, args = cls._parseURI(uri)
- assert host is None, "SQLite can only be used locally (with a
URI like sqlite:///file or sql:/file, not %r)" % uri
+ assert host in [ None, magic_host ], "SQLite can only be used
locally (with a URI like sqlite:///file or sql:/file, not %r), or with
the magic host '%s' to specify in-memory use." % (uri, magic_host)
assert user is None and password is None, "You may not provide
usernames or passwords for SQLite databases"
- return cls(filename='/' + path, **args)
+ if host == magic_host:
+ assert path == '/', "You may not provide a path with the
magic host '%s'" % magic_host
+ path = host
+ return cls(filename=path, **args)
connectionFromURI = classmethod(connectionFromURI)
def _setAutoCommit(self, conn, auto):
--
Daniel Brown
www.utacm.org
www.cs.utexas.edu
|