Skip to content
Snippets Groups Projects
Commit f066f144 authored by Ismail Moumni's avatar Ismail Moumni
Browse files

adding insert function in database file

parent 0266d84c
No related branches found
No related tags found
2 merge requests!7WIP : 005 editing server,!6WIP adding get_generator
Pipeline #866 passed with stage
in 14 seconds
...@@ -76,7 +76,7 @@ def apply_for_job(database, job_id: str): ...@@ -76,7 +76,7 @@ def apply_for_job(database, job_id: str):
return mycursor.rowcount 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. # in which case the value is the filename.
def getParameters(generators: dict): def getParameters(generators: dict):
database = database_connection() database = database_connection()
...@@ -99,6 +99,7 @@ def getParameters(generators: dict): ...@@ -99,6 +99,7 @@ def getParameters(generators: dict):
return (parameters_basefile, parameters_default) return (parameters_basefile, parameters_default)
# Returns a dictionary containing all database generators existing in database
def get_generators(): def get_generators():
database = database_connection() database = database_connection()
generators = {} generators = {}
...@@ -109,3 +110,21 @@ def get_generators(): ...@@ -109,3 +110,21 @@ def get_generators():
mycursor.close() mycursor.close()
for result in myresult: for result in myresult:
generators[result[0]] = [result] 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): ...@@ -135,7 +135,8 @@ def db_generators(req: dict):
def db_insert(s: socket, req: dict): def db_insert(s: socket, req: dict):
if(req is not None): if(req is not None):
if (verif_param(req) == req): 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") print("Query send")
else: else:
raise Exception("Query Doesn't match") raise Exception("Query Doesn't match")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment