(self, curs, new_table_name = None)
return sql
Generate creation SQL.
Generate creation SQL.
Generate creation SQL .
def get_create_sql(self, curs, new_table_name = None):
        """Generate creation SQL."""
        if not new_table_name:
            sql = self.defn
            table = self.table_name
        else:
            idrx = r'''([a-z0-9._]+|"([^"]+|"")+")+'''
            # fixme: broken / quoting
            rx = r"\bTO[ ]" + idrx
            rc = re.compile(rx, re.X)
            m = rc.search(self.defn)
            if not m:
                raise Exception('Cannot find table name in rule')
            old_tbl = m.group(1)
            new_tbl = quote_fqident(new_table_name)
            sql = self.defn.replace(old_tbl, new_tbl)
            table = new_table_name
        if self.enabled != 'O':
            # O - rule fires in origin and local modes
            # D - rule is disabled
            # R - rule fires in replica mode
            # A - rule fires always
            action = {'R': 'ENABLE REPLICA',
                      'A': 'ENABLE ALWAYS',
                      'D': 'DISABLE'} [self.enabled]
            sql += ('\nALTER TABLE %s %s RULE %s;' % (table, action, self.name))
        return sql
def get_create_sql ( self , curs , new_table_name = None ) : if not new_table_name : sql = self . defn table = self . table_name else : idrx = r'''([a-z0-9._]+|"([^"]+|"")+")+''' # fixme: broken / quoting rx = r"\bTO[ ]" + idrx rc = re . compile ( rx , re . X ) m = rc . search ( self . defn ) if not m : raise Exception ( 'Cannot find table name in rule' ) old_tbl = m . group ( 1 ) new_tbl = quote_fqident ( new_table_name ) sql = self . defn . replace ( old_tbl , new_tbl ) table = new_table_name if self . enabled != 'O' : # O - rule fires in origin and local modes # D - rule is disabled # R - rule fires in replica mode # A - rule fires always action = { 'R' : 'ENABLE REPLICA' , 'A' : 'ENABLE ALWAYS' , 'D' : 'DISABLE' } [ self . enabled ] sql += ( '\nALTER TABLE %s %s RULE %s;' % ( table , action , self . name ) ) return sql