summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/sqlite.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-04-02 21:36:11 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-04-02 21:36:11 +0000
commitcdceb3c3714af707bfe3ede10af6536eaf529ca8 (patch)
tree2ccbfb60cd10d995c0309801b0adc4fc3a1f0a44 /lib/sqlalchemy/databases/sqlite.py
parent8607de3159fd37923ae99118c499935c4a54d0e2 (diff)
downloadsqlalchemy-cdceb3c3714af707bfe3ede10af6536eaf529ca8.tar.gz
- merged the "execcontext" branch, refactors engine/dialect codepaths
- much more functionality moved into ExecutionContext, which impacted the API used by dialects to some degree - ResultProxy and subclasses now designed sanely - merged patch for #522, Unicode subclasses String directly, MSNVarchar implements for MS-SQL, removed MSUnicode. - String moves its "VARCHAR"/"TEXT" switchy thing into "get_search_list()" function, which VARCHAR and CHAR can override to not return TEXT in any case (didnt do the latter yet) - implements server side cursors for postgres, unit tests, #514 - includes overhaul of dbapi import strategy #480, all dbapi importing happens in dialect method "dbapi()", is only called inside of create_engine() for default and threadlocal strategies. Dialect subclasses have a datamember "dbapi" referencing the loaded module which may be None. - added "mock" engine strategy, doesnt require DBAPI module and gives you a "Connecition" which just sends all executes to a callable. can be used to create string output of create_all()/drop_all().
Diffstat (limited to 'lib/sqlalchemy/databases/sqlite.py')
-rw-r--r--lib/sqlalchemy/databases/sqlite.py60
1 files changed, 27 insertions, 33 deletions
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py
index b29be9eed..9270f2a5f 100644
--- a/lib/sqlalchemy/databases/sqlite.py
+++ b/lib/sqlalchemy/databases/sqlite.py
@@ -12,19 +12,19 @@ import sqlalchemy.engine.default as default
import sqlalchemy.types as sqltypes
import datetime,time
-pysqlite2_timesupport = False # Change this if the init.d guys ever get around to supporting time cols
-
-try:
- from pysqlite2 import dbapi2 as sqlite
-except ImportError:
+def dbapi():
try:
- from sqlite3 import dbapi2 as sqlite #try the 2.5+ stdlib name.
- except ImportError:
+ from pysqlite2 import dbapi2 as sqlite
+ except ImportError, e:
try:
- sqlite = __import__('sqlite') # skip ourselves
- except:
- sqlite = None
-
+ from sqlite3 import dbapi2 as sqlite #try the 2.5+ stdlib name.
+ except ImportError:
+ try:
+ sqlite = __import__('sqlite') # skip ourselves
+ except ImportError:
+ raise e
+ return sqlite
+
class SLNumeric(sqltypes.Numeric):
def get_col_spec(self):
if self.precision is None:
@@ -140,10 +140,6 @@ pragma_names = {
'BLOB' : SLBinary,
}
-if pysqlite2_timesupport:
- colspecs.update({sqltypes.Time : SLTime})
- pragma_names.update({'TIME' : SLTime})
-
def descriptor():
return {'name':'sqlite',
'description':'SQLite',
@@ -152,25 +148,29 @@ def descriptor():
]}
class SQLiteExecutionContext(default.DefaultExecutionContext):
- def post_exec(self, engine, proxy, compiled, parameters, **kwargs):
- if getattr(compiled, "isinsert", False):
- self._last_inserted_ids = [proxy().lastrowid]
-
+ def post_exec(self):
+ if self.compiled.isinsert:
+ self._last_inserted_ids = [self.cursor.lastrowid]
+ super(SQLiteExecutionContext, self).post_exec()
+
class SQLiteDialect(ansisql.ANSIDialect):
def __init__(self, **kwargs):
+ ansisql.ANSIDialect.__init__(self, default_paramstyle='qmark', **kwargs)
def vers(num):
return tuple([int(x) for x in num.split('.')])
- self.supports_cast = (sqlite is not None and vers(sqlite.sqlite_version) >= vers("3.2.3"))
- ansisql.ANSIDialect.__init__(self, **kwargs)
+ self.supports_cast = (self.dbapi is None or vers(self.dbapi.sqlite_version) >= vers("3.2.3"))
def compiler(self, statement, bindparams, **kwargs):
return SQLiteCompiler(self, statement, bindparams, **kwargs)
def schemagenerator(self, *args, **kwargs):
- return SQLiteSchemaGenerator(*args, **kwargs)
+ return SQLiteSchemaGenerator(self, *args, **kwargs)
def schemadropper(self, *args, **kwargs):
- return SQLiteSchemaDropper(*args, **kwargs)
+ return SQLiteSchemaDropper(self, *args, **kwargs)
+
+ def supports_alter(self):
+ return False
def preparer(self):
return SQLiteIdentifierPreparer(self)
@@ -182,8 +182,8 @@ class SQLiteDialect(ansisql.ANSIDialect):
def type_descriptor(self, typeobj):
return sqltypes.adapt_type(typeobj, colspecs)
- def create_execution_context(self):
- return SQLiteExecutionContext(self)
+ def create_execution_context(self, **kwargs):
+ return SQLiteExecutionContext(self, **kwargs)
def last_inserted_ids(self):
return self.context.last_inserted_ids
@@ -191,9 +191,6 @@ class SQLiteDialect(ansisql.ANSIDialect):
def oid_column_name(self, column):
return "oid"
- def dbapi(self):
- return sqlite
-
def has_table(self, connection, table_name, schema=None):
cursor = connection.execute("PRAGMA table_info(" + table_name + ")", {})
row = cursor.fetchone()
@@ -321,11 +318,9 @@ class SQLiteCompiler(ansisql.ANSICompiler):
return ansisql.ANSICompiler.binary_operator_string(self, binary)
class SQLiteSchemaGenerator(ansisql.ANSISchemaGenerator):
- def supports_alter(self):
- return False
def get_column_specification(self, column, **kwargs):
- colspec = self.preparer.format_column(column) + " " + column.type.engine_impl(self.engine).get_col_spec()
+ colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect).get_col_spec()
default = self.get_column_default_string(column)
if default is not None:
colspec += " DEFAULT " + default
@@ -345,8 +340,7 @@ class SQLiteSchemaGenerator(ansisql.ANSISchemaGenerator):
# super(SQLiteSchemaGenerator, self).visit_primary_key_constraint(constraint)
class SQLiteSchemaDropper(ansisql.ANSISchemaDropper):
- def supports_alter(self):
- return False
+ pass
class SQLiteIdentifierPreparer(ansisql.ANSIIdentifierPreparer):
def __init__(self, dialect):