Archived
update: 更新了不同数据库的sql语句问题
This commit is contained in:
1 file changed
+7
-3
+7
-3
@@ -14,6 +14,7 @@ class DatabaseSQL:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.conn = None
|
self.conn = None
|
||||||
self.cursor = None
|
self.cursor = None
|
||||||
|
self.target = None
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
@@ -30,7 +31,7 @@ class DatabaseSQL:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def insert(self, _id: str) -> bool:
|
def insert(self, _id: str) -> bool:
|
||||||
self.cursor.execute('insert into data (id, times) values ("%s", 1);' % _id)
|
self.cursor.execute('insert into data (id, times) values (%s, 1);' % self.target % _id)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def update(self, _id: str, times: int) -> bool:
|
def update(self, _id: str, times: int) -> bool:
|
||||||
@@ -43,8 +44,8 @@ class DatabaseSQL:
|
|||||||
result = self.cursor.fetchall()
|
result = self.cursor.fetchall()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def query_image(self, _id: str) -> list:
|
def query_image(self, theme: str) -> list:
|
||||||
self.cursor.execute('select * from image where id="%s";' % _id)
|
self.cursor.execute('select * from %s;' % self.target % theme)
|
||||||
result = self.cursor.fetchall()
|
result = self.cursor.fetchall()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -54,6 +55,8 @@ class SQLite(DatabaseSQL):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.conn = operator.connect('./src/db/data.sqlite')
|
self.conn = operator.connect('./src/db/data.sqlite')
|
||||||
self.cursor = self.conn.cursor()
|
self.cursor = self.conn.cursor()
|
||||||
|
self.target = '"%s"'
|
||||||
|
print(self.target)
|
||||||
|
|
||||||
|
|
||||||
class MySQL(DatabaseSQL):
|
class MySQL(DatabaseSQL):
|
||||||
@@ -71,3 +74,4 @@ class MySQL(DatabaseSQL):
|
|||||||
database=db
|
database=db
|
||||||
)
|
)
|
||||||
self.cursor = self.conn.cursor()
|
self.cursor = self.conn.cursor()
|
||||||
|
self.target = 'Counter.%s'
|
||||||
Reference in New Issue
Block a user