Spaces:
Sleeping
Sleeping
from psycopg2 import sql | |
import pymysql | |
import pandas as pd | |
from DbConnection import DbConnection | |
class AddSkill: | |
def AddSkillDetails(skills): | |
returnMsg='' | |
details = skills.split(',') | |
skill_details = details[0] | |
skill_type = details [1] | |
skill_score1 = details[2] | |
weightage = -2 | |
is_active = True | |
conn = DbConnection.GetMySQLDbConnection() | |
cursor = conn.cursor() | |
print("Adding Skill " + skill_details) | |
query = "SELECT skillid FROM skillmaster WHERE upper(skillDetails) IN (%s)" | |
params = (skill_details.upper(),) # Replace 'Test' with your actual variable or user input | |
cursor.execute(query, params) | |
if cursor.rowcount == 0: | |
insert_query = ("""INSERT INTO skillmaster (SkillDetails, SkillType, Weightage, IsActive, skill_score) | |
VALUES (%s, %s, %s, %s, %s)""") | |
cursor.execute(insert_query, (skill_details, skill_type, weightage, is_active, skill_score1)) | |
conn.commit() | |
returnMsg = 'Skill Added successfully' | |
else: | |
returnMsg = 'Skill Already in DB' | |
# Close the cursor and connection | |
cursor.close() | |
# Close the connection | |
conn.close() | |
print(returnMsg) | |
return returnMsg | |
def UpdateSkillDetails(skills): | |
returnMsg='' | |
details = skills.split(',') | |
skill_details = details[0] | |
weightage = details [1] | |
is_active = True | |
conn = DbConnection.GetMySQLDbConnection() | |
cursor = conn.cursor() | |
print("Updating Skill " + skill_details) | |
query = "SELECT skillid FROM skillmaster WHERE upper(skillDetails) IN (%s)" | |
params = (skill_details.upper(),) # Replace 'Test' with your actual variable or user input | |
cursor.execute(query, params) | |
if cursor.rowcount == 0: | |
returnMsg = 'Skill Not in DB' | |
else: | |
update_query = ("""UPDATE skillmaster set weightage = %s where upper(skilldetails) = %s""") | |
cursor.execute(update_query, (weightage, skill_details.upper())) | |
conn.commit() | |
returnMsg = 'Skill Updated successfully' | |
# Close the cursor and connection | |
cursor.close() | |
# Close the connection | |
conn.close() | |
print(returnMsg) | |
return returnMsg | |
def GetSkillDetails(): | |
conn = DbConnection.GetMySQLDbConnection() | |
cursor = conn.cursor() | |
cursor.execute("SELECT * FROM skillmaster") | |
cursor.close() | |
# Close the connection | |
conn.close() | |
return cursor.fetchall() | |