]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The path given as the location of a sqlite database is now
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 10 Feb 2011 20:03:11 +0000 (15:03 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 10 Feb 2011 20:03:11 +0000 (15:03 -0500)
normalized via os.path.abspath(), so that directory changes
within the process don't affect the ultimate location
of a relative file path.  [ticket:2036]

CHANGES
lib/sqlalchemy/dialects/sqlite/pysqlite.py
test/dialect/test_sqlite.py
test/lib/requires.py
test/orm/test_session.py

diff --git a/CHANGES b/CHANGES
index f2f05620824b8d430384f9c4e4b5ac0cb763271b..11b65b6f8ac11808c6866b04af8eae3bc5a2b1c6 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -212,6 +212,11 @@ CHANGES
   - SQLite dialect now uses `NullPool` for file-based databases
     [ticket:1921]
 
+  - The path given as the location of a sqlite database is now
+    normalized via os.path.abspath(), so that directory changes
+    within the process don't affect the ultimate location
+    of a relative file path.  [ticket:2036]
+
 - mssql
   - the String/Unicode types, and their counterparts VARCHAR/
     NVARCHAR, emit "max" as the length when no length is 
index 646c5b86f1272713aa4a6ada7629c98e62ef7fa3..d426b1bb28efca76c1e9c6c615f84461727ae7e8 100644 (file)
@@ -143,6 +143,7 @@ from sqlalchemy import exc, pool
 from sqlalchemy import types as sqltypes
 from sqlalchemy import util
 
+import os
 
 class _SQLite_pysqliteTimeStamp(DATETIME):
     def bind_processor(self, dialect):
@@ -228,6 +229,8 @@ class SQLiteDialect_pysqlite(SQLiteDialect):
                 " sqlite:///relative/path/to/file.db\n"
                 " sqlite:////absolute/path/to/file.db" % (url,))
         filename = url.database or ':memory:'
+        if filename != ':memory:':
+            filename = os.path.abspath(filename)
 
         opts = url.query.copy()
         util.coerce_kw_type(opts, 'timeout', float)
index efd616c3deaac3a9d651a903693ccc6c4d623b84..6b84c57edd333fdc500218b1e054169202949d50 100644 (file)
@@ -7,8 +7,9 @@ from sqlalchemy import *
 from sqlalchemy import exc, sql, schema, pool, types as sqltypes
 from sqlalchemy.dialects.sqlite import base as sqlite, \
     pysqlite as pysqlite_dialect
+from sqlalchemy.engine.url import make_url
 from test.lib import *
-
+import os
 
 class TestTypes(TestBase, AssertsExecutionResults):
 
@@ -328,6 +329,13 @@ class DialectTest(TestBase, AssertsExecutionResults):
                 pass
             raise
 
+    def test_file_path_is_absolute(self):
+        d = pysqlite_dialect.dialect()
+        eq_(
+            d.create_connect_args(make_url('sqlite:///foo.db')),
+            ([os.path.abspath('foo.db')], {})
+        )
+
     def test_pool_class(self):
         e = create_engine('sqlite+pysqlite://')
         assert e.pool.__class__ is pool.SingletonThreadPool
@@ -608,7 +616,7 @@ class MatchTest(TestBase, AssertsCompiledSQL):
         eq_([1, 3], [r.id for r in results])
 
 
-class TestAutoIncrement(TestBase, AssertsCompiledSQL):
+class AutoIncrementTest(TestBase, AssertsCompiledSQL):
 
     def test_sqlite_autoincrement(self):
         table = Table('autoinctable', MetaData(), Column('id', Integer,
index f26ba9c8938ca17fd6da5bd2e8f46b46158cf39c..610caa9f57f8660fa347ae85c6d926f5d7702b8d 100644 (file)
@@ -88,7 +88,8 @@ def independent_connections(fn):
     # ODBC as well.
     return _chain_decorators_on(
         fn,
-        no_support('sqlite', 'no driver support'),
+        no_support('sqlite', 'Independent connections disabled when '
+                            ':memory: connections are used'),
         exclude('mssql', '<', (9, 0, 0),
                 'SQL Server 2005+ is required for independent connections'),
         )
index c3f6dcd71ab5cad49df6c511ae065678b5bf2824..f0a925541088857ce513d5e778a2defae1d5540e 100644 (file)
@@ -520,7 +520,7 @@ class SessionTest(_fixtures.FixtureTest):
         assert session.connection().execute('select count(1) from users'
                 ).scalar() == 2
 
-    @testing.fails_on('sqlite', 'FIXME: unknown')
+    @testing.requires.independent_connections
     @testing.resolve_artifact_names
     def test_transactions_isolated(self):
         mapper(User, users)