-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSQLighter.py
More file actions
26 lines (21 loc) · 953 Bytes
/
SQLighter.py
File metadata and controls
26 lines (21 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sqlite3
class SQLighter:
# Конструктор курсора и привязка к бд
def __init__(self, database):
self.connection = sqlite3.connect(database)
self.cursor = self.connection.cursor()
# Выбор саундтрека
def select_single(self, rownum):
with self.connection:
return self.cursor.execute('SELECT * FROM music WHERE id = ?', (rownum,)).fetchall()[0]
# Подсчет строк бд для случайного выбора саундтрека
def count_rows(self):
with self.connection:
result = self.cursor.execute('SELECT * FROM music').fetchall()
return len(result)
def select_all(self):
with self.connection:
return self.cursor.execute('SELECT * FROM music').fetchall()
def close(self):
# Закрытие соединения с базой данных
self.connection.close()