def add_data_VMI(SPEC): if len(str(SPEC)) != 4: return 'SPEC LENGTH ERROR, PLEASE CHECK' conn = sqlite3.Connection( 'c:/users/sxchen/desktop/PartsChangeInformation/main.db') conn.text_factory = lambda x: unicode(x, "utf-8", "ignore") cur = conn.cursor() #COUNT could find records of database,but the row [SPEC,0,0,0,0,0,0,0,0] also need to handle sql = "SELECT * FROM tb1 WHERE SPEC = '%s'" % SPEC sql2 = "SELECT COUNT(*) FROM tb1" sql3 = "SELECT COUNT(*) FROM tb1 WHERE SPEC = %s" % SPEC sql4 = '''INSERT INTO tb1 (SPEC,MACHINE_TYPE,DIM,CENTER_DECK,PUSHOVER_CAN,SIDE_RING,BT_ADD,TRANSFER_RING,BO_PUSH_CAN) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s');''' sql5 = '''UPDATE tb1 SET SPEC='%s', MACHINE_TYPE='%s', DIM='%s', CENTER_DECK='%s', PUSHOVER_CAN='%s', SIDE_RING='%s', BT_ADD='%s', TRANSFER_RING='%s', BO_PUSH_CAN='%s' WHERE (MACHINE_TYPE='VMI' AND SPEC='%s');''' num, = cur.execute(sql3).fetchall()[0] res = extra_info(SPEC) res2 = [] res2.extend(res) res2.append(SPEC) #print res2 if num > 0: print SPEC, 'ALREADY EXISTED\n' print 'TRYING TO UPDATE...' cur.execute(sql5 % tuple(res2)) print 'UPDATED!' else: cur.execute(sql4 % tuple(res)) #cur.close() conn.commit()
def add_data_VMI(SPEC): if len(str(SPEC)) != 4: return "SPEC LENGTH ERROR, PLEASE CHECK" conn = sqlite3.Connection("c:/users/sxchen/desktop/PartsChangeInformation/main.db") conn.text_factory = lambda x: unicode(x, "utf-8", "ignore") cur = conn.cursor() # COUNT could find records of database,but the row [SPEC,0,0,0,0,0,0,0,0] also need to handle sql = "SELECT * FROM tb1 WHERE SPEC = '%s'" % SPEC sql2 = "SELECT COUNT(*) FROM tb1" sql3 = "SELECT COUNT(*) FROM tb1 WHERE SPEC = %s" % SPEC sql4 = """INSERT INTO tb1 (SPEC,MACHINE_TYPE,DIM,CENTER_DECK,PUSHOVER_CAN,SIDE_RING,BT_ADD,TRANSFER_RING,BO_PUSH_CAN) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s');""" sql5 = """UPDATE tb1 SET SPEC='%s', MACHINE_TYPE='%s', DIM='%s', CENTER_DECK='%s', PUSHOVER_CAN='%s', SIDE_RING='%s', BT_ADD='%s', TRANSFER_RING='%s', BO_PUSH_CAN='%s' WHERE (MACHINE_TYPE='VMI' AND SPEC='%s');""" num, = cur.execute(sql3).fetchall()[0] res = extra_info(SPEC) res2 = [] res2.extend(res) res2.append(SPEC) # print res2 if num > 0: print SPEC, "ALREADY EXISTED\n" print "TRYING TO UPDATE..." cur.execute(sql5 % tuple(res2)) print "UPDATED!" else: cur.execute(sql4 % tuple(res)) # cur.close() conn.commit()
def add_data_VMI(self, SPEC): if len(str(SPEC)) != 4: return 'SPEC LENGTH ERROR, PLEASE CHECK' #COUNT could find records of database,but the row [SPEC,0,0,0,0,0,0,0,0] also need to handle sql = "SELECT * FROM tb1 WHERE SPEC = '%s'" % SPEC sql2 = "SELECT COUNT(*) FROM tb1" sql3 = "SELECT COUNT(*) FROM tb1 WHERE SPEC = %s" % SPEC sql4 = '''INSERT INTO tb1 (SPEC,MACHINE_TYPE,DIM,CENTER_DECK,PUSHOVER_CAN,SIDE_RING,BT_ADD,TRANSFER_RING,BO_PUSH_CAN) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s');''' sql5 = '''UPDATE tb1 SET SPEC='%s', MACHINE_TYPE='%s', DIM='%s', CENTER_DECK='%s', PUSHOVER_CAN='%s', SIDE_RING='%s', BT_ADD='%s', TRANSFER_RING='%s', BO_PUSH_CAN='%s' WHERE (MACHINE_TYPE='VMI' AND SPEC='%s');''' num, = self.cur.execute(sql3).fetchall()[0] res = extra_info(SPEC) res2 = [] res2.extend(res) res2.append(SPEC) #print res2 if num > 0: print SPEC, 'ALREADY EXISTED\n' print 'TRYING TO UPDATE...' self.cur.execute(sql5 % tuple(res2)) print 'UPDATED!' else: self.cur.execute(sql4 % tuple(res))
def api(SPEC): data = extra_info(SPEC) return render_template('api.html',data = data)
def api(SPEC): data = extra_info(SPEC) return render_template('api.html', data=data)