From 72f0a7832a578df32e017fb2bd3eec8da4d52671 Mon Sep 17 00:00:00 2001 From: raymoo Date: Thu, 25 Feb 2016 21:26:05 -0800 Subject: [PATCH] Fix crash --- exchange.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exchange.lua b/exchange.lua index b9b2b77..c715d3a 100644 --- a/exchange.lua +++ b/exchange.lua @@ -50,6 +50,9 @@ ON Orders (Poster, Type, Time, Item, Rate); CREATE INDEX if not exists index_inbox ON Inbox (Recipient); +CREATE VIEW if not exists distinct_items AS +SELECT DISTINCT Item FROM Orders; + END TRANSACTION; ]=] @@ -649,6 +652,11 @@ function ex_methods.buy(self, p_name, ex_name, item_name, amount, rate) local db = self.db local bal = self:get_balance(p_name) + + if not bal then + return false, "Nonexistent account." + end + if bal < amount * rate then return false, "Not enough money." end