class ANSICompiler(sql.Compiled):
def __init__(self, parent, bindparams):
self.binds = {}
- self.bindparams = bindparams
+ self._bindparams = bindparams
self.parent = parent
self.froms = {}
self.wheres = {}
return self.wheres.get(obj, None)
def get_params(self, **params):
+ """returns the bind params for this compiled object, with values overridden by
+ those given in the **params dictionary"""
d = {}
for key, value in params.iteritems():
try:
d[b.key] = value
for b in self.binds.values():
- if not d.has_key(b.key):
- d[b.key] = b.value
+ d.setdefault(b.key, b.value)
return d
if t is not None:
froms.append(t)
- text += string.join(froms, ', ')
+ text += string.join(froms, ', ')
if whereclause is not None:
t = self.get_str(whereclause)
def visit_table(self, table):
self.froms[table] = table.name
-
+
def visit_join(self, join):
if join.isouter:
self.froms[join] = (self.get_from_text(join.left) + " LEFT OUTER JOIN " + self.get_from_text(join.right) +
" ON " + self.get_str(join.onclause))
else:
- self.froms[join] = (self.get_from_text(join.left) + " JOIN " + self.get_from_text(join.right) +
+ self.froms[join] = (self.get_from_text(join.left) + " JOIN " + self.get_from_text(join.right) +
" ON " + self.get_str(join.onclause))
-
-
+
def visit_insert(self, insert_stmt):
- colparams = insert_stmt.get_colparams(self.bindparams)
+ colparams = insert_stmt.get_colparams(self._bindparams)
for c in colparams:
b = c[1]
self.strings[insert_stmt] = text
def visit_update(self, update_stmt):
- colparams = update_stmt.get_colparams(self.bindparams)
+ colparams = update_stmt.get_colparams(self._bindparams)
for c in colparams:
b = c[1]
def connect_args(self):
return ([self.filename], self.opts)
+
+ def compile(self, statement, bindparams):
+ compiler = SQLiteCompiler(statement, bindparams)
+
+ statement.accept_visitor(compiler)
+ return compiler
def dbapi(self):
return sqlite
def reflecttable(self, table):
raise NotImplementedError()
+class SQLiteCompiler(ansisql.ANSICompiler):
+ def visit_insert(self, insert):
+ ansisql.ANSICompiler.visit_insert(self, insert)
+
class SQLiteColumnImpl(sql.ColumnSelectable):
def _get_specification(self):
coltype = self.column.type
c = self.compile(e, bindparams = params)
# TODO: do pre-execute right here, for sequences, if the compiled object
# defines it
- # TODO: why do we send the params twice, once to compile, once to c.get_params
- return e.execute(str(c), c.get_params(**params), echo = getattr(self, 'echo', None))
+ return e.execute(str(c), c.get_params(), echo = getattr(self, 'echo', None))
def result(self, **params):
e = self._engine()
c = self.compile(e, bindparams = params)
- return e.result(str(c), c.get_params(**params))
+ return e.result(str(c), c.binds)
class ColumnClause(ClauseElement):
"""represents a column clause element in a SQL statement."""