summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-02-10 15:03:11 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-02-10 15:03:11 -0500
commite43f85965e516218fd2630dba5d46cbdc8e00e09 (patch)
treea32d157bd8796cf888d15dda1cceb463e8ae434a
parent3f9a343d725eea883aba2145de4cbb7b84f9d08c (diff)
downloadsqlalchemy-e43f85965e516218fd2630dba5d46cbdc8e00e09.tar.gz
- 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]
-rw-r--r--CHANGES5
-rw-r--r--lib/sqlalchemy/dialects/sqlite/pysqlite.py3
-rw-r--r--test/dialect/test_sqlite.py12
-rw-r--r--test/lib/requires.py3
-rw-r--r--test/orm/test_session.py2
5 files changed, 21 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index f2f056208..11b65b6f8 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 646c5b86f..d426b1bb2 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 efd616c3d..6b84c57ed 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 f26ba9c89..610caa9f5 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 c3f6dcd71..f0a925541 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)