
--
-- Sampledb SQL database for AceQL usage tested with:
--  DB2 9.7+, 
--  Informix 11.70+, 
--  MySQL 5.5+,
--  PostgreSQL 8.4.1+,
--  Oracle 11g Release 2+, 
--  SQL Server 2008 R2+, 
--  Sybase AES 15.7+,
--  Sybase SQL Anywhere 12+.
--  Terradata 13.0+
-- 
-- NOTES 
-- Change the type of the following columns according to your database:
-- ==> orderlog.date_shipped,  
-- ==> orderlog.jpeg_image, 

CREATE TABLE users
(               
  username              varchar(300)    not null,     
  encrypted_password    varchar(300)    not null,
        PRIMARY KEY (username)
);

CREATE TABLE user_login
(               
  username              varchar(255)    not null,     
  hash_password         varchar(40)     not null,
        PRIMARY KEY (username)
);


CREATE TABLE banned_usernames
(               
  username              varchar(255)    not null,     
        PRIMARY KEY (username)
);


CREATE TABLE customer
(
    customer_id     integer     not null,
    customer_title  char(4)         null,
    fname           varchar(32)     null,
    lname           varchar(32) not null,
    addressline     varchar(64) not null,
    town            varchar(32) not null,
    zipcode         char(10)    not null,
    phone           varchar(32)     null,
        PRIMARY KEY(customer_id)
);

CREATE TABLE product_image
(
    product_id  integer     not null,
    name        varchar(64) not null,

    --  longblob for MySQL 
    --  blob for DB2 & HSQLDB & Informix & Oracle  & Terradata 
    --  oid For PostgreSQL / VarBinary(max) for SQL Server  
    --  Image for Sybase AES & Sybase SQL Anywhere
    	image oid null, 

        PRIMARY KEY(product_id)
);

--
-- orderlog table 
-- 

CREATE TABLE orderlog
(
    customer_id     integer     not null,
    item_id         integer     not null,
    description     varchar(64) not null,
    item_cost	    numeric     null,
    date_placed     date        not null,
    
    -- datetime for SQL Server & Sybase AES  & Sybase SQL Anywhere
    -- DATETIME YEAR TO FRACTION(5) for INFORMIX  
    -- timestamp for others.
    date_shipped    timestamp 	null, 
    
    --  longblob for MySQL 
    --  blob for DB2 & HSQLDB & Informix & Oracle  & Terradata 
    --  oid For PostgreSQL / VarBinary(max) for SQL Server  
    --  Image for Sybase AES & Sybase SQL Anywhere
    jpeg_image      oid 	null, 

    is_delivered    integer     null,
    quantity        integer     not null,    
         PRIMARY KEY(customer_id, item_id)
);

--
-- Example of a table with an auto-increment primary index
--

CREATE TABLE customer_auto
(
    -- PostgreSQL & Informix:
    customer_id  serial  not null,
    
    -- IBM DB2: 
    -- customer_id int not null GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
    
    -- H2 & MySql:
    -- customer_id int not null auto_increment,
    
    -- HSQLDB:
    -- customer_id int  GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
    
    -- Sybase SQL Anywhere: 
    -- customer_id int not null DEFAULT AUTOINCREMENT,
    
    -- SQL Server:
    -- customer_id int not null IDENTITY(1, 1),
    
    -- Sybase ASE: 
    -- customer_id numeric(12,0) identity,
    
    -- Terradata:
    -- customer_id INTEGER GENERATED ALWAYS AS IDENTITY NOT NULL,
    
    customer_title  char(4)     null,
    fname           varchar(32) null,
    lname           varchar(32) not null,
    addressline     varchar(64) null,
    town            varchar(32) null,
    zipcode         char(10)    not null,
    phone           varchar(32) null,
        PRIMARY KEY(customer_id)
);

--
-- documentation table
-- A CLOB example.

CREATE TABLE documentation
(
    item_id         integer     not null,
    
    -- longtext  CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL for MySQL  
    -- clob for DB2 & HSQLDB & Informix & Oracle  & Terradata  
    -- text for PostgreSQL. 
    -- VarChar(max) for SQL Server / text for Sybase AES & Sybase SQL Anywhere
    item_doc text NOT NULL,         
    
         PRIMARY KEY(item_id)
);

--
-- Init the users table with a (username, encrypted_password)
--

insert into users values ('username', '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8');
