]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Sep 2005 07:06:41 +0000 (07:06 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Sep 2005 07:06:41 +0000 (07:06 +0000)
lib/sqlalchemy/engine.py
lib/sqlalchemy/sql.py

index fec2f7ae902f7eb7d37d2750d9972f43cf4ffae4..2ebed6eafa0e38a14cd171fcfd3e23f7dc00450a 100644 (file)
@@ -67,6 +67,20 @@ class SQLEngine(schema.SchemaEngine):
     def schemadropper(self, proxy, **params):
         raise NotImplementedError()
 
+    def compiler(self, statement, bindparams):
+        raise NotImplementedError()
+
+    def create(self, table, **params):
+        table.accept_visitor(self.schemagenerator(self.proxy(), **params))
+
+    def drop(self, table, **params):
+        table.accept_visitor(self.schemadropper(self.proxy(), **params))
+
+    def compile(self, statement, bindparams):
+        compiler = self.compiler(statement, bindparams)
+        statement.accept_visitor(compiler)
+        return compiler
+
     def reflecttable(self, table):
         raise NotImplementedError()
 
@@ -84,9 +98,6 @@ class SQLEngine(schema.SchemaEngine):
     def dbapi(self):
         raise NotImplementedError()
 
-    def compile(self, statement, bindparams):
-        raise NotImplementedError()
-
     def do_begin(self, connection):
         """implementations might want to put logic here for turning autocommit on/off, etc."""
         pass
index 671c59c67d6107c4ae9b25a51653107a420ed90e..3887c63b5565cb2c3ccaa115bb32cbf1307b95a3 100644 (file)
@@ -115,8 +115,8 @@ def alias(*args, **params):
 def subquery(alias, *args, **params):
     return Alias(Select(*args, **params), alias)
 
-def bindparam(key, value = None):
-    return BindParamClause(key, value)
+def bindparam(key, value = None, type=None):
+    return BindParamClause(key, value, type=type)
 
 def text(text):
     return TextClause(text)
@@ -183,7 +183,7 @@ class Compiled(ClauseVisitor):
             params = [self.get_params(**m) for m in multiparams]
         else:
             params = self.get_params(**params)
-        return self.engine.execute(str(self), params, compiled = self)
+        return self.engine.execute(str(self), params, compiled = self, typemap = self.typemap)
 
 class ClauseElement(object):
     """base class for elements of a programmatically constructed SQL expression.
@@ -297,7 +297,7 @@ class BindParamClause(ClauseElement):
         self.key = key
         self.value = value
         self.shortname = shortname
-        self.type = type
+        self.type = type or types.NULLTYPE
 
     def accept_visitor(self, visitor):
         visitor.visit_bindparam(self)
@@ -309,10 +309,7 @@ class BindParamClause(ClauseElement):
         return "BindParam(%s, %s, %s)" % (repr(self.key), repr(self.value), repr(self.shortname))
 
     def typeprocess(self, value):
-        if self.type is not None:
-            return self.type.convert_bind_param(value)
-        else:
-            return value
+        return self.type.convert_bind_param(value)
             
 class TextClause(ClauseElement):
     """represents any plain text WHERE clause or full SQL statement"""
@@ -768,7 +765,7 @@ class UpdateBase(ClauseElement):
                 else:
                     col = key
                 try:
-                    parameters[key] = bindparam(col.name, value)
+                    parameters[key] = bindparam(col.name, value, type=col.type)
                 except KeyError:
                     del parameters[key]
         return parameters
@@ -777,7 +774,7 @@ class UpdateBase(ClauseElement):
         # case one: no parameters in the statement, no parameters in the 
         # compiled params - just return binds for all the table columns
         if parameters is None and self.parameters is None:
-            return [(c, bindparam(c.name)) for c in self.table.columns]
+            return [(c, bindparam(c.name, type=c.type)) for c in self.table.columns]
 
         # if we have statement parameters - set defaults in the 
         # compiled params
@@ -807,7 +804,7 @@ class UpdateBase(ClauseElement):
             if d.has_key(c):
                 value = d[c]
                 if _is_literal(value):
-                    value = bindparam(c.name, value)
+                    value = bindparam(c.name, value, type=c.type)
                 values.append((c, value))
         return values