master
parent
58fee164a0
commit
d314218ef4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SonarLintProjectSettings">
|
||||
<option name="fileExclusions">
|
||||
<list>
|
||||
<option value="DIRECTORY:windows/res/ven" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,9 @@
|
||||
sonar.projectKey=test1
|
||||
sonar.projectName=test1
|
||||
sonar.projectVersion=1.0
|
||||
|
||||
sonar.sources=./src
|
||||
|
||||
sonar.java.binaries=./build/intermediates/javac/debug/classes
|
||||
sonarsourceEncoding=UTF-8
|
||||
sonar.language=java
|
@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -1,6 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/windows.iml" filepath="$PROJECT_DIR$/.idea/windows.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,185 +0,0 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
print(current_path)
|
||||
DB_FOLDER = current_path
|
||||
class DatabaseHandler:
|
||||
def __init__(self, database):
|
||||
self.database = os.path.join(DB_FOLDER, database)
|
||||
self.conn = None
|
||||
self.cur = None
|
||||
|
||||
def connect(self):
|
||||
self.conn = sqlite3.connect(self.database)
|
||||
self.cur = self.conn.cursor()
|
||||
|
||||
def create_table(self, table_name):
|
||||
self.cur.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (pid INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, path VARCHAR, xOffset INTEGER, yOffset INTEGER, pOffsetX INTEGER, pOffsetY INTEGER, time INTEGER, rgb VARCHAR);")
|
||||
self.conn.commit()
|
||||
print('创建成功')
|
||||
|
||||
def insert_data(self, table_name, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
pid = max_pid + 1
|
||||
else:
|
||||
pid = 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
except sqlite3.Error as e:
|
||||
print(f"插入数据失败: {str(e)}")
|
||||
|
||||
def insert_pidData(self, table_name, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb, pid=None):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
if pid > max_pid:
|
||||
pid = max_pid + 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
else:
|
||||
for i in range(max_pid, pid - 1, -1):
|
||||
self.cur.execute(
|
||||
f"UPDATE {table_name} SET pid = ? WHERE pid = ?",
|
||||
(i + 1, i))
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
else:
|
||||
pid = 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
except sqlite3.Error as e:
|
||||
print(f"插入数据失败: {str(e)}")
|
||||
|
||||
def execute_query(self, table_name, pid=None):
|
||||
try:
|
||||
if pid is None:
|
||||
self.cur.execute(f"SELECT pid, * FROM {table_name}")
|
||||
rows = self.cur.fetchall()
|
||||
for row in rows:
|
||||
pid = row[0] # 第0列是pid
|
||||
data = row[1:] # 后续列为数据
|
||||
print(f"pid: {pid}, data: {data}")
|
||||
return rows # 返回所有行的结果集
|
||||
else:
|
||||
self.cur.execute(f"SELECT * FROM {table_name} WHERE pid = ?", (pid,))
|
||||
row = self.cur.fetchone()
|
||||
if row:
|
||||
print(f"Row with pid {pid}: {row[1:]}")
|
||||
else:
|
||||
print(f"Row with pid {pid} not found")
|
||||
return row[1:]
|
||||
except Exception as e:
|
||||
print(f"Error executing query on table {table_name}: {str(e)}")
|
||||
|
||||
def delete_table(self, table_name):
|
||||
try:
|
||||
self.cur.execute(f"DROP TABLE IF EXISTS {table_name}")
|
||||
self.conn.commit()
|
||||
print(f"Table {table_name} deleted")
|
||||
except Exception as e:
|
||||
print(f"Error deleting table {table_name}: {str(e)}")
|
||||
|
||||
def delete_row(self, table_name, pid):
|
||||
try:
|
||||
# 1. 获取删除行的pid和其后面的所有pid
|
||||
self.cur.execute(f"SELECT pid FROM {table_name} WHERE pid >= ?", (pid,))
|
||||
rows_to_update = self.cur.fetchall()
|
||||
|
||||
# 2. 删除指定行
|
||||
self.cur.execute(f"SELECT path FROM {table_name} WHERE pid = ?", (pid,))
|
||||
path = self.cur.fetchall()
|
||||
self.cur.execute(f"DELETE FROM {table_name} WHERE pid = ?", (pid,))
|
||||
|
||||
# 3. 更新后面行的pid
|
||||
for row in rows_to_update:
|
||||
new_pid = row[0] - 1
|
||||
self.cur.execute(f"UPDATE {table_name} SET pid = ? WHERE pid = ?", (new_pid, row[0]))
|
||||
|
||||
self.conn.commit()
|
||||
print(f"Row with pid {pid} deleted from {table_name}")
|
||||
return path
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
def get_max_pid(self, table_name):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
return max_pid
|
||||
else:
|
||||
return 0
|
||||
except sqlite3.Error as e:
|
||||
print(f"获取最大 pid 失败: {str(e)}")
|
||||
return 0
|
||||
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
# 示例用法
|
||||
|
||||
class DatabaseDatum:
|
||||
def __init__(self, *args):
|
||||
self.id = args[0]
|
||||
self.path = args[1]
|
||||
self.xOffset = args[2]
|
||||
self.yOffset = args[3]
|
||||
self.pOffsetX = args[4]
|
||||
self.pOffsetY = args[5]
|
||||
self.time = args[6]
|
||||
self.rgb = args[7]
|
||||
|
||||
'''def get_path_by_pid(self, tablename, pid):
|
||||
db = DatabaseHandler(database='test2.sqlite3')
|
||||
db.connect()
|
||||
query = f"SELECT path FROM {tablename} WHERE pid = ?;"
|
||||
db.cur.execute(query, (pid,))
|
||||
result = db.cur.fetchone()
|
||||
db.close()
|
||||
|
||||
if result:
|
||||
self.path = result[0]
|
||||
else:
|
||||
self.path = None
|
||||
|
||||
return self.path
|
||||
'''
|
||||
# 创建一个DatabaseDatum对象
|
||||
|
||||
|
||||
|
||||
# 调用get_path_by_pid
|
||||
#(datum.get_path_by_pid('rule10',1))
|
||||
|
||||
|
||||
# db = DatabaseHandler(database='test2.sqlite3')
|
||||
# db.connect()
|
||||
# path = db.delete_row('rule13', 3)
|
||||
#
|
||||
# if path and len(path) > 0:
|
||||
# result = path[0][0]
|
||||
# print(result)
|
||||
# else:
|
||||
# print("No path found")
|
||||
#
|
||||
# db.close()
|
||||
#
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 4.6 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue