(* Collection of code snippets by Arne Vajhøj *)
(* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) *)
[inherit('psqlitedir:sqlite', 'psqlitedir:psqlite')]
program add(input, output);

%include 'customer2.pas'
%include 'order2.pas'

var
   con : sqlite_ptr;
   stmt : sqlite_stmt_ptr;
   stat : integer;

begin
   con := psqlite_open('test.db');
   stmt := psqlite_prepare(con, 'INSERT INTO customer VALUES(?,?,?)');
   customer_id := 6;
   customer_name := 'F company';
   customer_phone := '6666-6666';
   psqlite_bind_int(stmt, 1, customer_id);
   psqlite_bind_text(stmt, 2, customer_name);
   psqlite_bind_text(stmt, 3, customer_phone);
   psqlite_step_nonquery(stmt);
   psqlite_finalize(stmt);
   stmt := psqlite_prepare(con, 'INSERT INTO customer_actual VALUES(?,?,?,?,?)');
   customer_actual_id := 6;
   customer_actual_address1 := 'F road 6';
   customer_actual_address2 := 'F town';
   customer_actual_contact := 'Mr. F';
   customer_actual_discount := 10;
   psqlite_bind_int(stmt, 1, customer_actual_id);
   psqlite_bind_text(stmt, 2, customer_actual_address1);
   psqlite_bind_text(stmt, 3, customer_actual_address2);
   psqlite_bind_text(stmt, 4, customer_actual_contact);
   psqlite_bind_int(stmt, 5, customer_actual_discount);
   psqlite_step_nonquery(stmt);
   psqlite_finalize(stmt);
   stmt := psqlite_prepare(con, 'INSERT INTO order_main VALUES(?,?,?)');
   order_id := 6;
   order_customer := 6;
   order_status := 'In progress';
   psqlite_bind_int(stmt, 1, order_id);
   psqlite_bind_int(stmt, 2, order_customer);
   psqlite_bind_text(stmt, 3, order_status);
   psqlite_step_nonquery(stmt);
   psqlite_finalize(stmt);
   stmt := psqlite_prepare(con, 'INSERT INTO order_line VALUES(?,?,?,?,?)');
   order_line_id := 8;
   order_line_order := 6;
   order_line_item := 'X stuff';
   order_line_quantity := 1;
   order_line_price := 72.00;
   psqlite_bind_int(stmt, 1, order_line_id);
   psqlite_bind_int(stmt, 2, order_line_order);
   psqlite_bind_text(stmt, 3, order_line_item);
   psqlite_bind_int(stmt, 4, order_line_quantity);
   psqlite_bind_double(stmt, 5, order_line_price);
   psqlite_step_nonquery(stmt);
   psqlite_finalize(stmt);
   psqlite_close(con);
end.
