"""Execute a query
:param str query: Query to execute.
:param args: parameters used with query. (optional)
:type args: tuple, list or dict
:return: Number of affected rows
:rtype: int
If args is a list or tuple, %s can be used as a placeholder in the query.
If args is a dict, %(name)s can be used as a placeholder in the query.
"""
官方的说明文档
实际操作中的示例
‘INSERT IGNORE INTO {}(g_name,g_index,uid,account,value,updatetime,writetime) ‘ ‘VALUES(%(g_name)s,%(g_index)s,%(uid)s,%(nickname)s,%(value)s,%(updatetime)s,NOW())‘
上面的示例中讲需要被格式化输入的字典的key写成%(name)s的形式,那么就是准备格式话输入字典的key,value将被格式化输入。
后面被格式话输入的字典形式可以为{‘g_name‘:xxx, ‘g_index‘:xxx,......}
说实话这样的输入感觉真的非常麻烦,还不如网上随便找个将keys,values分开的格式化输入。