MODULE TestDebug01; IMPORT Dialog, Log, SqlDB; TYPE custRec* = RECORD customerId*: INTEGER; name*: ARRAY 1*(16+1) OF CHAR; location*: ARRAY 1*(8+1) OF CHAR; END; CONST tableDefCust = "CREATE TABLE customer (" + " customerId INTEGER NOT NULL PRIMARY KEY," + " name VARCHAR(16) NOT NULL," + " location VARCHAR(8) NOT NULL" + ")"; OdbcDriver = "SqlOdbc3"; OdbcDatabase = "zeiterfDb01"; (*change name for ODBC data source here *) VAR globalCust*: custRec; PROCEDURE createTableWithContent* (); VAR myDb: SqlDB.Database; result: INTEGER; myTab: SqlDB.Table; BEGIN (* open data base: asynch=FALSE, showErrorMessages=TRUE *) SqlDB.OpenDatabase( OdbcDriver, "", "", OdbcDatabase, FALSE, TRUE, myDb, result ); IF result = 0 THEN (* drop previosly defined table; ignore error, if the table does not exist *) myDb.Exec( "DROP TABLE customer" ); myDb.Exec( tableDefCust ); INC( result, myDb.res ); IF result=0 THEN myDb.Commit(); Dialog.ShowMsg( "tables have been successfully created" ) ELSE myDb.Rollback(); Dialog.ShowMsg( "some errors occured: tables were NOT created" ); END; (* ---- create sample content in data base ----*) myTab := myDb.NewTable(); (* ------------ *) globalCust.customerId := 4711; globalCust.name := "Bjoern Inc."; globalCust.location := "Erkrath"; myTab.Exec( "INSERT INTO customer VALUES (:TestDebug01.globalCust)" ); (* ------------ *) globalCust.customerId := 4721; globalCust.name := "Laura GmbH & Co"; globalCust.location := "HH"; myTab.Exec( "INSERT INTO customer VALUES (:TestDebug01.globalCust)" ); (* ------------ *) globalCust.customerId := 815; globalCust.name := "1234567890123456"; globalCust.location := "12345678"; myTab.Exec( "INSERT INTO customer VALUES (:TestDebug01.globalCust)" ); (* ------------ *) myTab.base.Commit; myTab := NIL; Dialog.ShowMsg("sample values inserted into data base"); END; myDb := NIL; END createTableWithContent; PROCEDURE dumpContent*; VAR myDb: SqlDB.Database; custTab: SqlDB.Table; result, i: INTEGER; BEGIN SqlDB.OpenDatabase( OdbcDriver, "", "", OdbcDatabase, FALSE, TRUE, myDb, result ); IF result=0 THEN custTab := myDb.NewTable(); custTab.Exec( "SELECT * FROM customer" ); FOR i:= 0 TO custTab.rows-1 DO custTab.Read( i, globalCust ); Log.Ln; Log.String( "customerId = " ); Log.Int( globalCust.customerId ); Log.Ln; Log.String( "name = <" ); Log.String( globalCust.name ); Log.Char(">"); Log.Ln; Log.String( "location = <" ); Log.String( globalCust.location ); Log.Char(">"); Log.Ln; END; custTab := NIL; myDb := NIL; ELSE Dialog.GetOK( "ERROR: can not open data base", "", "", "", {Dialog.ok}, result) END; END dumpContent; END TestDebug01.