Thread: SQLite
View Single Post
  #46  
Old 04-14-2009, 11:09 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Inverness View Post
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); 
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote