Download SIMSCRIPT II.5 Database Connectivity User Manual

Transcript
6. Example Program: Bank Simulation
main
define DSNAME, USERNAME, PASSWORD as text variables
write as "Enter data source name:", /
read DSNAME
write as "Enter user name:", /
read USERNAME
write as "Enter password:", /
read PASSWORD
call DB.CONNECT.R(DSNAME, USERNAME, PASSWORD)
if DB.EXISTS.F("BANKSIM") = 0 ''BANKSIM table does not exist
call CREATE.TABLE
''so create it
always
create every TELLER(1)
call MAIN.LOOP
call DB.DISCONNECT.R
end
routine CREATE.TABLE
define SQL as a text variable
define ROWS as an integer variable
''construct an SQL CREATE TABLE statement
SQL = CONCAT.F(
"CREATE TABLE BANKSIM ",
"(RUNID
INTEGER NOT NULL PRIMARY KEY,",
" TELLERS INTEGER NOT NULL,",
" IATIME REAL
NOT NULL,",
" SRVTIME REAL
NOT NULL,",
" UTIL
REAL,",
" AVGQLEN REAL,",
" MAXQLEN INTEGER)")
''create the table
ROWS = DB.UPDATE.F(SQL)
end
29