def query(self, sql):
connect = selfconnect()
cur = connectcursor()
curexecute(sql)
index = curdescription
result = []
for res in curfetchall():
row = {}
for i in range(len(index)-1):
row[index[i][0]] = res[i]
resultappend(row)
connectclose()
return result
这个方法返回查询结果就是带字段名的{‘字段名’:‘值’}
class Buffer(object):
MAXSIZE = 8192
def __init__(self, conn, sql):
selfconn = conn
selfsql = sql
selfbuffer = []
def append(self, data):
selfbufferappend(data)
if len(selfbuffer) > selfMAXSIZE:
selfflush()
def flush(self):
data, selfbuffer = selfbuffer, []
curr = selfconncursor()
currexecutemany(selfsql, data)
selfconncommit()
# here are your code for init database connect conn_src and conn_store
buff = Buffer(conn_store, "insert into sybase_user values (%s, %s)")
sql_query = "select aid, aname from user_info a where aid=%s"
curr_src = conn_srccursor()
curr_srcexecute(sql_query, '0001')
for row in curr_src:
buffappend(row)
buffflush()
以上就是关于python读取数据库怎么把列名显示出来全部的内容,包括:python读取数据库怎么把列名显示出来、python 读取本地数据然后插入到另一个数据库中、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)