summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-11-25 03:28:49 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-11-25 03:28:49 +0000
commitcf18eecd704f5eb6fde4e0c362cfdb322e3e559a (patch)
tree9b6e4503802cf0fcae9171b3ac2f85ba0af453c7 /lib/sqlalchemy/databases
parent6f604f911640d92f705fc6611bfaa3e2600c4ee1 (diff)
downloadsqlalchemy-cf18eecd704f5eb6fde4e0c362cfdb322e3e559a.tar.gz
- named_with_column becomes an attribute
- cleanup within compiler visit_select(), column labeling - is_select() removed from dialects, replaced with returns_rows_text(), returns_rows_compiled() - should_autocommit() removed from dialects, replaced with should_autocommit_text() and should_autocommit_compiled() - typemap and column_labels collections removed from Compiler, replaced with single "result_map" collection. - ResultProxy uses more succinct logic in combination with result_map to target columns
Diffstat (limited to 'lib/sqlalchemy/databases')
-rw-r--r--lib/sqlalchemy/databases/access.py6
-rw-r--r--lib/sqlalchemy/databases/informix.py9
-rw-r--r--lib/sqlalchemy/databases/mssql.py8
-rw-r--r--lib/sqlalchemy/databases/mysql.py14
-rw-r--r--lib/sqlalchemy/databases/postgres.py18
-rw-r--r--lib/sqlalchemy/databases/sqlite.py7
-rw-r--r--lib/sqlalchemy/databases/sybase.py12
7 files changed, 29 insertions, 45 deletions
diff --git a/lib/sqlalchemy/databases/access.py b/lib/sqlalchemy/databases/access.py
index d57c9fa9f..354a8c332 100644
--- a/lib/sqlalchemy/databases/access.py
+++ b/lib/sqlalchemy/databases/access.py
@@ -356,11 +356,11 @@ class AccessCompiler(compiler.DefaultCompiler):
"""Access uses "mod" instead of "%" """
return binary.operator == '%' and 'mod' or binary.operator
- def label_select_column(self, select, column):
+ def label_select_column(self, select, column, asfrom):
if isinstance(column, expression._Function):
- return column.label(column.name + "_" + hex(random.randint(0, 65535))[2:])
+ return column.label()
else:
- return super(AccessCompiler, self).label_select_column(select, column)
+ return super(AccessCompiler, self).label_select_column(select, column, asfrom)
function_rewrites = {'current_date': 'now',
'current_timestamp': 'now',
diff --git a/lib/sqlalchemy/databases/informix.py b/lib/sqlalchemy/databases/informix.py
index 247ab2d41..6b01bfc22 100644
--- a/lib/sqlalchemy/databases/informix.py
+++ b/lib/sqlalchemy/databases/informix.py
@@ -409,15 +409,6 @@ class InfoCompiler(compiler.DefaultCompiler):
def limit_clause(self, select):
return ""
- def __visit_label(self, label):
- # TODO: whats this method for ?
- if self.select_stack:
- self.typemap.setdefault(label.name.lower(), label.obj.type)
- if self.strings[label.obj]:
- self.strings[label] = self.strings[label.obj] + " AS " + label.name
- else:
- self.strings[label] = None
-
def visit_function( self , func ):
if func.name.lower() == 'current_date':
return "today"
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index 672f8d77c..469355083 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -339,8 +339,8 @@ class MSSQLExecutionContext(default.DefaultExecutionContext):
_ms_is_select = re.compile(r'\s*(?:SELECT|sp_columns)',
re.I | re.UNICODE)
- def is_select(self):
- return self._ms_is_select.match(self.statement) is not None
+ def returns_rows_text(self, statement):
+ return self._ms_is_select.match(statement) is not None
class MSSQLExecutionContext_pyodbc (MSSQLExecutionContext):
@@ -910,11 +910,11 @@ class MSSQLCompiler(compiler.DefaultCompiler):
else:
return super(MSSQLCompiler, self).visit_binary(binary, **kwargs)
- def label_select_column(self, select, column):
+ def label_select_column(self, select, column, asfrom):
if isinstance(column, expression._Function):
return column.label(None)
else:
- return super(MSSQLCompiler, self).label_select_column(select, column)
+ return super(MSSQLCompiler, self).label_select_column(select, column, asfrom)
function_rewrites = {'current_date': 'getdate',
'length': 'len',
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index 39bfc0bea..03b9a749c 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -1378,9 +1378,6 @@ def descriptor():
class MySQLExecutionContext(default.DefaultExecutionContext):
- _my_is_select = re.compile(r'\s*(?:SELECT|SHOW|DESCRIBE|XA +RECOVER)',
- re.I | re.UNICODE)
-
def post_exec(self):
if self.compiled.isinsert and not self.executemany:
if (not len(self._last_inserted_ids) or
@@ -1388,11 +1385,11 @@ class MySQLExecutionContext(default.DefaultExecutionContext):
self._last_inserted_ids = ([self.cursor.lastrowid] +
self._last_inserted_ids[1:])
- def is_select(self):
- return SELECT_RE.match(self.statement)
+ def returns_rows_text(self, statement):
+ return SELECT_RE.match(statement)
- def should_autocommit(self):
- return AUTOCOMMIT_RE.match(self.statement)
+ def should_autocommit_text(self, statement):
+ return AUTOCOMMIT_RE.match(statement)
class MySQLDialect(default.DefaultDialect):
@@ -1873,9 +1870,6 @@ class MySQLCompiler(compiler.DefaultCompiler):
if type_ is None:
return self.process(cast.clause)
- if self.stack and self.stack[-1].get('select'):
- # not sure if we want to set the typemap here...
- self.typemap.setdefault("CAST", cast.type)
return 'CAST(%s AS %s)' % (self.process(cast.clause), type_)
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 88ac0e202..1cae31b53 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -233,16 +233,24 @@ RETURNING_QUOTED_RE = re.compile(
class PGExecutionContext(default.DefaultExecutionContext):
- def is_select(self):
- m = SELECT_RE.match(self.statement)
- return m and (not m.group(1) or (RETURNING_RE.search(self.statement)
- and RETURNING_QUOTED_RE.match(self.statement)))
+ def returns_rows_text(self, statement):
+ m = SELECT_RE.match(statement)
+ return m and (not m.group(1) or (RETURNING_RE.search(statement)
+ and RETURNING_QUOTED_RE.match(statement)))
+
+ def returns_rows_compiled(self, compiled):
+ return isinstance(compiled.statement, expression.Selectable) or \
+ (
+ (compiled.isupdate or compiled.isinsert) and "postgres_returning" in compiled.statement.kwargs
+ )
def create_cursor(self):
# executing a default or Sequence standalone creates an execution context without a statement.
# so slightly hacky "if no statement assume we're server side" logic
+ # TODO: dont use regexp if Compiled is used ?
self.__is_server_side = \
- self.dialect.server_side_cursors and (self.statement is None or \
+ self.dialect.server_side_cursors and \
+ (self.statement is None or \
(SELECT_RE.match(self.statement) and not re.search(r'FOR UPDATE(?: NOWAIT)?\s*$', self.statement, re.I))
)
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py
index 19d0855ff..16dd9427c 100644
--- a/lib/sqlalchemy/databases/sqlite.py
+++ b/lib/sqlalchemy/databases/sqlite.py
@@ -185,8 +185,8 @@ class SQLiteExecutionContext(default.DefaultExecutionContext):
if not len(self._last_inserted_ids) or self._last_inserted_ids[0] is None:
self._last_inserted_ids = [self.cursor.lastrowid] + self._last_inserted_ids[1:]
- def is_select(self):
- return SELECT_REGEXP.match(self.statement)
+ def returns_rows_text(self, statement):
+ return SELECT_REGEXP.match(statement)
class SQLiteDialect(default.DefaultDialect):
supports_alter = False
@@ -343,9 +343,6 @@ class SQLiteCompiler(compiler.DefaultCompiler):
if self.dialect.supports_cast:
return super(SQLiteCompiler, self).visit_cast(cast)
else:
- if self.stack and self.stack[-1].get('select'):
- # not sure if we want to set the typemap here...
- self.typemap.setdefault("CAST", cast.type)
return self.process(cast.clause)
def limit_clause(self, select):
diff --git a/lib/sqlalchemy/databases/sybase.py b/lib/sqlalchemy/databases/sybase.py
index 87045d192..2209594ed 100644
--- a/lib/sqlalchemy/databases/sybase.py
+++ b/lib/sqlalchemy/databases/sybase.py
@@ -778,11 +778,11 @@ class SybaseSQLCompiler(compiler.DefaultCompiler):
else:
return super(SybaseSQLCompiler, self).visit_binary(binary)
- def label_select_column(self, select, column):
+ def label_select_column(self, select, column, asfrom):
if isinstance(column, expression._Function):
- return column.label(column.name + "_" + hex(random.randint(0, 65535))[2:])
+ return column.label(None)
else:
- return super(SybaseSQLCompiler, self).label_select_column(select, column)
+ return super(SybaseSQLCompiler, self).label_select_column(select, column, asfrom)
function_rewrites = {'current_date': 'getdate',
}
@@ -795,13 +795,7 @@ class SybaseSQLCompiler(compiler.DefaultCompiler):
cast = expression._Cast(func, SybaseDate_mxodbc)
# infinite recursion
# res = self.visit_cast(cast)
- if self.stack and self.stack[-1].get('select'):
- # not sure if we want to set the typemap here...
- self.typemap.setdefault("CAST", cast.type)
-# res = "CAST(%s AS %s)" % (self.process(cast.clause), self.process(cast.typeclause))
res = "CAST(%s AS %s)" % (res, self.process(cast.typeclause))
-# elif func.name.lower() == 'count':
-# res = 'count(*)'
return res
def for_update_clause(self, select):