]> Softwares of Agnibho - librevax.git/blob - inventory.py
Database dump
[librevax.git] / inventory.py
1 # LibreVax
2 # Copyright (C) 2024 Dr. Agnibho Mondal
3 # This file is part of LibreVax.
4 # LibreVax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 # LibreVax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6 # You should have received a copy of the GNU General Public License along with LibreVax. If not, see <https://www.gnu.org/licenses/>.
7
8 def create(cursor, data, available):
9 try:
10 cursor.execute("INSERT INTO inventory (mid, vaccine, altname, dose, dpv, route, batch, doe, available, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (data["mid"], data["vaccine"], data["altname"], data["dose"], data["dpv"], data["route"], data["batch"], data["doe"], available, ""))
11 if(cursor.rowcount==0):
12 return (False, "Failed to create record.")
13 else:
14 return (True, cursor.lastrowid)
15 except Exception as e:
16 raise(e)
17 return (False, e)
18
19 def read(cursor, iid):
20 try:
21 result=cursor.execute("SELECT * FROM inventory WHERE iid=?", (iid,))
22 if(cursor.rowcount==0):
23 return (False, "Record not found.")
24 else:
25 return (True, result.fetchone())
26 except Exception as e:
27 return (False, e)
28
29 def update(cursor, iid, data, available):
30 try:
31 cursor.execute("UPDATE inventory SET vaccine=?, altname=?, dose=?, dpv=?, route=?, batch=?, doe=?, available=? WHERE iid=?", (data["vaccine"], data["altname"], data["dose"], data["dpv"], data["route"], data["batch"], data["doe"], available, iid))
32 if(cursor.rowcount==0):
33 return (False, "Failed to update record.")
34 else:
35 return (True, cursor.lastrowid)
36 except Exception as e:
37 return (False, e)
38
39 def delete(cursor, iid):
40 try:
41 cursor.execute("DELETE FROM inventory WHERE iid=?", (iid,))
42 if(cursor.rowcount==0):
43 return (False, "Failed to delete record.")
44 else:
45 return (True, cursor.lastrowid)
46 except Exception as e:
47 return (False, e)
48
49 def list(cursor, mid, all=False):
50 try:
51 if(all):
52 result=cursor.execute("SELECT * FROM inventory WHERE mid=? ORDER BY available DESC", (mid,))
53 else:
54 result=cursor.execute("SELECT * FROM inventory WHERE mid=? AND available=?", (mid, True))
55 if(cursor.rowcount==0):
56 return (False, "Record not found.")
57 else:
58 return (True, result.fetchall())
59 except Exception as e:
60 return (False, e)