Example #1
0
    def sql_create_function_delete(self, name, table,
                                   column, aggtable, action,
                                   where_clause=None,
                                   agg_key=None):
        """Return a SQL statement to create a FUNCTION

        name : functions name
        column : column name
        aggtable : the table where data will be stored
        action : action that fired the trigger
        """
        tpl = os.path.join(os.path.dirname(__file__), 'templates')
        env = Environment(loader=FileSystemLoader(tpl))
        template = env.get_template('pg_function_delete.sql')

        if agg_key is None:
            actions = "agg_count=agg_count-1"
        else:
            actions = "agg_count_{0}=agg_count_{0}-1".format(agg_key)

        if where_clause:
            where_clause = parse_where_clause(where_clause, table, "OLD")

        tmp = template.render(name=name,
                              table=aggtable,
                              column=column,
                              actions=actions,
                              where_clause=where_clause)
        return tmp
Example #2
0
    def sql_create_function_delete(self,
                                   name,
                                   table,
                                   column,
                                   aggtable,
                                   action,
                                   where_clause=None,
                                   agg_key=None):
        """Return a SQL statement to create a FUNCTION

        name : functions name
        column : column name
        aggtable : the table where data will be stored
        action : action that fired the trigger
        """
        tpl = os.path.join(os.path.dirname(__file__), 'templates')
        env = Environment(loader=FileSystemLoader(tpl))
        template = env.get_template('pg_function_delete.sql')

        if agg_key is None:
            actions = "agg_count=agg_count-1"
        else:
            actions = "agg_count_{0}=agg_count_{0}-1".format(agg_key)

        if where_clause:
            where_clause = parse_where_clause(where_clause, table, "OLD")

        tmp = template.render(name=name,
                              table=aggtable,
                              column=column,
                              actions=actions,
                              where_clause=where_clause)
        return tmp
Example #3
0
    def sql_create_function_insert(self, name, table,
                                   column, aggtable, action,
                                   where_clause=None,
                                   agg_key=None):
        """Return a SQL statement to create a FUNCTION

        name : function name
        table (string) : the originate of datas
        column : column name
        aggtable : the table where data will be stored
        """
        tpl = os.path.join(os.path.dirname(__file__), 'templates')
        env = Environment(loader=FileSystemLoader(tpl))
        template = env.get_template('pg_function_insert.sql')
        if agg_key is None:
            action_key = "agg_count"
            actions = "agg_count=agg_count+1"
        else:
            action_key = "agg_count_{0}".format(agg_key)
        actions = "{0}={0}+1".format(action_key)
        insert_values = 1
        if where_clause:
            where_clause = parse_where_clause(where_clause, table, "NEW")
        tmp = template.render(name=name,
                              table=table,
                              aggtable=aggtable,
                              column=column,
                              actions=actions,
                              action_key=action_key,
                              insert_values=insert_values,
                              where_clause=where_clause)
        return tmp
Example #4
0
    def sql_create_function_insert(self,
                                   name,
                                   table,
                                   column,
                                   aggtable,
                                   action,
                                   where_clause=None,
                                   agg_key=None):
        """Return a SQL statement to create a FUNCTION

        name : function name
        table (string) : the originate of datas
        column : column name
        aggtable : the table where data will be stored
        """
        tpl = os.path.join(os.path.dirname(__file__), 'templates')
        env = Environment(loader=FileSystemLoader(tpl))
        template = env.get_template('pg_function_insert.sql')
        if agg_key is None:
            action_key = "agg_count"
            actions = "agg_count=agg_count+1"
        else:
            action_key = "agg_count_{0}".format(agg_key)
        actions = "{0}={0}+1".format(action_key)
        insert_values = 1
        if where_clause:
            where_clause = parse_where_clause(where_clause, table, "NEW")
        tmp = template.render(name=name,
                              table=table,
                              aggtable=aggtable,
                              column=column,
                              actions=actions,
                              action_key=action_key,
                              insert_values=insert_values,
                              where_clause=where_clause)
        return tmp