Commit f066f144 authored by Ismail Moumni's avatar Ismail Moumni
Browse files

adding insert function in database file

parent 0266d84c
Pipeline #866 passed with stage
in 14 seconds
......@@ -76,7 +76,7 @@ def apply_for_job(database, job_id: str):
return mycursor.rowcount
# Returns a dictionnary containing each generator's parameters as a key. The value associated to each key is "is this parameter's value written in the comand line or in a separated file
# Returns a dictionary containing each generator's parameters as a key. The value associated to each key is "is this parameter's value written in the comand line or in a separated file
# in which case the value is the filename.
def getParameters(generators: dict):
database = database_connection()
......@@ -99,6 +99,7 @@ def getParameters(generators: dict):
return (parameters_basefile, parameters_default)
# Returns a dictionary containing all database generators existing in database
def get_generators():
database = database_connection()
generators = {}
......@@ -109,3 +110,21 @@ def get_generators():
mycursor.close()
for result in myresult:
generators[result[0]] = [result]
def db_insert(query: dict):
if(query is not None):
database = database_connection()
try:
values = query.values()
print(values)
cols = query.keys()
print(cols)
sql_new_job_row = "INSERT INTO jobs (%s) VALUES ('%s');" % (", ".join(cols), "','".join(values))
print(sql_new_job_row)
mycursor = database.cursor(buffered=False)
mycursor.execute(sql_new_job_row)
database.commit()
print("Record inserted", mycursor.rowcount)
except mysql.connector.Error as err:
print("MYSQL Error :{}".format(err))
......@@ -135,7 +135,8 @@ def db_generators(req: dict):
def db_insert(s: socket, req: dict):
if(req is not None):
if (verif_param(req) == req):
s.send(bytes(json.dumps(req), "utf-8"))
ins = db.insert_query(req)
s.send(bytes(json.dumps(ins), "utf-8"))
print("Query send")
else:
raise Exception("Query Doesn't match")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment