wstkeys/services/orders.py

40 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sqlite3
# Получаем sku из параметров
def get_sku(sku):
if sku:
# Подключаемся к БД
conn = sqlite3.connect("./files/rokky.db")
cursor = conn.cursor()
try:
# Выполняем поиск: выбираем sku и gg, где sku совпадает с искомым
# Используем (sku,) как кортеж для передачи параметра
cursor.execute("SELECT sku, gg, price FROM products WHERE gg = ?", (sku,))
# Получаем одну запись
result = cursor.fetchone()
if result:
db_sku, db_gg, db_price = result
# Выводим sku из таблицы
print(f"Найденный SKU: {db_sku}")
# # Если нужно также вывести значение из колонки gg:
# print(f"Значение gg: {db_gg}")
print(f"Значение price: {db_price}")
return db_sku, db_price
else:
print(f"Товар с SKU {sku} не найден")
except sqlite3.Error as e:
print(f"Ошибка базы данных: {e}")
finally:
# Обязательно закрываем соединение
conn.close()
# get_sku(102180432)