summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/firebird.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-05-25 14:20:23 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-05-25 14:20:23 +0000
commitbb79e2e871d0a4585164c1a6ed626d96d0231975 (patch)
tree6d457ba6c36c408b45db24ec3c29e147fe7504ff /lib/sqlalchemy/databases/firebird.py
parent4fc3a0648699c2b441251ba4e1d37a9107bd1986 (diff)
downloadsqlalchemy-bb79e2e871d0a4585164c1a6ed626d96d0231975.tar.gz
merged 0.2 branch into trunk; 0.1 now in sqlalchemy/branches/rel_0_1
Diffstat (limited to 'lib/sqlalchemy/databases/firebird.py')
-rw-r--r--lib/sqlalchemy/databases/firebird.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/sqlalchemy/databases/firebird.py b/lib/sqlalchemy/databases/firebird.py
index 99ef9eb9f..7dc48a54a 100644
--- a/lib/sqlalchemy/databases/firebird.py
+++ b/lib/sqlalchemy/databases/firebird.py
@@ -5,7 +5,7 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-import sys, StringIO, string, datetime
+import sys, StringIO, string
import sqlalchemy.sql as sql
import sqlalchemy.schema as schema
@@ -30,16 +30,6 @@ class FBSmallInteger(sqltypes.Smallinteger):
class FBDateTime(sqltypes.DateTime):
def get_col_spec(self):
return "DATE"
- def convert_bind_param(self, value, engine):
- if value is not None:
- if isinstance(value, datetime.datetime):
- seconds = float(str(value.second) + "."
- + str(value.microsecond))
- return kinterbasdb.date_conv_out((value.year, value.month, value.day,
- value.hour, value.minute, seconds))
- return kinterbasdb.timestamp_conv_in(value)
- else:
- return None
class FBText(sqltypes.TEXT):
def get_col_spec(self):
return "BLOB SUB_TYPE 2"
@@ -84,12 +74,13 @@ def descriptor():
]}
class FBSQLEngine(ansisql.ANSISQLEngine):
- def __init__(self, opts, module=None, use_oids=False, **params):
+ def __init__(self, opts, use_ansi = True, module = None, **params):
+ self._use_ansi = use_ansi
+ self.opts = opts or {}
if module is None:
self.module = kinterbasdb
else:
self.module = module
- self.opts = self._translate_connect_args(('host', 'database', 'user', 'password'), opts)
ansisql.ANSISQLEngine.__init__(self, **params)
def do_commit(self, connection):
@@ -111,7 +102,7 @@ class FBSQLEngine(ansisql.ANSISQLEngine):
return self.context.last_inserted_ids
def compiler(self, statement, bindparams, **kwargs):
- return FBCompiler(statement, bindparams, engine=self, **kwargs)
+ return FBCompiler(statement, bindparams, engine=self, use_ansi=self._use_ansi, **kwargs)
def schemagenerator(self, **params):
return FBSchemaGenerator(self, **params)
@@ -197,6 +188,21 @@ class FBSQLEngine(ansisql.ANSISQLEngine):
class FBCompiler(ansisql.ANSICompiler):
"""firebird compiler modifies the lexical structure of Select statements to work under
non-ANSI configured Firebird databases, if the use_ansi flag is False."""
+
+ def __init__(self, engine, statement, parameters, use_ansi = True, **kwargs):
+ self._outertable = None
+ self._use_ansi = use_ansi
+ ansisql.ANSICompiler.__init__(self, engine, statement, parameters, **kwargs)
+
+ def visit_column(self, column):
+ if self._use_ansi:
+ return ansisql.ANSICompiler.visit_column(self, column)
+
+ if column.table is self._outertable:
+ self.strings[column] = "%s.%s(+)" % (column.table.name, column.name)
+ else:
+ self.strings[column] = "%s.%s" % (column.table.name, column.name)
+
def visit_function(self, func):
if len(func.clauses):
super(FBCompiler, self).visit_function(func)
@@ -217,11 +223,10 @@ class FBCompiler(ansisql.ANSICompiler):
""" called when building a SELECT statment, position is just before column list
Firebird puts the limit and offset right after the select...thanks for adding the
visit_select_precolumns!!!"""
- result = ''
if select.offset:
- result +=" FIRST %s " % select.offset
+ result +=" FIRST " + select.offset
if select.limit:
- result += " SKIP %s " % select.limit
+ result += " SKIP " + select.limit
if select.distinct:
result += " DISTINCT "
return result
@@ -229,8 +234,6 @@ class FBCompiler(ansisql.ANSICompiler):
def limit_clause(self, select):
"""Already taken care of in the visit_select_precolumns method."""
return ""
- def default_from(self):
- return ' from RDB$DATABASE '
class FBSchemaGenerator(ansisql.ANSISchemaGenerator):
def get_column_specification(self, column, override_pk=False, **kwargs):