]> Softwares of Agnibho - librevax.git/blob - advice.py
Database dump
[librevax.git] / advice.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, pid):
9 try:
10 cursor.execute("INSERT INTO advice (pid, mid, date, findings, advice, consultant, data) VALUES (?, ?, ?, ?, ?, ?, ?)", (data["pid"], data["mid"], data["date"], data["findings"], data["advice"], data["consultant"], ""))
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 return (False, e)
17
18 def read(cursor, aid):
19 try:
20 result=cursor.execute("SELECT * FROM advice WHERE aid=?", (aid,))
21 if(cursor.rowcount==0):
22 return (False, "Record not found.")
23 else:
24 return (True, result.fetchone())
25 except Exception as e:
26 return (False, e)
27
28 def update(cursor, aid, data):
29 try:
30 cursor.execute("UPDATE advice SET date=?, findings=?, advice=?, consultant=? WHERE aid=?", (data["date"], data["findings"], data["advice"], data["consultant"], aid))
31 if(cursor.rowcount==0):
32 return (False, "Failed to update record.")
33 else:
34 return (True, cursor.lastrowid)
35 except Exception as e:
36 return (False, e)
37
38 def delete(cursor, aid):
39 try:
40 cursor.execute("DELETE FROM advice WHERE aid=?", (aid,))
41 if(cursor.rowcount==0):
42 return (False, "Failed to delete record.")
43 else:
44 return (True, cursor.lastrowid)
45 except Exception as e:
46 return (False, e)
47
48 def list(cursor, pid):
49 try:
50 result=cursor.execute("SELECT * FROM advice WHERE pid=?", (pid,))
51 if(cursor.rowcount==0):
52 return (False, "Record not found.")
53 else:
54 return (True, result.fetchall())
55 except Exception as e:
56 return (False, e)