Quote:
Originally Posted by Inverness
No such thing as sub-tables in this case. The syntax you're thinking of is for creating a table in a database other than the default, which is useless in this case since there is only one database. Just create a normal table.
|
Simply because the syntax is incorrect doesn't mean that what I'm trying to do is impossible, mind you. I've considered using a separate table, but would favor my original plan to avoid overly-complicated referencing.
I've looked in to creating VIEWS, but I'm not sure if I'm doing it correctly.
PHP Code:
sql.execute(
"CREATE TABLE IF NOT EXISTS shops (
title TEXT NOT NULL DEFAULT 'Shop',
stype TEXT NOT NULL DEFAULT 'Server',
owner TEXT NOT NULL DEFAULT 'Unknown',
arch TEXT NOT NULL DEFAULT 'Unknown',
price INT DEFAULT 0,
stock INT DEFAULT 0,
kerou INT NOT NULL DEFAULT 5000,
desc TEXT NOT NULL DEFAULT 'Description text.',
createtime INT NOT NULL DEFAULT CURRENT_TIMESTAMP)", false);
sql.execute(
"CREATE VIEW shopitems AS SELECT arch, price, stock FROM shops", false);
sql.execute(
"CREATE TRIGGER insert_item INSTEAD OF INSERT ON shopitems
BEGIN
INSERT INTO shops (arch, price, stock) VALUES (arch, price, stock);
END;
CREATE TRIGGER update_item INSTEAD OF UPDATE ON shopitems
BEGIN
UPDATE shops SET arch = new.arch;
UPDATE shops SET price = new.price;
UPDATE shops SET stock = new.stock;
END;", false);