Ejemplo n.º 1
0
    def _insert_query(self,
            model,
            objs,
            fields,
            return_id=True,
            raw=False,
            using=None,
            update = [],
            replace = False,
            ignore = False,
        ):

        query = sql.InsertQuery(model)
        query.insert_values(fields, objs, raw=raw)
        compiler = query.get_compiler(using=using)

        post_str = ''
        if(update):
            xupdate = self._build_update(fields, update)
            if(xupdate):
                update_str = ','.join([
                    "`%s` = %s"%(key,value)
                    for key, value in six.iteritems(xupdate)
                ])
                post_str = 'on duplicate key update %s'%(update_str)
        pre_replace_str = ''

        if(replace):
            pre_replace_str = 'REPLACE'

        if(ignore):
            pre_replace_str = 'INSERT IGNORE'

        return self._insert_query_execute_sql(
            compiler = compiler,
            return_id = return_id,
            pre_replace_str = pre_replace_str,
            post_str = post_str
        )
Ejemplo n.º 2
0
    def _insert_query(
        self,
        model,
        objs,
        fields,
        return_id=True,
        raw=False,
        using=None,
        update=[],
        replace=False,
        ignore=False,
    ):

        query = sql.InsertQuery(model)
        query.insert_values(fields, objs, raw=raw)
        compiler = query.get_compiler(using=using)

        post_str = ''
        if (update):
            xupdate = self._build_update(fields, update)
            if (xupdate):
                update_str = ','.join([
                    "`%s` = %s" % (key, value)
                    for key, value in six.iteritems(xupdate)
                ])
                post_str = 'on duplicate key update %s' % (update_str)
        pre_replace_str = ''

        if (replace):
            pre_replace_str = 'REPLACE'

        if (ignore):
            pre_replace_str = 'INSERT IGNORE'

        return self._insert_query_execute_sql(compiler=compiler,
                                              return_id=return_id,
                                              pre_replace_str=pre_replace_str,
                                              post_str=post_str)
Ejemplo n.º 3
0
def insert_query_sqlx(model, values, return_id=False, raw_values=False):
    """overrides insert_query() from models.query module"""
    query = sql.InsertQuery(model, connection)
    query.insert_values(values, raw_values)
    return query.as_sql() # return SQL tuple
Ejemplo n.º 4
0
def insert_query_sqlx(model, values, return_id=False, raw_values=False):
    """overrides insert_query() from models.query module"""
    query = sql.InsertQuery(model, connection)
    query.insert_values(values, raw_values)
    return query.as_sql()  # return SQL tuple