]> Softwares of Agnibho - librevax.git/blob - transaction.py
Database dump
[librevax.git] / transaction.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):
9 try:
10 cursor.execute("INSERT INTO transactions (iid, date, action, target, memo, data) VALUES (?, ?, ?, ?, ?, ?)", (data["iid"], data["date"], data["action"], data["target"], data["memo"], ""))
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, tid):
19 try:
20 result=cursor.execute("SELECT * FROM transactions WHERE tid=?", (tid,))
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, tid, data):
29 try:
30 cursor.execute("UPDATE transactions SET date=?, action=?, target=?, memo=? WHERE tid=?", (data["date"], data["action"], data["target"], data["memo"], tid))
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, tid):
39 try:
40 cursor.execute("DELETE FROM transactions WHERE tid=?", (tid,))
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, iid):
49 try:
50 result=cursor.execute("SELECT * FROM transactions WHERE iid=? ORDER BY date", (iid,))
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)