Files

42 lines
1.2 KiB
Python
Raw Permalink Normal View History

from AppCode.Config import DBConfig
import mysql.connector
class YearGet:
def __init__(self):
self.conn = DBConfig.get_db_connection()
self.cursor = self.conn.cursor(dictionary=True)
2025-12-02 15:38:19 +05:30
# get year fetch in perticular Model name.
def get_year_by_model(self, proc_name):
try:
self.cursor.callproc(proc_name)
years = []
for result in self.cursor.stored_results():
rows = result.fetchall()
years = [row["year"] for row in rows]
return years
except mysql.connector.Error as e:
print("MySQL Error:", e)
return []
2025-12-02 15:38:19 +05:30
2026-01-21 22:59:36 +05:30
def CheckYearExists(self, table_name, year):
try:
self.cursor.callproc('CheckYearExists', (table_name, year))
result = 0
for result_set in self.cursor.stored_results():
result = result_set.fetchone()[0]
return {"exists": result > 0}
except mysql.connector.Error as e:
print("MySQL Error:", e)
return {"exists": False, "error": str(e)}
def close(self):
self.cursor.close()
self.conn.close()