zoukankan      html  css  js  c++  java
  • python执行sql语句

      dbname = 'db.sqlite3'
        dbpath = 'D:\pyweb\sf\db.sqlite3'
        csvpath = pspath
    
        #custom thread number
        tnum = 20
        hvsrvs_all =hvsrvs.objects.all()
        serverips=[]
        #ls = []
        for hvsrv in hvsrvs_all:
             Phy_ServerIP = hvsrv.serverip
             serverips.append(Phy_ServerIP)
    
    
        for ips in lstg(tnum,serverips):
            threads=[]
    
            for Phy_ServerIP in ips:
                #print Phy_ServerIP
                t = threading.Thread(target=GetVMs,args=(PS_GetVMs,Phy_ServerIP))
                t.setDaemon(True)
                t.start()
                threads.append(t)  
            for t in threads:
                t.join()
    
        sql_insert = '''insert into sinfors_hvvms values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'''
        conn = sqlite3.connect(dbpath)
        cu = conn.cursor()
        datas=[]
        i = 1
        for csvf in os.listdir(csvpath):
            if os.path.splitext(csvf)[0].startswith('queryresult-') and os.path.splitext(csvf)[1] == '.csv':
                csvfile = os.path.join(csvpath,csvf)
                #print csvfile
                cf = open(csvfile)
                cf.readline()
                
                for l in csv.reader(cf):
                    l.insert(0,i)
                    i=i+1
                    datas.append(tuple(l))
                cf.close()
                #print csvfile
                os.remove(csvfile)
        #print datas
        if len(datas) > 0:
            cu.execute('delete from sinfors_hvvms')
            conn.commit()
            for data in datas:
                cu.execute(sql_insert,data)
    
            conn.commit()
            cu.execute('select * from sinfors_hvvms')
            cu.close()
  • 相关阅读:
    结对编程作业
    4组-Alpha冲刺-2/6
    4组-Alpha冲刺-1/6
    结对编程作业
    4组 团队展示
    python多进程遇到的问题和解决
    GNS3第一次ping通
    前缀表达式计算(栈的使用)
    欧拉筛法(线性筛)素数
    拓扑排序
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/5604523.html
Copyright © 2011-2022 走看看