return '%s NOT ILIKE %s' % (self.process(binary.left), self.process(binary.right)) \
+ (escape and ' ESCAPE \'%s\'' % escape or '')
- def post_process_text(self, text):
- if '%%' in text:
- util.warn("The SQLAlchemy postgresql dialect now automatically escapes '%' in text() expressions to '%%'.")
- return text.replace('%', '%%')
-
def visit_sequence(self, seq):
if seq.optional:
return None
else:
return None
+
class PGTypeCompiler(compiler.GenericTypeCompiler):
def visit_INET(self, type_):
return "INET"
def visit_ARRAY(self, type_):
return self.process(type_.item_type) + '[]'
+
class PGIdentifierPreparer(compiler.IdentifierPreparer):
def _unquote_identifier(self, value):
if value[0] == self.initial_quote:
- value = value[1:-1].replace('""','"')
+ value = value[1:-1].replace(self.escape_to_quote, self.escape_quote)
return value
- def _escape_identifier(self, value):
- value = value.replace('"', '""')
- # TODO: might want to move this to psycopg2 + pg8000 individually
- return value.replace('%', '%%')
class PGInspector(reflection.Inspector):
import decimal
from sqlalchemy import util
from sqlalchemy import types as sqltypes
-from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler
+from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, PGIdentifierPreparer
class _PGNumeric(sqltypes.Numeric):
def bind_processor(self, dialect):
return value
return process
+
class PostgreSQL_pg8000ExecutionContext(default.DefaultExecutionContext):
pass
+
class PostgreSQL_pg8000Compiler(PGCompiler):
def visit_mod(self, binary, **kw):
return self.process(binary.left) + " %% " + self.process(binary.right)
-
+
+ def post_process_text(self, text):
+ if '%%' in text:
+ util.warn("The SQLAlchemy postgresql dialect now automatically escapes '%' in text() "
+ "expressions to '%%'.")
+ return text.replace('%', '%%')
+
+
+class PostgreSQL_pg8000IdentifierPreparer(PGIdentifierPreparer):
+ def _escape_identifier(self, value):
+ value = value.replace(self.escape_quote, self.escape_to_quote)
+ return value.replace('%', '%%')
+
class PostgreSQL_pg8000(PGDialect):
driver = 'pg8000'
supports_sane_multi_rowcount = False
execution_ctx_cls = PostgreSQL_pg8000ExecutionContext
statement_compiler = PostgreSQL_pg8000Compiler
+ preparer = PostgreSQL_pg8000IdentifierPreparer
colspecs = util.update_copy(
PGDialect.colspecs,
from sqlalchemy.sql import expression
from sqlalchemy.sql import operators as sql_operators
from sqlalchemy import types as sqltypes
-from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler
+from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, PGIdentifierPreparer
class _PGNumeric(sqltypes.Numeric):
def bind_processor(self, dialect):
else:
return base.ResultProxy(self)
+
class PostgreSQL_psycopg2Compiler(PGCompiler):
def visit_mod(self, binary, **kw):
return self.process(binary.left) + " %% " + self.process(binary.right)
def post_process_text(self, text):
return text.replace('%', '%%')
+
+class PostgreSQL_psycopg2IdentifierPreparer(PGIdentifierPreparer):
+ def _escape_identifier(self, value):
+ value = value.replace(self.escape_quote, self.escape_to_quote)
+ return value.replace('%', '%%')
+
+
class PostgreSQL_psycopg2(PGDialect):
driver = 'psycopg2'
supports_unicode_statements = False
supports_sane_multi_rowcount = False
execution_ctx_cls = PostgreSQL_psycopg2ExecutionContext
statement_compiler = PostgreSQL_psycopg2Compiler
+ preparer = PostgreSQL_psycopg2IdentifierPreparer
colspecs = util.update_copy(
PGDialect.colspecs,
"""
from sqlalchemy.connectors.zxJDBC import ZxJDBCConnector
-from sqlalchemy.dialects.postgresql.base import PGCompiler, PGDialect
-
-class PostgreSQL_jdbcCompiler(PGCompiler):
-
- def post_process_text(self, text):
- # Don't escape '%' like PGCompiler
- return text
-
+from sqlalchemy.dialects.postgresql.base import PGDialect
class PostgreSQL_jdbc(ZxJDBCConnector, PGDialect):
- statement_compiler = PostgreSQL_jdbcCompiler
-
jdbc_db_name = 'postgresql'
jdbc_driver_name = 'org.postgresql.Driver'