오랜만이라 뭐가 수정된지 잘 몰라서 일단 커밋
This commit is contained in:
+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