Commits

Mike Bayer committed e2b0345 Merge

- merge

  • Participants
  • Parent commits 0505949, 358f38f

Comments (0)

Files changed (10)

     exceptions, "could not receive data from server"
     [ticket:2044]
 
+  - Added RESERVED_WORDS for postgresql dialect. [ticket:2092]
+
+- informix
+
+- Added RESERVED_WORDS informix dialect. [ticket:2092]
+
 - mysql
   - oursql dialect accepts the same "ssl" arguments in 
     create_engine() as that of MySQLdb.  [ticket:2047]

File lib/sqlalchemy/dialects/informix/base.py

 from sqlalchemy.engine import default, reflection
 from sqlalchemy import types as sqltypes
 
+RESERVED_WORDS = set(
+    ["abs", "absolute", "access", "access_method", "acos", "active", "add",
+    "address", "add_months", "admin", "after", "aggregate", "alignment",
+    "all", "allocate", "all_rows", "altere", "and", "ansi", "any", "append",
+    "array", "as", "asc", "ascii", "asin", "at", "atan", "atan2", "attach",
+    "attributes", "audit", "authentication", "authid", "authorization",
+    "authorized", "auto", "autofree", "auto_reprepare", "auto_stat_mode",
+    "avg", "avoid_execute", "avoid_fact", "avoid_full", "avoid_hash",
+    "avoid_index", "avoid_index_sj", "avoid_multi_index", "avoid_nl",
+    "avoid_star_join", "avoid_subqf", "based", "before", "begin",
+    "between", "bigint", "bigserial", "binary", "bitand", "bitandnot",
+    "bitnot", "bitor", "bitxor", "blob", "blobdir", "boolean", "both",
+    "bound_impl_pdq", "buffered", "builtin", "by", "byte", "cache", "call",
+    "cannothash", "cardinality", "cascade", "case", "cast", "ceil", "char",
+    "character", "character_length", "char_length", "check", "class",
+    "class_origin", "client", "clob", "clobdir", "close", "cluster",
+    "clustersize", "cobol", "codeset", "collation", "collection",
+    "column", "columns", "commit", "committed", "commutator", "component",
+    "components", "concat", "concurrent", "connect", "connection",
+    "connection_name", "connect_by_iscycle", "connect_by_isleaf",
+    "connect_by_rootconst", "constraint", "constraints", "constructor",
+    "context", "continue", "copy", "cos", "costfunc", "count", "crcols",
+    "create", "cross", "current", "current_role", "currval", "cursor",
+    "cycle", "database", "datafiles", "dataskip", "date", "datetime",
+    "day", "dba", "dbdate", "dbinfo", "dbpassword", "dbsecadm",
+    "dbservername", "deallocate", "debug", "debugmode", "debug_env", "dec",
+    "decimal", "declare", "decode", "decrypt_binary", "decrypt_char",
+    "dec_t", "default", "default_role", "deferred", "deferred_prepare",
+    "define", "delay", "delete", "deleting", "delimited", "delimiter",
+    "deluxe", "desc", "describe", "descriptor", "detach", "diagnostics",
+    "directives", "dirty", "disable", "disabled", "disconnect", "disk",
+    "distinct", "distributebinary", "distributesreferences",
+    "distributions", "document", "domain", "donotdistribute", "dormant",
+    "double", "drop", "dtime_t", "each", "elif", "else", "enabled",
+    "encryption", "encrypt_aes", "encrypt_tdes", "end", "enum",
+    "environment", "error", "escape", "exception", "exclusive", "exec",
+    "execute", "executeanywhere", "exemption", "exists", "exit", "exp",
+    "explain", "explicit", "express", "expression", "extdirectives",
+    "extend", "extent", "external", "fact", "false", "far", "fetch",
+    "file", "filetoblob", "filetoclob", "fillfactor", "filtering", "first",
+    "first_rows", "fixchar", "fixed", "float", "floor", "flush", "for",
+    "force", "forced", "force_ddl_exec", "foreach", "foreign", "format",
+    "format_units", "fortran", "found", "fraction", "fragment",
+    "fragments", "free", "from", "full", "function", "general", "get",
+    "gethint", "global", "go", "goto", "grant", "greaterthan",
+    "greaterthanorequal", "group", "handlesnulls", "hash", "having", "hdr",
+    "hex", "high", "hint", "hold", "home", "hour", "idslbacreadarray",
+    "idslbacreadset", "idslbacreadtree", "idslbacrules",
+    "idslbacwritearray", "idslbacwriteset", "idslbacwritetree",
+    "idssecuritylabel", "if", "ifx_auto_reprepare", "ifx_batchedread_table",
+    "ifx_int8_t", "ifx_lo_create_spec_t", "ifx_lo_stat_t", "immediate",
+    "implicit", "implicit_pdq", "in", "inactive", "increment", "index",
+    "indexes", "index_all", "index_sj", "indicator", "informix", "init",
+    "initcap", "inline", "inner", "inout", "insert", "inserting", "instead",
+    "int", "int8", "integ", "integer", "internal", "internallength",
+    "interval", "into", "intrvl_t", "is", "iscanonical", "isolation",
+    "item", "iterator", "java", "join", "keep", "key", "label", "labeleq",
+    "labelge", "labelglb", "labelgt", "labelle", "labellt", "labellub",
+    "labeltostring", "language", "last", "last_day", "leading", "left",
+    "length", "lessthan", "lessthanorequal", "let", "level", "like",
+    "limit", "list", "listing", "load", "local", "locator", "lock", "locks",
+    "locopy", "loc_t", "log", "log10", "logn", "long", "loop", "lotofile",
+    "low", "lower", "lpad", "ltrim", "lvarchar", "matched", "matches",
+    "max", "maxerrors", "maxlen", "maxvalue", "mdy", "median", "medium",
+    "memory", "memory_resident", "merge", "message_length", "message_text",
+    "middle", "min", "minute", "minvalue", "mod", "mode", "moderate",
+    "modify", "module", "money", "month", "months_between", "mounting",
+    "multiset", "multi_index", "name", "nchar", "negator", "new", "next",
+    "nextval", "next_day", "no", "nocache", "nocycle", "nomaxvalue",
+    "nomigrate", "nominvalue", "none", "non_dim", "non_resident", "noorder",
+    "normal", "not", "notemplatearg", "notequal", "null", "nullif",
+    "numeric", "numrows", "numtodsinterval", "numtoyminterval", "nvarchar",
+    "nvl", "octet_length", "of", "off", "old", "on", "online", "only",
+    "opaque", "opclass", "open", "optcompind", "optical", "optimization",
+    "option", "or", "order", "ordered", "out", "outer", "output",
+    "override", "page", "parallelizable", "parameter", "partition",
+    "pascal", "passedbyvalue", "password", "pdqpriority", "percaltl_cos",
+    "pipe", "pli", "pload", "policy", "pow", "power", "precision",
+    "prepare", "previous", "primary", "prior", "private", "privileges",
+    "procedure", "properties", "public", "put", "raise", "range", "raw",
+    "read", "real", "recordend", "references", "referencing", "register",
+    "rejectfile", "relative", "release", "remainder", "rename",
+    "reoptimization", "repeatable", "replace", "replication", "reserve",
+    "resolution", "resource", "restart", "restrict", "resume", "retain",
+    "retainupdatelocks", "return", "returned_sqlstate", "returning",
+    "returns", "reuse", "revoke", "right", "robin", "role", "rollback",
+    "rollforward", "root", "round", "routine", "row", "rowid", "rowids",
+    "rows", "row_count", "rpad", "rtrim", "rule", "sameas", "samples",
+    "sampling", "save", "savepoint", "schema", "scroll", "seclabel_by_comp",
+    "seclabel_by_name", "seclabel_to_char", "second", "secondary",
+    "section", "secured", "security", "selconst", "select", "selecting",
+    "selfunc", "selfuncargs", "sequence", "serial", "serial8",
+    "serializable", "serveruuid", "server_name", "session", "set",
+    "setsessionauth", "share", "short", "siblings", "signed", "sin",
+    "sitename", "size", "skall", "skinhibit", "skip", "skshow",
+    "smallfloat", "smallint", "some", "specific", "sql", "sqlcode",
+    "sqlcontext", "sqlerror", "sqlstate", "sqlwarning", "sqrt",
+    "stability", "stack", "standard", "start", "star_join", "statchange",
+    "statement", "static", "statistics", "statlevel", "status", "stdev",
+    "step", "stop", "storage", "store", "strategies", "string",
+    "stringtolabel", "struct", "style", "subclass_origin", "substr",
+    "substring", "sum", "support", "sync", "synonym", "sysdate",
+    "sysdbclose", "sysdbopen", "system", "sys_connect_by_path", "table",
+    "tables", "tan", "task", "temp", "template", "test", "text", "then",
+    "time", "timeout", "to", "today", "to_char", "to_date",
+    "to_dsinterval", "to_number", "to_yminterval", "trace", "trailing",
+    "transaction", "transition", "tree", "trigger", "triggers", "trim",
+    "true", "trunc", "truncate", "trusted", "type", "typedef", "typeid",
+    "typename", "typeof", "uid", "uncommitted", "under", "union",
+    "unique", "units", "unknown", "unload", "unlock", "unsigned",
+    "update", "updating", "upon", "upper", "usage", "use",
+    "uselastcommitted", "user", "use_hash", "use_nl", "use_subqf",
+    "using", "value", "values", "var", "varchar", "variable", "variance",
+    "variant", "varying", "vercols", "view", "violations", "void",
+    "volatile", "wait", "warning", "weekday", "when", "whenever", "where",
+    "while", "with", "without", "work", "write", "writedown", "writeup",
+    "xadatasource", "xid", "xload", "xunload", "year"
+    ])
 
 class InfoDateTime(sqltypes.DateTime):
     def bind_processor(self, dialect):
             text += "CONSTRAINT %s " % self.preparer.format_constraint(constraint)
         return text
 
