From: Mike Bayer Date: Thu, 10 Feb 2011 20:03:11 +0000 (-0500) Subject: - The path given as the location of a sqlite database is now X-Git-Tag: rel_0_7b1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e43f85965e516218fd2630dba5d46cbdc8e00e09;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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] --- diff --git a/CHANGES b/CHANGES index f2f0562082..11b65b6f8a 100644 --- 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 diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index 646c5b86f1..d426b1bb28 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -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) diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index efd616c3de..6b84c57edd 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -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, diff --git a/test/lib/requires.py b/test/lib/requires.py index f26ba9c893..610caa9f57 100644 --- a/test/lib/requires.py +++ b/test/lib/requires.py @@ -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'), ) diff --git a/test/orm/test_session.py b/test/orm/test_session.py index c3f6dcd71a..f0a9255410 100644 --- a/test/orm/test_session.py +++ b/test/orm/test_session.py @@ -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)