The Silk Performer medium-level interface provides access to DBMSs via ODBC. The medium-level interface gives you more control when accessing the database than is possible with the high-level interface.
The main characteristics of the medium-level interface are:
DB_Api functions work with SQL commands defined in the dclsql section. See Datatype SQL.
Automatic binding is supported.
Automatic error handling is provided.
Cursors must be declared explicitly (in contrast to the high-level interface). See Datatype cursor.
Multiple connects to DBMSs are possible within a single transaction.
The following example shows the TSelling transaction from above using the medium-level interface.
use "DBAPI.bdh"; dclrand rAno: RndUniN(1..2000); var hDBC1, ano, stock : number; c1, c2 : cursor; dcltrans transaction DBApiSelling var i : number; bFirst : boolean init true; begin if bFirst then //connecting, only executed on first call bFirst := false; hDBC1 := DB_Connect("dsn=sample;uid=u1;pwd=u1"); SQLSetConnectOption(hDBC1, SQL_AUTOCOMMIT, 0); DB_AllocCursor(hDBC1, c1); DB_AllocCursor(hDBC1, c2); DB_Prepare(c1, SelArticle); DB_Prepare(c2, UpdStock); end; for i := 1 to RndUniN(4..7) do ano := rAno; DB_Execute(c1); fetch c1 next 1; DB_Execute(c2); end; DB_Commit(hDBC1); end DBApiSelling; dclsql SelArticle: SELECT a_name, a_cat, a_price, a_stock INTO *, *, *, :stock FROM article WHERE a_no = :ano; UpdStock: UPDATE article SET a_stock = 99999 WHERE a_no = :ano;
The medium-level interface consists of the following database access functions (DB_Api functions):