quoting table names

This commit is contained in:
mdipierro
2013-06-25 15:40:06 -05:00
parent 29f0428889
commit 198dc8e0cd
2 changed files with 21 additions and 12 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.5.1-stable+timestamp.2013.06.25.09.09.16 Version 2.5.1-stable+timestamp.2013.06.25.15.39.19
+15 -6
View File
@@ -644,6 +644,8 @@ class BaseAdapter(ConnectionPool):
TRUE = 'T' TRUE = 'T'
FALSE = 'F' FALSE = 'F'
T_SEP = ' ' T_SEP = ' '
QUOTE_TEMPLATE = '"%s"'
types = { types = {
'boolean': 'CHAR(1)', 'boolean': 'CHAR(1)',
'string': 'CHAR(%(length)s)', 'string': 'CHAR(%(length)s)',
@@ -1361,7 +1363,7 @@ class BaseAdapter(ConnectionPool):
def expand(self, expression, field_type=None): def expand(self, expression, field_type=None):
if isinstance(expression, Field): if isinstance(expression, Field):
out = '%s.%s' % (expression.tablename, expression.name) out = '%s.%s' % (expression.table, expression.name)
if field_type == 'string' and not expression.type in ( if field_type == 'string' and not expression.type in (
'string','text','json','password'): 'string','text','json','password'):
out = 'CAST(%s AS %s)' % (out, self.types['text']) out = 'CAST(%s AS %s)' % (out, self.types['text'])
@@ -1448,6 +1450,7 @@ class BaseAdapter(ConnectionPool):
sql_v = ','.join(['%s=%s' % (field.name, sql_v = ','.join(['%s=%s' % (field.name,
self.expand(value, field.type)) \ self.expand(value, field.type)) \
for (field, value) in fields]) for (field, value) in fields])
tablename = "%s" % self.db[tablename]
return 'UPDATE %s SET %s%s;' % (tablename, sql_v, sql_w) return 'UPDATE %s SET %s%s;' % (tablename, sql_v, sql_w)
def update(self, tablename, query, fields): def update(self, tablename, query, fields):
@@ -2433,6 +2436,8 @@ class MySQLAdapter(BaseAdapter):
'big-reference': 'BIGINT, INDEX %(index_name)s (%(field_name)s), FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'big-reference': 'BIGINT, INDEX %(index_name)s (%(field_name)s), FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
} }
QUOTE_TEMPLATE = "`%s`"
def varquote(self,name): def varquote(self,name):
return varquote_aux(name,'`%s`') return varquote_aux(name,'`%s`')
@@ -3082,6 +3087,8 @@ class MSSQLAdapter(BaseAdapter):
drivers = ('pyodbc',) drivers = ('pyodbc',)
T_SEP = 'T' T_SEP = 'T'
QUOTE_TEMPLATE = "[%s]"
types = { types = {
'boolean': 'BIT', 'boolean': 'BIT',
'string': 'VARCHAR(%(length)s)', 'string': 'VARCHAR(%(length)s)',
@@ -8492,9 +8499,10 @@ class Table(object):
def __str__(self): def __str__(self):
if self._ot is not None: if self._ot is not None:
if 'Oracle' in str(type(self._db._adapter)): # <<< patch return self._db._adapter.QUOTE_TEMPLATE % self._ot
return '%s %s' % (self._ot, self._tablename) # <<< patch #if 'Oracle' in str(type(self._db._adapter)): # <<< patch
return '%s AS %s' % (self._ot, self._tablename) # return '%s %s' % (self._ot, self._tablename) # <<< patch
#return '%s AS %s' % (self._ot, self._tablename)
return self._tablename return self._tablename
def _drop(self, mode = ''): def _drop(self, mode = ''):
@@ -9959,7 +9967,7 @@ class Set(object):
fields = table._listify(update_fields,update=True) fields = table._listify(update_fields,update=True)
if not fields: if not fields:
raise SyntaxError("No fields to update") raise SyntaxError("No fields to update")
ret = db._adapter.update(tablename,self.query,fields) ret = db._adapter.update("%s" % table,self.query,fields)
ret and [f(self,update_fields) for f in table._after_update] ret and [f(self,update_fields) for f in table._after_update]
return ret return ret
@@ -9971,7 +9979,8 @@ class Set(object):
table = self.db[tablename] table = self.db[tablename]
fields = table._listify(update_fields,update=True) fields = table._listify(update_fields,update=True)
if not fields: raise SyntaxError("No fields to update") if not fields: raise SyntaxError("No fields to update")
ret = self.db._adapter.update(tablename,self.query,fields)
ret = self.db._adapter.update("%s" % table,self.query,fields)
return ret return ret
def validate_and_update(self, **update_fields): def validate_and_update(self, **update_fields):