⍝ Quad_SQL.tc
⍝ ----------------------------------

      ]NEXTFILE no-SQLITE3   ⍝ done if SQLITE3 is not available

      Filename ← "testcases/test_Quad_SQL.db"

      ⍝ erase old database (if any)
      ⍝
      ⊣⎕FIO.unlink Filename

      create←,⊃"""
CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL);
               """

      ⍝ connect to DB and list tables
      ⍝
      DB←'sqlite' ⎕SQL[1] Filename
      ⊣create ⎕SQL[3, DB] ''

      ⎕SQL[8] DB
 COMPANY 

      ⍝ list table columns
      ⍝
      DB ⎕SQL[9] 'COMPANY'
 ID      INT      
 NAME    TEXT     
 AGE     INT      
 ADDRESS CHAR(50) 
 SALARY  REAL     

      ⍝ Add records
      ⍝
      insert←'INSERT INTO COMPANY(ID,NAME,AGE,ADDRESS,SALARY) VALUES(?,?,?,?,?)'
      insert ⎕SQL[3, DB] 1 'Paul'  32 'California' 20000.00

      insert ⎕SQL[3, DB] 2 'Allen' 25 'Texas'      15000.00

      insert←'INSERT INTO COMPANY VALUES(?,?,?,?,?)'
      insert ⎕SQL[3, DB] 3 'Teddy' 23 'Norway'     20000.00


      select←'SELECT ID,NAME,AGE FROM COMPANY'
      select ⎕SQL[4, DB] ''
 1 Paul  32 
 2 Allen 25 
 3 Teddy 23 

      update←'UPDATE COMPANY SET SALARY=? where ID=?'
      update ⎕SQL[4, DB] 22000 3        ⍝ increase TTeddy's salary

      select←'SELECT ID, NAME, SALARY FROM COMPANY'
      select ⎕SQL[4, DB] ''
 1 Paul  20000 
 2 Allen 15000 
 3 Teddy 22000 

      ⍝ using function name syntax
      ⍝
      update ⎕SQL.update DB (17000 2)     ⍝ increase Allan's salary

      select←'SELECT ID, NAME, SALARY FROM COMPANY'

      select ⎕SQL.query DB ''
 1 Paul  20000 
 2 Allen 17000 
 3 Teddy 22000 

      ⎕SQL[2] DB   ⍝ close DB


      ⍝ remove the database
      ⍝
      ⎕FIO.unlink Filename
0

      )ERASE DB create insert select

      )CHECK
OK      - no stale functions
OK      - no stale values
OK      - no stale indices
OK      - no duplicate parents

⍝ ==================================

