Differences between DB2 UDB CLI and embedded SQL

 

DB2® UDB call level interface (CLI) and embedded SQL differ in many ways.

An application that uses an embedded SQL interface requires a precompiler to convert the SQL statements into code. Code is compiled, bound to the database, and processed. In contrast, a DB2 UDB CLI application does not require precompilation or binding, but instead uses a standard set of functions to run SQL statements and related services at run time.

This difference is important because, traditionally, precompilers have been specific to a database product, which effectively ties your applications to that product. DB2 UDB CLI enables you to write portable applications that are independent of any particular database product. This independence means that a DB2 UDB CLI application does not need to be recompiled or rebound to access-different database products. An application selects the appropriate database products at run time. DB2 UDB CLI and embedded SQL also differ in the following ways:

Despite these differences, there is an important common concept between embedded SQL and DB2 UDB CLI:


Table 1 lists each SQL statement, and whether it can be processed using DB2 UDB CLI.

Table 1. SQL statements
SQL statement Dyn 1 CLI 3
ALTER TABLE X X
BEGIN DECLARE SECTION 2    
CALL X X
CLOSE   SQLFreeStmt()
COMMENT ON X X
COMMIT X SQLTransact(), SQLEndTran()
CONNECT (Type 1)   SQLConnect()
CONNECT (Type 2)   SQLConnect()
CREATE INDEX X X
CREATE TABLE X X
CREATE VIEW X X
DECLARE CURSOR b   SQLAllocStmt()
DELETE X X
DESCRIBE   SQLDescribeCol(), SQLColAttributes()
DISCONNECT   SQLDisconnect()
DROP X X
END DECLARE SECTION b    
EXECUTE   SQLExecute()
EXECUTE IMMEDIATE   SQLExecDirect()
FETCH   SQLFetch()
GRANT X X
INCLUDE b    
INSERT X X
LOCK TABLE X X
OPEN   SQLExecute(), SQLExecDirect()
PREPARE   SQLPrepare()
RELEASE   SQLDisconnect()
REVOKE X X
ROLLBACK X SQLTransact(), SQLEndTran()
SELECT X X
SET CONNECTION    
UPDATE X X
WHENEVER 2    
Notes:

1

Dyn stands for dynamic. All statements in this list can be coded as static SQL, but only those marked with X can be coded as dynamic SQL.

2

This is a nonprocessable statement.

3

An X indicates that this statement can be processed using either SQLExecDirect() or SQLPrepare() and SQLExecute(). If there is an equivalent DB2 UDB CLI function, the function name is listed.

Each DBMS might have additional statements that can be dynamically prepared, in which case DB2 UDB CLI passes them to the DBMS. There is one exception, COMMIT and ROLLBACK can be dynamically prepared by some DBMSs but are not passed. Instead, the SQLTransact() or SQLEndTran() should be used to specify either COMMIT or ROLLBACK.

 

Parent topic:

Getting started with DB2 UDB CLI