This example inserts data into the table:
CREATE STATEMENT INS1 INSERT INTO TAB(COL1, COL2) VALUES('ABC', :COL2_VALUE)
The table used can easily be created using the following statements:
CREATE TABLE tab (col1 VARCHAR(30),
col2 NCHAR VARYING(50),
col3 VARCHAR(10));
INSERT INTO tab VALUES ('Some', 'sample', 'text');
INSERT INTO tab VALUES ('ABC1', 'ABC', 'ABC');
INSERT INTO tab VALUES ('DEF', 'GHIJ', 'KLMN');
INSERT INTO tab VALUES ('OPQ2', 'rst', 'ABC');
INSERT INTO tab VALUES ('xyYZ', 'last', 'row');
The example looks as follows:
exec sql BEGIN DECLARE SECTION; varwchar_t c2[51]; varwchar_t st[100]; exec sql END DECLARE SECTION; exec sql CONNECT TO ' ' USER 'JOE' USING 'Secret'; wcscpy(c2, L"C2VAL"); wcscpy(st, L"execute statement INS1"); exec sql PREPARE STAT2 FROM :st; /* * The execute statement actually performs the * insert */ exec sql EXECUTE STAT2 USING :c2; exec sql COMMIT; exec sql DISCONNECT;
The program inserts a row into the table TAB and COL1 is set to ABC and COL2 is set to C2VAL. The varwchar_t is converted to a wchar_t (Unicode character string) by the preprocessor.
For more information on preprocessing embedded SQL, see Mimer SQL Programmer's Manual, Processing ESQL.