summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/postgres.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-08-31 18:58:22 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-08-31 18:58:22 +0000
commit0c7250a4740b26875d94fc9a1cb714fc970ea700 (patch)
tree79f3661459b4aab78681ae8c42f51944858ef0e9 /lib/sqlalchemy/databases/postgres.py
parent2e077dc627bfbc9f81cdb363a1ea1acf32f4cfe9 (diff)
downloadsqlalchemy-0c7250a4740b26875d94fc9a1cb714fc970ea700.tar.gz
- added case_sensitive argument to MetaData, Table, Column, determines
itself automatically based on if a parent schemaitem has a non-None setting for the flag, or if not, then whether the identifier name is all lower case or not. when set to True, quoting is applied to identifiers with mixed or uppercase identifiers. quoting is also applied automatically in all cases to identifiers that are known to be reserved words or contain other non-standard characters. various database dialects can override all of this behavior, but currently they are all using the default behavior. tested with postgres, mysql, sqlite. needs more testing with firebird, oracle, ms-sql. part of the ongoing work with [ticket:155]
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r--lib/sqlalchemy/databases/postgres.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 19ec95a13..c7a03629d 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -171,10 +171,6 @@ pg1_ischema_names.update({
'time' : PG1Time
})
-reserved_words = util.Set(['all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'authorization', 'between', 'binary', 'both', 'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'cross', 'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user', 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false', 'for', 'foreign', 'freeze', 'from', 'full', 'grant', 'group', 'having', 'ilike', 'in', 'initially', 'inner', 'intersect', 'into', 'is', 'isnull', 'join', 'leading', 'left', 'like', 'limit', 'localtime', 'localtimestamp', 'natural', 'new', 'not', 'notnull', 'null', 'off', 'offset', 'old', 'on', 'only', 'or', 'order', 'outer', 'overlaps', 'placing', 'primary', 'references', 'right', 'select', 'session_user', 'similar', 'some', 'symmetric', 'table', 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'verbose', 'when', 'where'])
-
-legal_characters = util.Set(string.ascii_lowercase + string.digits + '_$')
-illegal_initial_characters = util.Set(string.digits + '$')
def engine(opts, **params):
return PGSQLEngine(opts, **params)
@@ -376,7 +372,7 @@ class PGDialect(ansisql.ANSIDialect):
colargs= []
if default is not None:
colargs.append(PassiveDefault(sql.text(default)))
- table.append_item(schema.Column(name, coltype, nullable=nullable, natural_case=natural_case, *colargs))
+ table.append_item(schema.Column(name, coltype, nullable=nullable, case_sensitive=not natural_case, *colargs))
if not found_table:
@@ -444,11 +440,11 @@ class PGDialect(ansisql.ANSIDialect):
if referred_schema is not None:
natural_case_schema = preparer._is_natural_case(referred_schema)
schema.Table(referred_table, table.metadata, autoload=True, schema=referred_schema,
- autoload_with=connection, natural_case=natural_case, natural_case_schema = natural_case_schema)
+ autoload_with=connection, case_sensitive= not natural_case, case_sensitive_schema = not natural_case_schema)
for column in referred_columns:
refspec.append(".".join([referred_schema, referred_table, column]))
else:
- schema.Table(referred_table, table.metadata, autoload=True, autoload_with=connection, natural_case=natural_case)
+ schema.Table(referred_table, table.metadata, autoload=True, autoload_with=connection, case_sensitive=not natural_case)
for column in referred_columns:
refspec.append(".".join([referred_table, column]))
@@ -533,9 +529,9 @@ class PGDefaultRunner(ansisql.ANSIDefaultRunner):
# TODO: this has to build into the Sequence object so we can get the quoting
# logic from it
if sch is not None:
- exc = "select nextval('%s.%s_%s_seq')" % (sch, column.table.name, column.name)
+ exc = "select nextval('\"%s.%s_%s_seq\"')" % (sch, column.table.name, column.name)
else:
- exc = "select nextval('%s_%s_seq')" % (column.table.name, column.name)
+ exc = "select nextval('\"%s_%s_seq\"')" % (column.table.name, column.name)
c = self.proxy(exc)
return c.fetchone()[0]
else:
@@ -553,13 +549,6 @@ class PGDefaultRunner(ansisql.ANSIDefaultRunner):
class PGIdentifierPreparer(ansisql.ANSIIdentifierPreparer):
def _fold_identifier_case(self, value):
return value.lower()
- def _requires_quotes(self, value, natural_case):
- if natural_case:
- value = self._fold_identifier_case(str(value))
- retval = bool(len([x for x in str(value) if x not in legal_characters]))
- if not retval and (value[0] in illegal_initial_characters or value in reserved_words):
- retval = True
- return retval
def _unquote_identifier(self, value):
if value[0] == self.initial_quote:
value = value[1:-1].replace('""','"')