diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 6e050304d..c52668762 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -65,22 +65,22 @@ from sqlalchemy import processors from sqlalchemy.types import BLOB, BOOLEAN, CHAR, DATE, DATETIME, DECIMAL,\ FLOAT, INTEGER, NUMERIC, SMALLINT, TEXT, TIME,\ TIMESTAMP, VARCHAR - + class _DateTimeMixin(object): _reg = None _storage_format = None - + def __init__(self, storage_format=None, regexp=None, **kw): super(_DateTimeMixin, self).__init__(**kw) if regexp is not None: self._reg = re.compile(regexp) if storage_format is not None: self._storage_format = storage_format - + class DATETIME(_DateTimeMixin, sqltypes.DateTime): _storage_format = "%04d-%02d-%02d %02d:%02d:%02d.%06d" - + def bind_processor(self, dialect): datetime_datetime = datetime.datetime datetime_date = datetime.date @@ -122,7 +122,7 @@ class DATE(_DateTimeMixin, sqltypes.Date): raise TypeError("SQLite Date type only accepts Python " "date objects as input.") return process - + def result_processor(self, dialect, coltype): if self._reg: return processors.str_to_datetime_processor_factory( @@ -146,7 +146,7 @@ class TIME(_DateTimeMixin, sqltypes.Time): raise TypeError("SQLite Time type only accepts Python " "time objects as input.") return process - + def result_processor(self, dialect, coltype): if self._reg: return processors.str_to_datetime_processor_factory( @@ -200,10 +200,10 @@ class SQLiteCompiler(compiler.SQLCompiler): def visit_now_func(self, fn, **kw): return "CURRENT_TIMESTAMP" - + def visit_char_length_func(self, fn, **kw): return "length%s" % self.function_argspec(fn) - + def visit_cast(self, cast, **kwargs): if self.dialect.supports_cast: return super(SQLiteCompiler, self).visit_cast(cast) @@ -252,7 +252,7 @@ class SQLiteDDLCompiler(compiler.DDLCompiler): isinstance(column.type, sqltypes.Integer) and \ not column.foreign_keys: colspec += " PRIMARY KEY AUTOINCREMENT" - + return colspec def visit_primary_key_constraint(self, constraint): @@ -269,12 +269,12 @@ class SQLiteDDLCompiler(compiler.DDLCompiler): return super(SQLiteDDLCompiler, self).\ visit_primary_key_constraint(constraint) - + def visit_foreign_key_constraint(self, constraint): - + local_table = constraint._elements.values()[0].parent.table remote_table = list(constraint._elements.values())[0].column.table - + if local_table.schema != remote_table.schema: return None else: @@ -282,7 +282,7 @@ class SQLiteDDLCompiler(compiler.DDLCompiler): def define_constraint_remote_table(self, constraint, table, preparer): """Format the remote table clause of a CREATE CONSTRAINT clause.""" - + return preparer.format_table(table, use_schema=False) def visit_create_index(self, create): @@ -347,7 +347,7 @@ class SQLiteExecutionContext(default.DefaultExecutionContext): trunc_col = colname.split(".")[1] rp._metadata._set_keymap_synonym(trunc_col, colname) return rp - + class SQLiteDialect(default.DefaultDialect): name = 'sqlite' supports_alter = False @@ -356,7 +356,7 @@ class SQLiteDialect(default.DefaultDialect): supports_default_values = True supports_empty_insert = False supports_cast = True - + default_paramstyle = 'qmark' statement_compiler = SQLiteCompiler ddl_compiler = SQLiteDDLCompiler @@ -366,7 +366,7 @@ class SQLiteDialect(default.DefaultDialect): colspecs = colspecs isolation_level = None execution_ctx_cls = SQLiteExecutionContext - + supports_cast = True supports_default_values = True @@ -378,7 +378,7 @@ class SQLiteDialect(default.DefaultDialect): "Valid isolation levels for sqlite are 'SERIALIZABLE' and " "'READ UNCOMMITTED'.") self.isolation_level = isolation_level - + # this flag used by pysqlite dialect, and perhaps others in the # future, to indicate the driver is handling date/timestamp # conversions (and perhaps datetime/time as well on some @@ -391,14 +391,14 @@ class SQLiteDialect(default.DefaultDialect): self.supports_cast = \ self.dbapi.sqlite_version_info >= (3, 2, 3) - + def on_connect(self): if self.isolation_level is not None: if self.isolation_level == 'READ UNCOMMITTED': isolation_level = 1 else: isolation_level = 0 - + def connect(conn): cursor = conn.cursor() cursor.execute("PRAGMA read_uncommitted = %d" % isolation_level) @@ -439,7 +439,7 @@ class SQLiteDialect(default.DefaultDialect): qtable = quote(table_name) cursor = _pragma_cursor(connection.execute("%stable_info(%s)" % (pragma, qtable))) row = cursor.fetchone() - + # consume remaining rows, to work around # http://www.sqlite.org/cvstrac/tktview?tn=1884 while not cursor.closed and cursor.fetchone() is not None: @@ -626,7 +626,7 @@ class SQLiteDialect(default.DefaultDialect): def _pragma_cursor(cursor): """work around SQLite issue whereby cursor.description is blank when PRAGMA returns no rows.""" - + if cursor.closed: cursor.fetchone = lambda: None return cursor |