-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataoper.py
More file actions
63 lines (51 loc) · 1.45 KB
/
dataoper.py
File metadata and controls
63 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sqlite3 as sq
import os
import sys
sys.path.append("..")
import randtext
import devdata
def make_table(pat=""):
con = sq.connect(pat)
cu = con.cursor()
cu.execute("create table tpf_data(idd varchar(20) UNIQUE,key varchar(52))")
con.commit()
con.close()
print("make table success")
def delete_table(pat=devdata.dir,tab="tpf_data"):
con = sq.connect(pat)
cu = con.cursor()
cu.execute("drop table %s" % tab)
con.commit()
con.close()
print("delete table success")
def insert_table(idd,key):
if len(idd) > 20 or len(key) !=50:
return "insert fail!"
con = sq.connect(devdata.dir)
cu = con.cursor()
cu.execute("select * from tpf_data where idd = '%s'" % idd)
if cu.fetchall() != []:
print("insert repeat element!")
return "insert fail!"
cu.execute("insert into tpf_data values('%s','%s')" % (idd,key) )
con.commit()
con.close()
return "insert success"
def find_table(idd):
con = sq.connect(devdata.dir)
cu = con.cursor()
cu.execute("select * from tpf_data where idd = '%s'" % idd)
# print(str(cu.fetchall())+' '+idd)
res = cu.fetchall()
if res == []:
return "None"
else :
return res[0][1]
def display_table():
con = sq.connect(devdata.dir)
cu = con.cursor()
cu.execute("select * from tpf_data")
print(cu.fetchall())
if __name__ == "__main__":
insert_table("a",randtext.get_randtext())
display_table()