Ticket #7600: postgres_quoting.patch
| File postgres_quoting.patch, 2.2 KB (added by felix.schwarz@…, 4 years ago) |
|---|
-
trac/db/postgres_backend.py
66 66 cursor = cnx.cursor() 67 67 if cnx.schema: 68 68 cursor.execute('CREATE SCHEMA "%s"' % cnx.schema) 69 cursor.execute('SET search_path TO %s', (cnx.schema,))69 cursor.execute('SET search_path TO "%s"', (cnx.schema,)) 70 70 from trac.db_default import schema 71 71 for table in schema: 72 72 for stmt in self.to_sql(table): … … 74 74 cnx.commit() 75 75 76 76 def to_sql(self, table): 77 sql = [ "CREATE TABLE %s ("% table.name]77 sql = ['CREATE TABLE "%s" (' % table.name] 78 78 coldefs = [] 79 79 for column in table.columns: 80 80 ctype = column.type 81 81 if column.auto_increment: 82 ctype = "SERIAL"82 ctype = 'SERIAL' 83 83 if len(table.key) == 1 and column.name in table.key: 84 ctype += " PRIMARY KEY"85 coldefs.append( " %s %s"% (column.name, ctype))84 ctype += ' PRIMARY KEY' 85 coldefs.append(' "%s" %s' % (column.name, ctype)) 86 86 if len(table.key) > 1: 87 coldefs.append( " CONSTRAINT %s_pk PRIMARY KEY (%s)"88 % (table.name, ' ,'.join(table.key)))87 coldefs.append(' CONSTRAINT "%s_pk" PRIMARY KEY ("%s")' 88 % (table.name, '","'.join(table.key))) 89 89 sql.append(',\n'.join(coldefs) + '\n)') 90 90 yield '\n'.join(sql) 91 91 for index in table.indices: 92 92 unique = index.unique and 'UNIQUE' or '' 93 yield "CREATE %s INDEX %s_%s_idx ON %s (%s)"% (unique, table.name,93 yield 'CREATE "%s" INDEX "%s_%s_idx" ON "%s" ("%s")' % (unique, table.name, 94 94 '_'.join(index.columns), table.name, ','.join(index.columns)) 95 95 96 96 … … 159 159 def like(self): 160 160 # Temporary hack needed for the case-insensitive string matching in the 161 161 # search module 162 return "ILIKE %sESCAPE '/'"162 return "ILIKE \"%s\" ESCAPE '/'" 163 163 164 164 def like_escape(self, text): 165 165 return _like_escape_re.sub(r'/\1', text)