+class InformixIdentifierPreparer(compiler.IdentifierPreparer):
+
+    reserved_words = RESERVED_WORDS
+
 
 class InformixDialect(default.DefaultDialect):
     name = 'informix'
     ddl_compiler = InfoDDLCompiler
     colspecs = colspecs
     ischema_names = ischema_names
+    preparer = InformixIdentifierPreparer
     default_paramstyle = 'qmark'
 
     def __init__(self, has_transactions=True, *args, **kwargs):

File lib/sqlalchemy/dialects/postgresql/base.py

         CHAR, TEXT, FLOAT, NUMERIC, \
         DATE, BOOLEAN
 
+RESERVED_WORDS = set(
+    ["all", "analyse", "analyze", "and", "any", "array", "as", "asc",
+    "asymmetric", "both", "case", "cast", "check", "collate", "column",
+    "constraint", "create", "current_catalog", "current_date",
+    "current_role", "current_time", "current_timestamp", "current_user",
+    "default", "deferrable", "desc", "distinct", "do", "else", "end",
+    "except", "false", "fetch", "for", "foreign", "from", "grant", "group",
+    "having", "in", "initially", "intersect", "into", "leading", "limit",
+    "localtime", "localtimestamp", "new", "not", "null", "off", "offset",
+    "old", "on", "only", "or", "order", "placing", "primary", "references",
+    "returning", "select", "session_user", "some", "symmetric", "table",
+    "then", "to", "trailing", "true", "union", "unique", "user", "using",
+    "variadic", "when", "where", "window", "with", "authorization",
+    "between", "binary", "cross", "current_schema", "freeze", "full",
+    "ilike", "inner", "is", "isnull", "join", "left", "like", "natural",
+    "notnull", "outer", "over", "overlaps", "right", "similar", "verbose"
+    ])
+
 _DECIMAL_TYPES = (1231, 1700)
 _FLOAT_TYPES = (700, 701, 1021, 1022)
 _INT_TYPES = (20, 21, 23, 26, 1005, 1007, 1016)
 
 
 class PGIdentifierPreparer(compiler.IdentifierPreparer):
