Skip to content

Commit

Permalink
log deposits too
Browse files Browse the repository at this point in the history
  • Loading branch information
esmil committed Nov 12, 2012
1 parent a52e82d commit 03f530f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drinkomatic.lua
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions structure.sql
Expand Up @@ -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,
Expand Down

0 comments on commit 03f530f

Please sign in to comment.