You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.5 KiB
46 lines
1.5 KiB
#-*-coding utf-8-*- |
|
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru> |
|
|
|
import sqlite3 |
|
from bot_sys import log |
|
|
|
# Работа с базой данных |
|
|
|
def GetBDDateTimeNow(): |
|
return 'datetime(\'now\')' |
|
|
|
# TODO: Удалить что-то из SelectBDTemplate RequestSelectTemplate |
|
def SelectBDTemplate(a_Bot, a_TableName): |
|
def SelectBD(): |
|
return a_Bot.SQLRequest(f'SELECT * FROM {a_TableName}') |
|
return SelectBD |
|
|
|
def RequestSelectTemplate(a_Bot, a_TableName): |
|
def SelectBD(): |
|
return a_Bot.SQLRequest(f'SELECT * FROM {a_TableName}') |
|
return SelectBD |
|
|
|
def SQLRequest(a_Log, a_BDFileName, a_Request : str, commit = False, return_error = False, param = None): |
|
#print('SQLRequest', a_Request, commit) |
|
db = sqlite3.connect(a_BDFileName) |
|
cursor = db.cursor() |
|
result = [] |
|
error = None |
|
try: |
|
if not param is None: |
|
cursor.execute(a_Request, (param)) |
|
else: |
|
cursor.execute(a_Request) |
|
result = cursor.fetchall() |
|
if commit: |
|
db.commit() |
|
except sqlite3.Error as e: |
|
a_Log.Error(f'Ошибка при обработке запроса [{a_Request}]:{str(e)}') |
|
error = "Ошибка sqlite3:" + str(e) |
|
cursor.close() |
|
db.close() |
|
if not error and commit: |
|
a_Log.Success(f'Выполнен запрос [{a_Request}]') |
|
if return_error: |
|
return result, error |
|
return result
|
|
|