-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertTest.py
42 lines (34 loc) · 1.11 KB
/
InsertTest.py
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
import mysql.connector
import os
import sys
def showUser(userName):
connector = mysql.connector.connect(
user='root',
password=os.environ['PASSWORD'],
host='localhost',
database='debugger')
cursor = connector.cursor()
cursor.execute("select * from test where name = '" +userName + "'")
#print(cursor.fetchall())
users = cursor.fetchall()
if len(users) == 0:
print("row is null")
sys.stdout.write("Do you input %s or not?(Y/N)" % userName)
flag = input()
if flag == 'Y':
cursor.execute("insert into test(name) values('" +userName + "')")
print("Input a %s" % userName)
else:
for row in users:
print("ID:" + str(row[0]) + " NAME:" + row[1])
connector.commit()
cursor.close
connector.close
if __name__ == "__main__":
argvs = sys.argv
argc = len(argvs)
if (argc < 2):
print('Usage: # python %s UserName1 ... UserNamen:Input UserNames which you want to search.' % argvs[0])
quit()
for i in range(1,argc):
showUser(argvs[i])