Table of Contents |
---|
APRE compile options
APRE has three parse-options. (refer to this document).
If you want to declare host-variables without "EXEC SQL BEGIN DECLARE" and "EXEC SQL END DECLARE" clauses,
You have to use option like "-parse full".
Data Types
Internal Type in DB | C Type in your source-code | Description |
---|---|---|
NUMERIC-Types | short, int, long, double, float |
|
VARCHAR | char, char[n] varchar[n] | Single character or n-byte character array varchar is "struct { int len; char arr[n] ;} " |
CHAR | char, char[n] | N-byte character array |
NUMBER(p,s) | short int long float double | Small integer integer large integer floating point number double-precision floating point number |
DATE | char[n] SQL_DATE_STRUCTSQL_TIME_STRUCTSQL_TIMESTAMP_STRUCT | N-byte character array year, month, day : small integer hour, minute, second : small integer year, month, day, hour, minute, second : small integer and fraction : integer |
BINARY | APRE_CLOBAPRE_BLOBAPRE_BINARYAPRE_BYTESAPRE_NIBBLE | N-byte charater array. Definition in APRE is as follows. typedef char APRE_CLOB; typedef char APRE_BLOB; typedef char APRE_BINARY; typedef char APRE_BYTES; typedef char APRE_NIBBLE; |
- APRE doesn't support a "ROWID" type.
- APRE doesn't support "LONG" and "RAW" type.
- For example, Even though you can use a char-type host-variable for integer-column, We don't recommend a conversion between char-type and numeric-type.
INDICATOR
You can use every host-varaible with optional indicator-varaible defined as 4-byte integer.
Indicator-variable indicates that a return-value from DB is NULL.
Code Block |
---|
char name[20]; int name_ind; ... EXEC SQL SELECT name INTO :name INDICATOR :name_ind FROM employees ... // or EXEC SQL SELECT name INTO :name :name_ind FROM employees ... \\ * If indicator-value is "-1" as output, it means that NULL was returned. * If indicator-value is "-1" as input, DBMS will assign a NULL to the column, ignoring the value of host-variable. |
CURSOR Variable
APRE doesn't support a cursor-variable like "SQL_CURSOR".
CONTEXT Variable
APRE doesn't support a context-variable like "ALLOCATE", "CONTEXT".
HOST Structure
You can use a structure host-variable as follows.
Code Block |
---|
typedef struct { char emp_name[21]; int emp_age; } emp_record; ... emp_record new_emp; sprintf(new_emp.emp_name, "ckh0618"); new_emp.emp_age = 35; EXEC SQL INSERT INTO employee (ename, age) VALUES (:new_emp); // or EXEC SQL SELECT ename, age INTO :new_emp FROM employee; |
APRE supports host-structure and arrays...
Code Block |
---|
typedef struct { char emp_name[30][21]; int emp_age[30]; } emp_record; ... |
You can not use a structure type in structure like ORACLE.
- APRE supports "For" clauses.int rows_to_insert;
rows_to_insert = 2;
EXEC SQL FOR :rows_to_insert INSERT INTO employee VALUES (:array_variable);
You can use Indicator structure and arrays as follows.
Code Block |
---|
typedef struct { char emp_name[21]; int emp_age; } emp_record; typedef struct { int name_ind; int age_ind; } emp_ind; emp_record new_rec; emp_ind new_ind; EXEC SQL SELECT name, age INTO :new_rec INDICATOR :emp_ind FROM employee; |
Indicator structure arrays sample-code.
Code Block |
---|
typedef struct { char emp_name[30][21]; int emp_age[30]; } emp_record; typedef struct { int name_ind[30]; int age_ind[30]; } emp_ind; emp_record new_rec; emp_ind new_ind; EXEC SQL SELECT name, age INTO :new_rec INDICATOR :emp_ind FROM employee; |
POINTER type
You can use a pointer type.
Code Block |
---|
.... char *ptr; ptr = (char*)malloc(100); ... EXEC SQL SELECT name INTO :ptr FROM employee... |
Also, You can use it as follows.
Code Block |
---|
typedef struct { char emp_name[30][21]; int emp_age[30]; } emp_record; emp_record *rec; rec = (emp_record*)malloc(sizeof(emp_record)); ... EXEC SQL SELECT name, age INTO :rec FROM employee ... ... printf ("name = %s, age = %d\n", rec->name, rec->age); |
CONVBUFSZ
It is not supported-feature.