-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconnectdb.py
39 lines (29 loc) · 1.12 KB
/
connectdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import asyncio
import sqlite3
mutex_for_store = asyncio.Lock()
async def select_from_db(sql):
connect = sqlite3.connect('./erpdata.db') # Connect to the SQLite database file 'erp.db'
cursor = connect.cursor() # Use cursor() to get a cursor
cursor.execute(sql) # Execute the SQL statement
results = cursor.fetchall() # Get all results
connect.commit()
cursor.close()
connect.close()
return results
async def exec_sql(sql):
connect = sqlite3.connect('./erpdata.db') # Connect to the SQLite database file 'erp.db'
cursor = connect.cursor() # Use cursor() to get a cursor
cursor.execute(sql) # Execute the SQL statement
connect.commit()
cursor.close()
connect.close()
return
async def get_supply_available():
supply_available = []
sql_res = await select_from_db("""select DISTINCT inventory."父物料名称" from inventory""")
for item in sql_res:
if item[0] != "" and item[0] is not None:
supply_available.append(item)
return supply_available
async def get_store_available():
return await select_from_db("""select * from store""")