Edgewall Software

Ticket #7600: postgres_quoting.patch

File postgres_quoting.patch, 2.2 KB (added by felix.schwarz@…, 4 years ago)

patch against 0.11

  • trac/db/postgres_backend.py

     
    6666        cursor = cnx.cursor() 
    6767        if cnx.schema: 
    6868            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,)) 
    7070        from trac.db_default import schema 
    7171        for table in schema: 
    7272            for stmt in self.to_sql(table): 
     
    7474        cnx.commit() 
    7575 
    7676    def to_sql(self, table): 
    77         sql = ["CREATE TABLE %s (" % table.name] 
     77        sql = ['CREATE TABLE "%s" (' % table.name] 
    7878        coldefs = [] 
    7979        for column in table.columns: 
    8080            ctype = column.type 
    8181            if column.auto_increment: 
    82                 ctype = "SERIAL" 
     82                ctype = 'SERIAL' 
    8383            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)) 
    8686        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))) 
    8989        sql.append(',\n'.join(coldefs) + '\n)') 
    9090        yield '\n'.join(sql) 
    9191        for index in table.indices: 
    9292            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,  
    9494                   '_'.join(index.columns), table.name, ','.join(index.columns)) 
    9595 
    9696 
     
    159159    def like(self): 
    160160        # Temporary hack needed for the case-insensitive string matching in the 
    161161        # search module 
    162         return "ILIKE %s ESCAPE '/'" 
     162        return "ILIKE \"%s\" ESCAPE '/'" 
    163163 
    164164    def like_escape(self, text): 
    165165        return _like_escape_re.sub(r'/\1', text)