mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-07 11:45:35 +00:00
rewrite sql statements to use parameter binding
This commit is contained in:
parent
151fb36276
commit
d39c0ea2f8
@ -22,18 +22,17 @@ class SQLitePlaylistMethods:
|
||||
last_updated,
|
||||
name,
|
||||
trackhashes
|
||||
) VALUES(?,?,?,?,?,?,?)
|
||||
) VALUES(:artisthashes, :banner_pos, :has_gif, :image, :last_updated, :name, :trackhashes)
|
||||
"""
|
||||
|
||||
playlist = OrderedDict(sorted(playlist.items()))
|
||||
params = (*playlist.values(),)
|
||||
|
||||
with SQLiteManager(userdata_db=True) as cur:
|
||||
cur.execute(sql, params)
|
||||
cur.execute(sql, playlist)
|
||||
pid = cur.lastrowid
|
||||
params = (pid, *params)
|
||||
|
||||
return tuple_to_playlist(params)
|
||||
p_tuple = (pid, *playlist.values())
|
||||
return tuple_to_playlist(p_tuple)
|
||||
|
||||
@staticmethod
|
||||
def get_playlist_by_name(name: str):
|
||||
|
@ -4,6 +4,7 @@ interacting with the tracks table.
|
||||
"""
|
||||
|
||||
|
||||
from collections import OrderedDict
|
||||
from sqlite3 import Cursor
|
||||
|
||||
from app.db.sqlite.utils import tuple_to_track, tuples_to_tracks
|
||||
@ -37,31 +38,11 @@ class SQLiteTrackMethods:
|
||||
title,
|
||||
track,
|
||||
trackhash
|
||||
) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
) VALUES(:album, :albumartist, :albumhash, :artist, :bitrate, :copyright, :date, :disc, :duration, :filepath, :folder, :genre, :title, :track, :trackhash)
|
||||
"""
|
||||
|
||||
cur.execute(
|
||||
sql,
|
||||
(
|
||||
track["album"],
|
||||
track["albumartist"],
|
||||
track["albumhash"],
|
||||
track["artist"],
|
||||
track["bitrate"],
|
||||
track["copyright"],
|
||||
track["date"],
|
||||
track["disc"],
|
||||
track["duration"],
|
||||
track["filepath"],
|
||||
track["folder"],
|
||||
track["genre"],
|
||||
track["title"],
|
||||
track["track"],
|
||||
track["trackhash"],
|
||||
),
|
||||
)
|
||||
|
||||
# TODO: rewrite the above code using an ordered dict and destructuring
|
||||
track = OrderedDict(sorted(track.items()))
|
||||
cur.execute(sql, track)
|
||||
|
||||
@classmethod
|
||||
def insert_many_tracks(cls, tracks: list[dict]):
|
||||
|
Loading…
x
Reference in New Issue
Block a user