Differences between DB2 for i CLI and embedded SQL

DB2® for i 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 for i 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 for i CLI enables you to write portable applications that are independent of any particular database product. This independence means that a DB2 for i 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 for i CLI and embedded SQL also differ in the following ways:

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

Start of changeTable 1 lists each SQL statement, and whether it can be processed using DB2 for i CLI. End of change

Table 1. SQL statements
SQL statement Dyn 1 CLI 3
ALLOCATE CURSOR    
ALLOCATE DESCRIPTOR    
ASSOCIATE LOCATORS    
ALTER PROCEDURE X  
ALTER SEQUENCE X  
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 ALIAS X  
CREATE FUNCTION X  
CREATE INDEX X X
CREATE PROCEDURE X  
CREATE SCHEMA X  
CREATE SEQUENCE X  
CREATE TABLE X X
CREATE TRIGGER X  
CREATE TYPE X  
CREATE VARIABLE X X
CREATE VIEW X X
DEALLOCATE DESCRIPTOR    
DECLARE CURSOR b   SQLAllocStmt()
DECLARE GLOBAL TEMPORARY TABLE X  
DELETE X X
DESCRIBE   SQLDescribeCol(), SQLColAttribute()
DESCRIBE CURSOR    
DESCRIBE PROCEDURE    
DISCONNECT   SQLDisconnect()
DROP X X
END DECLARE SECTION b    
EXECUTE   SQLExecute()
EXECUTE IMMEDIATE   SQLExecDirect()
FETCH   SQLFetch()
FREE LOCATOR X SQLSetConnectAttr()
GET DESCRIPTOR    
GET DIAGNOSTICS    
GRANT X X
HOLD LOCATOR X  
INCLUDE b    
INSERT X X
LABEL X  
LOCK TABLE X X
MERGE X X
OPEN   SQLExecute(), SQLExecDirect()
PREPARE   SQLPrepare()
REFRESH TABLE X  
RELEASE   SQLDisconnect()
RELEASE SAVEPOINT X  
RENAME X  
REVOKE X X
ROLLBACK X SQLTransact(), SQLEndTran()
SAVEPOINT X  
SELECT X X
SET CONNECTION    
SET CURRENT DEBUG MODE X  
SET CURRENT DEGREE X  
SET CURRENT IMPLICIT XMLPARSE OPTION X SQLSetConnectAttr()
SET DESCRIPTOR    
SET ENCRYPTION PASSWORD X  
SET PATH X  
SET SCHEMA X  
SET SESSION AUTHORIZATION X  
SET RESULT SETS    
SET TRANSACTION X  
SIGNAL    
UPDATE X X
VALUES INTO 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 non-executable statement.
3
An X indicates that this statement can be processed using either SQLExecDirect() or SQLPrepare() and SQLExecute(). If there is an equivalent DB2 for i CLI function, the function name is listed.

Each DBMS might have additional statements that can be dynamically prepared, in which case DB2 for i 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.