Permalink
Browse files

log deposits too

  • Loading branch information...
1 parent a52e82d commit 03f530f6db8315c3eda2b35ad215f34c32ad438b @esmil esmil committed Nov 12, 2012
Showing with 9 additions and 4 deletions.
  1. +6 −4 drinkomatic.lua
  2. +3 −0 structure.sql
View
@@ -460,10 +460,12 @@ DEPOSIT = {
end
print(" Inserting %.2f DKK", n)
- assert(db:fetchone("\z
- UPDATE users \z
- SET balance = balance + ? \z
- WHERE id = ?", n, id))
+ assert(db:exec("\z
+ BEGIN; \z
+ UPDATE users SET balance = balance + @amount WHERE id = @id; \z
+ INSERT INTO log (dt, uid, pid, count, price) \z
+ VALUES (datetime('now'), @id, 1, 1, @amount); \z
+ COMMIT", { id = id, amount = n }))
local r = assert(db:fetchone(
"SELECT balance FROM users WHERE id = ?", id))
View
@@ -4,12 +4,15 @@ CREATE TABLE users (
hash VARCHAR(40) UNIQUE,
balance FLOAT
);
+
CREATE TABLE products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
barcode VARCHAR(40) UNIQUE,
price FLOAT,
name VARCHAR(255)
);
+INSERT INTO products VALUES (1,NULL,NULL,'Deposit');
+
CREATE TABLE log (
dt VARCHAR(23),
uid INTEGER,

0 comments on commit 03f530f

Please sign in to comment.