-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsql_table.py
More file actions
25 lines (22 loc) · 732 Bytes
/
sql_table.py
File metadata and controls
25 lines (22 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sql_sb
import mysql.connector
from mysql.connector import errorcode
def create_tables(tables):
cnx=sql_sb.connect_sql()
if cnx is None:
print("unable to execute connect_sql")
else:
cursor=cnx.cursor()
sql_sb.connect_db(cursor)
for t_names in tables:
t_dis=tables[t_names]
try:
#print('Creating table {}'.format(t_names),end=" ")
cursor.execute(t_dis)
except mysql.connector.Error as err:
if err.err == errorcode.ER_TABLE_EXISTS_ERROR:
print("table already exists.")
else:
print(err.msg)
cursor.close()
cnx.close()