-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateMariaDB.py
60 lines (55 loc) · 2.87 KB
/
UpdateMariaDB.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import json
import ast
import sys
import os
from os.path import join, dirname
from os import environ
import mysql.connector
from mysql.connector import MySQLConnection, Error
from mysql.connector import MySQLConnection, Error
from python_mysql_dbconfig import read_db_config
IDObject= sys.argv[1]
CurrentMail= sys.argv[2]
FirstName= sys.argv[3]
LastName= sys.argv[4]
CurrentCompany= sys.argv[5]
STRUserUUID1= sys.argv[6]
JobRole= sys.argv[7]
# this is a trick while waiting for user increment
IDObject="1"
def insert_web_information_fct(web_information_update):
row1="title"
row2="isbn"
query1 = "CREATE TABLE IF NOT EXISTS `web_information` (`IDObject` int(11) NOT NULL ,`CurrentMail` varchar(300) NOT NULL,`FirstName` varchar(300) NOT NULL,`LastName` varchar(300) NOT NULL,`CurrentCompany` varchar(600) NOT NULL, `STRUserUUID1` varchar(300) NOT NULL,`JobRole` varchar(300) NOT NULL);"
#query2 = "INSERT INTO web_information(IDObject,CurrentMail,FirstName,LastName,CurrentCompany,STRUserUUID1,JobRole) " \
# "VALUES(%s,%s,%s,%s,%s,%s,%s)"
query2 = "INSERT INTO web_information(IDObject,CurrentMail,FirstName,LastName,CurrentCompany,STRUserUUID1,JobRole) " \
"VALUES(%s,%s,%s,%s,%s,%s,%s)"
try:
print "*********************************DEBUG A **********************"
db_config = read_db_config()
print "*********************************DEBUG A-1 **********************"
conn = MySQLConnection(**db_config)
#cnx = mysql.connector.connect(user="demo@mouradmysql", password={M0nP@ssw0rd!}, host="mouradmysql.mysql.database.azure.com", port=3306, database={customersDB})
print "*********************************DEBUG A-2 **********************"
#cursor = cnx.cursor()
cursor = conn.cursor()
print "*********************************DEBUG A-3 **********************"
cursor.execute(query1)
print "*********************************DEBUG A-4 **********************"
cursor.executemany(query2, web_information_update)
print "*********************************DEBUG A-5 **********************"
conn.commit()
#cnx.commit()
print "*********************************DEBUG A-6 **********************"
except Error as e:
print "*********************************DEBUG B **********************"
print('Error:', e)
finally:
print "*********************************DEBUG C **********************"
cursor.close()
conn.close()
#cnx.close()
#web_information_update=[(IDObject,CurrentMail,FirstName,LastName,CurrentCompany,STRUserUUID1,JobRole)]
web_information_update=[(IDObject, CurrentMail,FirstName,LastName,CurrentCompany,STRUserUUID1,JobRole)]
insert_web_information_fct(web_information_update)