+
+    reserved_words = RESERVED_WORDS
+
     def _unquote_identifier(self, value):
         if value[0] == self.initial_quote:
             value = value[1:-1].\

File lib/sqlalchemy/util/langhelpers.py

 import itertools
 import inspect
 import operator
+import sys
 import types
 import warnings
 from compat import update_wrapper, set_types, threading

File test/base/test_dependency.py

 from test.lib import TestBase
 from test.lib.testing import assert_raises, eq_
 from test.lib.util import conforms_partial_ordering
-from sqlalchemy import exc, util
+from sqlalchemy import exc
 
 class DependencySortTest(TestBase):
 

File test/dialect/test_mysql.py

 from test.lib.engines import utf8_engine
 import datetime
 
+class CompileTest(TestBase, AssertsCompiledSQL):
+
+    __dialect__ = mysql.dialect()
+
+    def test_reserved_words(self):
+        table = Table("mysql_table", MetaData(),
+            Column("col1", Integer),
+            Column("master_ssl_verify_server_cert", Integer))
+        x = select([table.c.col1, table.c.master_ssl_verify_server_cert])
+
+        self.assert_compile(x, 
+            '''SELECT mysql_table.col1, mysql_table.`master_ssl_verify_server_cert` FROM mysql_table''')
 
 class DialectTest(TestBase):
     __only_on__ = 'mysql'

File test/dialect/test_postgresql.py

                                     'anon_1 FROM t' % (field,
                                     compiled_expr))
 
+    def test_reserved_words(self):
+        table = Table("pg_table", MetaData(),
+            Column("col1", Integer),
+            Column("variadic", Integer))
+        x = select([table.c.col1, table.c.variadic])
+
+        self.assert_compile(x, 
+            '''SELECT pg_table.col1, pg_table."variadic" FROM pg_table''')
+
+
 class FloatCoercionTest(TablesTest, AssertsExecutionResults):
     __only_on__ = 'postgresql'
     __dialect__ = postgresql.dialect()

File test/ext/test_declarative.py

 import sqlalchemy as sa
 from test.lib import testing
 from sqlalchemy import MetaData, Integer, String, ForeignKey, \
-    ForeignKeyConstraint, asc, Index
+    ForeignKeyConstraint, Index
 from test.lib.schema import Table, Column
 from sqlalchemy.orm import relationship, create_session, class_mapper, \
     joinedload, configure_mappers, backref, clear_mappers, \

File test/sql/test_query.py

     def teardown_class(cls):
         metadata.drop_all()
 
+    @testing.skip_if(lambda: testing.against('postgresql'), "psycopg2 2.4 no longer accepts % in bind placeholders")
     def test_single_roundtrip(self):
         percent_table.insert().execute(
             {'percent%':5, 'spaces % more spaces':12},
         )
         self._assert_table()
 
+    @testing.skip_if(lambda: testing.against('postgresql'), "psycopg2 2.4 no longer accepts % in bind placeholders")
     @testing.crashes('mysql+mysqldb', 'MySQLdb handles executemany() inconsistently vs. execute()')
     def test_executemany_roundtrip(self):
         percent_table.insert().execute(

File test/sql/test_quote.py

         self.assert_compile(x,
             '''SELECT "SomeLabel" FROM (SELECT 'FooCol' AS "SomeLabel" FROM "ImATable")''')
 
+    def test_reserved_words(self):
+        metadata = MetaData()
+        table = Table("ImATable", metadata,
+            Column("col1", Integer),
+            Column("from", Integer, key="morf"),
+            Column("louisville", Integer),
+            Column("order", Integer))
+        x = select([table.c.col1, table.c.morf, table.c.louisville, table.c.order])
+
+        self.assert_compile(x, 
+            '''SELECT "ImATable".col1, "ImATable"."from", "ImATable".louisville, "ImATable"."order" FROM "ImATable"''')
+        
 
 class PreparerTest(TestBase):
     """Test the db-agnostic quoting services of IdentifierPreparer."""