Dynamic SQL
ALTIBASE HDB supports method-1, 2, 3 except method-4 like oracle.
Method-1
Code Block |
---|
|
char query [1024];
...
sprintf (query, "INSERT INTO employee values ('andy park', 40)");
EXEC SQL EXECUTE IMMEDIATE :query;
|
- This method can process only DML-statement except SELECT-statment.
Method-2
Code Block |
---|
|
char query [1024];
char ename [40];
int age;
...
sprintf (query, "INSERT INTO employee values ('andy park', 40)");
EXEC SQL PREPARE stmt1 FROM :query;
...
sprintf (ename, "andy park");
age = 40;
EXEC SQL EXECUTE stmt1 USING :ename, :age;
|
- This method can process only DML-statement except SELECT-statment.
Method-3
Code Block |
---|
|
char query [1024];
char ename [40];
...
sprintf (query, "SELECT * FROM employee WHERE name = ?");
EXEC SQL PREPARE sel_stmt FROM :query;
...
EXEC SQL DECLARE cursor1 CURSOR FOR sel_stmt;
...
sprintf (ename, "andy park");
EXEC SQL OPEN cursor1 USING :ename;
...
|
- ALTIBASE HDB doesn't support a "Fetch Across Commit".
Therefore, If you execute a commit while fetching records, your cursor will be closed.
Method-4
ALTIBASE HDB doesn't support this type.