python3 sqlite3限制条件查询操作代码

作者:袖梨 2022-06-25

本篇文章小编给大家分享一下python3 sqlite3限制条件查询操作代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

请注意10,11,24行的代码,代码如下:

import json 
import sqlite3
import re
import argparse
def Get(db_file):
  
    conn = sqlite3.connect(db_file)
    cur = conn.cursor()
    print("5555555")
    value1=(60)# this is must be ()
    cur.execute("select * from exception where AGV_ID=(%s)" %(value1))
    #cursor.execute("insert into exception values('%s', '%s','%s' ) " %(start_time ,ID ,infomation))
 
    result= cur.fetchall()
    print("result:",result)
    for i in result:
       print(i)  
    print("******************************888")
  
def get_agv_id(db_file):
  try:
    conn = sqlite3.connect(db_file)
    cur = conn.cursor()
    cur.execute("select * from exception where AGV_ID=51")
    #print( cur.fetchall())
    result= cur.fetchall()
    for i in result:
       print(i)
  except sqlite3.Error,e:
    print(e)
    
if __name__ == '__main__': 
  parser = argparse.ArgumentParser(description='check the information of db')
  #parser.add_argument('-h', '--help', help='Statistics for abnormal information')
  parser.add_argument('-n', '--name', help=' the db of name ')
  args = vars(parser.parse_args())
  db_name = args['name']
  print("db_name:",db_name)
  conn = sqlite3.connect('db_name')
  cursor = conn.cursor()
  Get('fitkits.db')
  get_agv_id('fitkits.db')  
  
  conn.commit()
  conn.close() 
  print('DONE!')
  print("666")

相关文章

精彩推荐