오랜만이라 뭐가 수정된지 잘 몰라서 일단 커밋
This commit is contained in:
+23
-24
@@ -145,46 +145,45 @@ class PupilData:
|
||||
return retInfo
|
||||
"""
|
||||
|
||||
def _get_gallery_data(self) -> dict:
|
||||
if not isinstance(self.m_data, dict):
|
||||
return {}
|
||||
|
||||
gallery_data = self.m_data.get(GALINFO)
|
||||
if not isinstance(gallery_data, dict):
|
||||
gallery_data = self.m_data.get(GALBLOCK)
|
||||
|
||||
return gallery_data if isinstance(gallery_data, dict) else {}
|
||||
|
||||
#
|
||||
def GetTitle(self) -> str:
|
||||
retStr : str = ""
|
||||
if None != self.m_data:
|
||||
retStr = self.m_data[GALINFO]["title"]
|
||||
|
||||
return retStr
|
||||
return self._get_gallery_data().get("title", "")
|
||||
|
||||
#
|
||||
def GetHitomiID(self) -> str:
|
||||
retStr : str = ""
|
||||
if None != self.m_data:
|
||||
retStr = self.m_data[GALINFO]["id"]
|
||||
|
||||
return retStr
|
||||
return self._get_gallery_data().get("id", "")
|
||||
|
||||
#
|
||||
def GetImgFileCount(self) -> int:
|
||||
if None == self.m_data:
|
||||
return 0
|
||||
|
||||
return len(self.m_data[GALINFO]["files"])
|
||||
return len(self._get_gallery_data().get("files", []))
|
||||
|
||||
# pupil 의 JSON 을 파싱해서 ImageFileList 를 반환한다.
|
||||
def GetImgFileList(self) -> list[info.ImageFileInfo]:
|
||||
listRet = list[info.ImageFileInfo]()
|
||||
|
||||
if None != self.m_data:
|
||||
listFiles = self.m_data[GALINFO]["files"]
|
||||
for item in listFiles:
|
||||
tempInfo = info.ImageFileInfo(item["name"],
|
||||
item["height"],
|
||||
item["width"],
|
||||
item["hash"],
|
||||
item["haswebp"])
|
||||
listRet.append(tempInfo)
|
||||
listFiles = self._get_gallery_data().get("files", [])
|
||||
for item in listFiles:
|
||||
tempInfo = info.ImageFileInfo(
|
||||
item["name"],
|
||||
item["height"],
|
||||
item["width"],
|
||||
item["hash"],
|
||||
item["haswebp"],
|
||||
)
|
||||
listRet.append(tempInfo)
|
||||
|
||||
return listRet
|
||||
|
||||
#
|
||||
def GetText(self) -> str:
|
||||
return util.PrintJSONTree(self.m_data)
|
||||
|
||||
|
||||
+5
-5
@@ -24,7 +24,7 @@ class MgrCalibreDB(MyDB.MgrSQLiteDB):
|
||||
if True == util.IsEmptyStr(strTableName):
|
||||
return -1
|
||||
|
||||
strSQL = f"SELECT MAX(id) FROM \'{strTableName}\';"
|
||||
strSQL = f"SELECT MAX(id) FROM \"{strTableName}\";"
|
||||
listMaxID = self.SQLExecute_Get(self.cursor, strSQL)
|
||||
if listMaxID is None or 0 >= len(listMaxID):
|
||||
util.DbgOut("Error : Invalid Table Name")
|
||||
@@ -142,8 +142,8 @@ class MgrCalibreDB(MyDB.MgrSQLiteDB):
|
||||
return
|
||||
|
||||
strAuthorSort = strAuthor.replace(" ", ",")
|
||||
strSQL = f"INSERT OR IGNORE INTO \'{strTableName}\' VALUES ({nMaxID}, \'{strAuthor}\',\'{strAuthorSort}\', \'\');"
|
||||
self.SQLExecute(self.cursor, strSQL, True)
|
||||
strSQL = f"INSERT OR IGNORE INTO \"{strTableName}\" VALUES (?, ?, ?, ?);"
|
||||
self.SQLExecute_Params(self.cursor, strSQL, (nMaxID, strAuthor, strAuthorSort, ""), True)
|
||||
|
||||
|
||||
#
|
||||
@@ -157,8 +157,8 @@ class MgrCalibreDB(MyDB.MgrSQLiteDB):
|
||||
util.DbgOut("Error : Invalid Table Name")
|
||||
return
|
||||
|
||||
strSQL = f"INSERT OR IGNORE INTO \'{strTableName}\' VALUES ({nMaxID}, \'{strTag}\', \'\');"
|
||||
self.SQLExecute(self.cursor, strSQL, True)
|
||||
strSQL = f"INSERT OR IGNORE INTO \"{strTableName}\" VALUES (?, ?, ?);"
|
||||
self.SQLExecute_Params(self.cursor, strSQL, (nMaxID, strTag, ""), True)
|
||||
|
||||
|
||||
""" #Example usage
|
||||
|
||||
+8
-9
@@ -37,14 +37,13 @@ class MgrPupilColDB(MyDB.MgrSQLiteDB):
|
||||
if True == util.IsEmptyStr(strName) or True == util.IsEmptyStr(strTableName):
|
||||
return -1
|
||||
|
||||
strSQL = f"SELECT id FROM \'{strTableName}\' WHERE name = \'{strName}\';"
|
||||
self.SQLExecute(self.cursor, strSQL, True)
|
||||
result = self.cursor.fetchone()
|
||||
strSQL = f"SELECT id FROM \"{strTableName}\" WHERE name = ?;"
|
||||
listRet = self.SQLExecute_Get_Params(self.cursor, strSQL, (strName,))
|
||||
|
||||
if result is None:
|
||||
if listRet is None or 0 >= len(listRet):
|
||||
return -1
|
||||
|
||||
return result[0]
|
||||
return listRet[0][0]
|
||||
|
||||
#
|
||||
def GetAuthorIDByName(self, strName: str) -> int:
|
||||
@@ -129,7 +128,7 @@ class MgrPupilColDB(MyDB.MgrSQLiteDB):
|
||||
|
||||
strTableName = "authors"
|
||||
try:
|
||||
strSQL = f"INSERT OR IGNORE INTO \'{strTableName}\' (name, group, language, desc) VALUES (?, ?, ?, ?)"
|
||||
strSQL = f"INSERT OR IGNORE INTO \"{strTableName}\" (name, group, language, desc) VALUES (?, ?, ?, ?)"
|
||||
self.cursor.execute(strSQL, (strName, strGroup, strLanguage, strDesc))
|
||||
nID = self.cursor.lastrowid
|
||||
self.conn.commit()
|
||||
@@ -163,7 +162,7 @@ class MgrPupilColDB(MyDB.MgrSQLiteDB):
|
||||
|
||||
strTableName = "tags"
|
||||
try:
|
||||
strSQL = f"INSERT INTO \'{strTableName}\' (name, sep_title, value) VALUES (?)"
|
||||
strSQL = f"INSERT INTO \"{strTableName}\" (name, sep_title, value) VALUES (?, ?, ?)"
|
||||
self.cursor.execute(strSQL, (strName, strSep, strValue,))
|
||||
nID = self.cursor.lastrowid
|
||||
self.conn.commit()
|
||||
@@ -183,7 +182,7 @@ class MgrPupilColDB(MyDB.MgrSQLiteDB):
|
||||
|
||||
strTableName = "groups"
|
||||
try:
|
||||
strSQL = f"INSERT INTO \'{strTableName}\' (name) VALUES (?)"
|
||||
strSQL = f"INSERT INTO \"{strTableName}\" (name) VALUES (?)"
|
||||
self.cursor.execute(strSQL, (strName,))
|
||||
nID = self.cursor.lastrowid
|
||||
self.conn.commit()
|
||||
@@ -201,7 +200,7 @@ class MgrPupilColDB(MyDB.MgrSQLiteDB):
|
||||
def AddFileInfo(self, strName: str, strHash: str, bHasAvif: bool, nWidth: int, nHeight: int) -> int:
|
||||
strTableName = "files"
|
||||
try:
|
||||
strSQL = f"INSERT INTO \'{strTableName}\' (filename, hash, hasavif, width, height) VALUES (?)"
|
||||
strSQL = f"INSERT INTO \"{strTableName}\" (filename, hash, hasavif, width, height) VALUES (?, ?, ?, ?, ?)"
|
||||
self.cursor.execute(strSQL, (strName, strHash, bHasAvif, nWidth, nHeight))
|
||||
nID = self.cursor.lastrowid
|
||||
self.conn.commit()
|
||||
|
||||
+42
-7
@@ -27,7 +27,24 @@ class MgrSQLiteDB:
|
||||
return None
|
||||
|
||||
try:
|
||||
self.cursor.execute(strSQL)
|
||||
cursor.execute(strSQL)
|
||||
|
||||
if True == bCommit:
|
||||
self.conn.commit()
|
||||
|
||||
except sqlite3.Error as e:
|
||||
util.DbgOut(f"SQLite Error occurred: {e}")
|
||||
|
||||
# 파라미터 바인딩으로 쿼리를 실행한다. SQL 인젝션 방지용.
|
||||
def SQLExecute_Params(self, cursor: sqlite3.Cursor, strSQL: str, tupleParams: tuple, bCommit: bool = True):
|
||||
if not cursor:
|
||||
return None
|
||||
|
||||
if True == util.IsEmptyStr(strSQL):
|
||||
return None
|
||||
|
||||
try:
|
||||
cursor.execute(strSQL, tupleParams)
|
||||
|
||||
if True == bCommit:
|
||||
self.conn.commit()
|
||||
@@ -47,8 +64,26 @@ class MgrSQLiteDB:
|
||||
listRet = []
|
||||
|
||||
try:
|
||||
self.cursor.execute(strSQL)
|
||||
listRet = self.cursor.fetchall()
|
||||
cursor.execute(strSQL)
|
||||
listRet = cursor.fetchall()
|
||||
except sqlite3.Error as e:
|
||||
util.DbgOut(f"SQLite Error occurred: {e}")
|
||||
|
||||
return listRet
|
||||
|
||||
# 파라미터 바인딩으로 쿼리를 실행해서 결과를 가져온다.
|
||||
def SQLExecute_Get_Params(self, cursor: sqlite3.Cursor, strSQL: str, tupleParams: tuple):
|
||||
if not cursor:
|
||||
return None
|
||||
|
||||
if True == util.IsEmptyStr(strSQL):
|
||||
return None
|
||||
|
||||
listRet = []
|
||||
|
||||
try:
|
||||
cursor.execute(strSQL, tupleParams)
|
||||
listRet = cursor.fetchall()
|
||||
except sqlite3.Error as e:
|
||||
util.DbgOut(f"SQLite Error occurred: {e}")
|
||||
|
||||
@@ -78,8 +113,8 @@ class MgrSQLiteDB:
|
||||
if 0 >= nID or True == util.IsEmptyStr(strTableName) or True == util.IsEmptyStr(strColName):
|
||||
return
|
||||
|
||||
strSQL = f"UPDATE {strTableName} SET \'{strColName}\' = \'{strValue}\' WHERE id = {nID};"
|
||||
self.SQLExecute(self.cursor, strSQL)
|
||||
strSQL = f"UPDATE {strTableName} SET \"{strColName}\" = ? WHERE id = ?;"
|
||||
self.SQLExecute_Params(self.cursor, strSQL, (strValue, nID))
|
||||
|
||||
|
||||
# 하나의 조건에 맞는 항목의 한 컬럼을 지정해서 값을 가져온다.
|
||||
@@ -87,8 +122,8 @@ class MgrSQLiteDB:
|
||||
if True == util.IsEmptyStr(strTableName) or True == util.IsEmptyStr(strGetCol) or True == util.IsEmptyStr(strCompCol):
|
||||
return []
|
||||
|
||||
strSQL = f"SELECT {strGetCol} FROM {strTableName} WHERE {strCompCol} = {strCompValue};"
|
||||
listRet = self.SQLExecute_Get(self.cursor, strSQL)
|
||||
strSQL = f"SELECT {strGetCol} FROM {strTableName} WHERE {strCompCol} = ?;"
|
||||
listRet = self.SQLExecute_Get_Params(self.cursor, strSQL, (strCompValue,))
|
||||
|
||||
if listRet is None or 0 >= len(listRet):
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user