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()
  • 相关阅读:
    二分查找算法
    java多线程模拟停车位问题
    ECShop模板原理
    linux 常用命令 自己 积累
    ubuntu忘记root密码解决
    centos下一键安装lamp环境,快捷,方便
    腾讯php部分面试题答案
    PHP面试题集
    php笔试题
    流行的php面试题及答案
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/5604523.html
Copyright © 2011-2022 走看看