当前位置:Gxlcms > 数据库问题 > Tornado中insert into sql语句的构造

Tornado中insert into sql语句的构造

时间:2021-07-01 10:21:17 帮助过:21人阅读

!/usr/bin/env python # -*- coding:utf-8 -*- d = {name: alx, age: 18,k1:123,k2: 123} t = "inset into tb(%s) values(%s)" key_list =[] value_list = [] for k,v in d.items(): key_list.append(k) value_list.append("%%(%s)s" %k) sql = t %( ,.join(key_list), ,.join(value_list)) print(sql)

inset into tb(k2,k1,name,age) values(%(k2)s,%(k1)s,%(name)s,%(age)s),      字典

 

    def add_merchant(self, **kwargs):
        cursor = self.db_conn.connect()
        sql = """insert into merchant(%s) values(%s)"""
        key_list = []
        value_list = []
        for k, v in kwargs.items():
            key_list.append(k)
            value_list.append(%%(%s)s % k)
        sql = sql % (,.join(key_list), ,.join(value_list))
        cursor.execute(sql, kwargs)
        self.db_conn.close()

 

Tornado中insert into sql语句的构造

标签:odi   list   rgs   ems   pre   elf   set   bsp   key   

人气教程排行