-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql_ground.py
More file actions
49 lines (38 loc) · 1.49 KB
/
mysql_ground.py
File metadata and controls
49 lines (38 loc) · 1.49 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pymysql
import sys
def ct_dp_tl():
try:
con = pymysql.connect('localhost', 'root', '2272as8a2', 'ground')
cur = con.cursor()
#print (con.set_charset())
with con:
req = "DROP TABLE IF EXISTS lot_list"
cur.execute(req)
# AUTO_INCREMENT убрал из примера т.к. считаю, что это автонумерация
req = "CREATE TABLE lot_list(Id INT PRIMARY KEY AUTO_INCREMENT, \
bidKindId VARCHAR(2), bidKindName VARCHAR(255), bidNumber VARCHAR(100), \
organizationName VARCHAR(1000), isArchived VARCHAR(1), publishDate VARCHAR(25), \
lastChanged VARCHAR(25), odDetailedHref VARCHAR(255)) DEFAULT CHARACTER SET utf8"
cur.execute(req)
except pymysql.Error as e:
print ("Error %d: %s" % (e.args[0], e.args[1]))
sys.exit(1)
finally:
if cur:
cur.close()
def db_data_add(table, data):
try:
con = pymysql.connect('localhost', 'root', '2272as8a2', 'ground')
con.set_charset('utf8')
cur = con.cursor()
with con:
req = "INSERT INTO %s (%s) VALUES(%s)" % (table, ",".join(data.keys()), ",".join(data.values()))
cur.execute(req)
except pymysql.Error as e:
print ("Error %d: %s" % (e.args[0], e.args[1]))
sys.exit(1)
finally:
if cur:
cur.close()