mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-07-04 09:11:42 +02:00
MySQL Working, bug fixes.
This commit is contained in:
@ -19,7 +19,7 @@ def open_db() -> engine.base.Connection:
|
||||
global connection
|
||||
if (not connection):
|
||||
print(current_app.config.get("DBCONNSTRING"))
|
||||
engine = create_engine(current_app.config.get("DBCONNSTRING"))
|
||||
engine = create_engine(current_app.config.get("DBCONNSTRING")) # type: ignore
|
||||
connection = engine.connect()
|
||||
# cur.execute('PRAGMA encoding = "UTF-8";')
|
||||
return connection
|
||||
@ -32,7 +32,7 @@ def import_songs(song_csv):
|
||||
df.to_sql(song_table, conn, if_exists='replace',
|
||||
index=False)
|
||||
cur = conn.execute("SELECT Count(Id) FROM songs")
|
||||
num_songs = cur.fetchone()[0]
|
||||
num_songs = cur.fetchone()[0] # type: ignore
|
||||
# conn.close()
|
||||
print("Imported songs ({} in Database)".format(num_songs))
|
||||
return("Imported songs ({} in Database)".format(num_songs))
|
||||
@ -41,7 +41,7 @@ def import_songs(song_csv):
|
||||
def create_entry_table():
|
||||
conn = open_db()
|
||||
conn.execute('CREATE TABLE IF NOT EXISTS '+entry_table +
|
||||
' (ID INTEGER PRIMARY KEY NOT NULL, Song_Id INTEGER NOT NULL, Name VARCHAR(255), Client_Id VARCHAR(36), Transferred INTEGER DEFAULT 0)')
|
||||
' (ID INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT, Song_Id INTEGER NOT NULL, Name VARCHAR(255), Client_Id VARCHAR(36), Transferred INTEGER DEFAULT 0)')
|
||||
# conn.close()
|
||||
|
||||
|
||||
@ -73,14 +73,14 @@ def create_list_view():
|
||||
conn.execute("""CREATE OR REPLACE VIEW `Liste` AS
|
||||
SELECT Name, Title, Artist, entries.Id AS entry_ID, songs.Id AS song_ID, entries.Transferred
|
||||
FROM entries, songs
|
||||
WHERE entries.Song_Id=Song_ID""")
|
||||
WHERE entries.Song_Id=songs.Id""")
|
||||
# conn.close()
|
||||
|
||||
|
||||
def create_done_song_view():
|
||||
conn = open_db()
|
||||
conn.execute("""CREATE OR REPLACE VIEW `Abspielliste` AS
|
||||
SELECT Artist || \" - \" || Title AS Song, Plays AS Wiedergaben
|
||||
SELECT CONCAT(Artist," - ", Title) AS Song, Plays AS Wiedergaben
|
||||
FROM songs, done_songs
|
||||
WHERE done_songs.Song_Id=songs.Id""")
|
||||
# conn.close()
|
||||
@ -127,14 +127,16 @@ def add_entry(name, song_id, client_id):
|
||||
def add_sung_song(entry_id):
|
||||
conn = open_db()
|
||||
cur = conn.execute(
|
||||
"""SELECT Song_Id FROM entries WHERE Id=?""", (entry_id,))
|
||||
song_id = cur.fetchone()[0]
|
||||
conn.execute("""INSERT OR REPLACE INTO done_songs (Song_Id, Plays)
|
||||
VALUES("""+str(song_id)+""",
|
||||
COALESCE(
|
||||
(SELECT Plays FROM done_songs
|
||||
WHERE Song_Id="""+str(song_id)+"), 0) + 1)"
|
||||
)
|
||||
"""SELECT Song_Id FROM entries WHERE Id=%s""", (entry_id,))
|
||||
song_id = cur.fetchone()[0] # type: ignore
|
||||
conn.execute("""INSERT INTO done_songs (Song_Id, Plays) VALUES("""+str(song_id)+""",1) ON DUPLICATE KEY UPDATE Plays=Plays + 1;""")
|
||||
# SQLite bullshittery
|
||||
# conn.execute("""REPLACE INTO done_songs (Song_Id, Plays)
|
||||
# VALUES("""+str(song_id)+""",
|
||||
# COALESCE(
|
||||
# (SELECT Plays FROM done_songs
|
||||
# WHERE Song_Id="""+str(song_id)+"), 0) + 1)"
|
||||
# )
|
||||
delete_entry(entry_id)
|
||||
# conn.close()
|
||||
return True
|
||||
@ -143,14 +145,14 @@ def add_sung_song(entry_id):
|
||||
def toggle_transferred(entry_id):
|
||||
conn = open_db()
|
||||
cur = conn.execute(
|
||||
"SELECT Transferred FROM entries WHERE ID =?", (entry_id,))
|
||||
"SELECT Transferred FROM entries WHERE ID =%s", (entry_id,))
|
||||
marked = cur.fetchall()[0][0]
|
||||
if(marked == 0):
|
||||
conn.execute(
|
||||
"UPDATE entries SET Transferred = 1 WHERE ID =?", (entry_id,))
|
||||
"UPDATE entries SET Transferred = 1 WHERE ID =%s", (entry_id,))
|
||||
else:
|
||||
conn.execute(
|
||||
"UPDATE entries SET Transferred = 0 WHERE ID =?", (entry_id,))
|
||||
"UPDATE entries SET Transferred = 0 WHERE ID =%s", (entry_id,))
|
||||
# conn.close()
|
||||
return True
|
||||
|
||||
@ -158,7 +160,7 @@ def toggle_transferred(entry_id):
|
||||
def check_entry_quota(client_id):
|
||||
conn = open_db()
|
||||
cur = conn.execute(
|
||||
"SELECT Count(*) FROM entries WHERE entries.Client_Id = ?", (client_id,))
|
||||
"SELECT Count(*) FROM entries WHERE entries.Client_Id = %s", (client_id,))
|
||||
return cur.fetchall()[0][0]
|
||||
|
||||
|
||||
@ -177,7 +179,7 @@ def clear_played_songs():
|
||||
|
||||
def delete_entry(id):
|
||||
conn = open_db()
|
||||
conn.execute("DELETE FROM entries WHERE id=?", (id,))
|
||||
conn.execute("DELETE FROM entries WHERE id=%s", (id,))
|
||||
# conn.close()
|
||||
return True
|
||||
|
||||
@ -188,7 +190,7 @@ def delete_entries(ids):
|
||||
idlist.append((x,))
|
||||
try:
|
||||
conn = open_db()
|
||||
cur = conn.execute("DELETE FROM entries WHERE id=?", idlist)
|
||||
cur = conn.execute("DELETE FROM entries WHERE id=%s", idlist)
|
||||
# conn.close()
|
||||
return cur.rowcount
|
||||
except Exception as error:
|
||||
|
Reference in New Issue
Block a user