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

adding check function to database insert

parent c888c56c
Pipeline #1315 failed with stage
in 15 seconds
...@@ -123,12 +123,12 @@ def list_generator(): ...@@ -123,12 +123,12 @@ def list_generator():
mycur.execute(sql_get_generators) mycur.execute(sql_get_generators)
res = mycur.fetchall() res = mycur.fetchall()
mycur.close() mycur.close()
for a,b in res: for a, b in res:
generators[b] = a generators[b] = a
return generators return generators
# Insert in database query send from client and returns insert status # Insert in database query send from client and returns insert status 1 if inserted
def db_insert(query: dict): def db_insert(query: dict):
if(query is not None): if(query is not None):
database = database_connection() database = database_connection()
...@@ -145,11 +145,15 @@ def db_insert(query: dict): ...@@ -145,11 +145,15 @@ def db_insert(query: dict):
database.commit() database.commit()
mycursor.close() mycursor.close()
database.close() database.close()
res = db_job_check(query)
print("res:", res)
return res
except mysql.connector.Error as err: except mysql.connector.Error as err:
print("MYSQL Error :{}".format(err)) print("MYSQL Error :{}".format(err))
# Checks existance of query ID in database and returns the status # Checks existance of query ID in database and returns the status
# db_job_check returns 1 if query exist in database else returns 0
def db_job_check(query: dict): def db_job_check(query: dict):
if (query is not None): if (query is not None):
db = database_connection() db = database_connection()
......
...@@ -10,10 +10,11 @@ import database as db ...@@ -10,10 +10,11 @@ import database as db
__RDOS_Dict__ = {"parameters": "request"} __RDOS_Dict__ = {"parameters": "request"}
# tools List # tools List
__RDOS_Tool__ = db.list_generator() # __RDOS_Tool__ = db.list_generators()
class RdosServer: class RdosServer:
__RDOS_Tool__ = db.list_generators()
# Function server_conn creates a socket and listens on port 9393 # Function server_conn creates a socket and listens on port 9393
# Function input address : SERVER IP ADRESS & Port server Port # Function input address : SERVER IP ADRESS & Port server Port
...@@ -32,8 +33,7 @@ class RdosServer: ...@@ -32,8 +33,7 @@ class RdosServer:
data = conn.recv(4096) data = conn.recv(4096)
query = (json.loads(data.decode('utf-8'))) query = (json.loads(data.decode('utf-8')))
print("Requete reçu : ", query) print("Requete reçu : ", query)
#query = json_to_dict(req) if (query is not None):
if(query is not None):
# Sending GENERATORS # Sending GENERATORS
print(query) print(query)
if (match_query_dict(query, __RDOS_Dict__)): if (match_query_dict(query, __RDOS_Dict__)):
...@@ -44,13 +44,17 @@ class RdosServer: ...@@ -44,13 +44,17 @@ class RdosServer:
# Inserting client query in DATABASE # Inserting client query in DATABASE
else: else:
print("check", check_and_complete_parameters(query)) print("check", check_and_complete_parameters(query))
db_server_insert(conn, query_client(addr, check_and_complete_parameters(query))) res = db_server_insert(conn, query_client(addr, check_and_complete_parameters(query)))
print("query received : ", query) # print("query : " , query)
conn.send(bytes(json.dumps("{'etat':'inserted'}"), "utf-8")) if (res == 1):
conn.send(bytes(res, "utf-8"))
else:
conn.send(bytes("query not inserted !!", "utf-8"))
conn.close() conn.close()
def query_client(addr, data): def query_client(addr, data):
__RDOS_Tool__ = db.list_generators()
sa = __RDOS_Tool__.get(list(data.keys())[0]) sa = __RDOS_Tool__.get(list(data.keys())[0])
lm = list((data.values())) lm = list((data.values()))
s = {"id": "", "idGenerator": "", "IP": "", "timeSubmitted": "", "timeExecuted": "", "timeFinished": "", "status": "", "parametersJSON": "", "directory": "", "url": "", "message": "", "email": ""} s = {"id": "", "idGenerator": "", "IP": "", "timeSubmitted": "", "timeExecuted": "", "timeFinished": "", "status": "", "parametersJSON": "", "directory": "", "url": "", "message": "", "email": ""}
......
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