From: Jim Phares Date: Tue, 15 Mar 2011 20:56:45 +0000 (-0400) Subject: Informix and postgresql reserved words changes -- almost done. X-Git-Tag: rel_0_7b3~23^2^2~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fde2a7f8fe5fd16891ddff99511e2ed3c8eb9ab6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Informix and postgresql reserved words changes -- almost done. --- diff --git a/CHANGES b/CHANGES index 1a7212f874..0f0a2bca8e 100644 --- a/CHANGES +++ b/CHANGES @@ -458,6 +458,12 @@ CHANGES 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] diff --git a/lib/sqlalchemy/dialects/informix/base.py b/lib/sqlalchemy/dialects/informix/base.py index 1ea8d4e391..f6749e5cf3 100644 --- a/lib/sqlalchemy/dialects/informix/base.py +++ b/lib/sqlalchemy/dialects/informix/base.py @@ -20,6 +20,124 @@ from sqlalchemy.sql import compiler, text 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): @@ -213,6 +331,10 @@ class InfoDDLCompiler(compiler.DDLCompiler): text += "CONSTRAINT %s " % self.preparer.format_constraint(constraint) return text +class InformixIdentifierPreparer(compiler.IdentifierPreparer): + + reserved_words = RESERVED_WORDS + class InformixDialect(default.DefaultDialect): name = 'informix' @@ -224,6 +346,7 @@ class InformixDialect(default.DefaultDialect): ddl_compiler = InfoDDLCompiler colspecs = colspecs ischema_names = ischema_names + preparer = InformixIdentifierPreparer default_paramstyle = 'qmark' def __init__(self, has_transactions=True, *args, **kwargs): diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index b6a6357b5f..f7b3490a3a 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -101,6 +101,24 @@ from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \ 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) @@ -649,6 +667,9 @@ class PGTypeCompiler(compiler.GenericTypeCompiler): class PGIdentifierPreparer(compiler.IdentifierPreparer): + + reserved_words = RESERVED_WORDS + def _unquote_identifier(self, value): if value[0] == self.initial_quote: value = value[1:-1].\ diff --git a/test/dialect/test_mysql.py b/test/dialect/test_mysql.py index a805d9838f..d199152665 100644 --- a/test/dialect/test_mysql.py +++ b/test/dialect/test_mysql.py @@ -16,6 +16,18 @@ from test.lib import * 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' diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 149421404a..020a92bf37 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -220,6 +220,16 @@ class CompileTest(TestBase, AssertsCompiledSQL): '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() diff --git a/test/sql/test_quote.py b/test/sql/test_quote.py index 50adad7512..b31e7dfb4e 100644 --- a/test/sql/test_quote.py +++ b/test/sql/test_quote.py @@ -169,6 +169,18 @@ class QuoteTest(TestBase, AssertsCompiledSQL): 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."""