我的结构定义如下:
typedef struct{
int v1;
int v2;
}INFOS_HND;
INFOS_HND hnd_list[100];
EXEC SQL BEGIN DECLARE SECTION;
char statement[200];
int current_row = 0;
EXEC SQL END DECLARE SECTION;
我在pro C / C ++中使用此语句。
snprintf(statement, sizeof(statement), "select i1, i2, from table_a");
这是我的SQL指令:
EXEC SQL PREPARE SEL_INSTR FROM :statement;
EXEC SQL DECLARE MY_CURSOR CURSOR FOR SEL_INSTR;
EXEC SQL OPEN MY_CURSOR;
EXEC SQL WHENEVER NOT FOUND DO break;
while(1){
EXEC SQL FETCH MY_CURSOR INTO :hnd_list[current_row].v1, :hnd_list[current_row].v2;
current_row++;
EXEC SQL CLOSE MY_CURSOR;
编译时会显示以下错误:
PCC-S-02322, found undefined identifier
Semantic error at line 53, column 10, file my_file:
EXEC SQL FETCH MY_CURSOR INTO :hnd_list[current_row].v1;
PCC-S-02327, struct or struct pointer required
Semantic error at line 53, column 10, file my_file:
EXEC SQL FETCH MY_CURSOR INTO :hnd_list[current_row].v1;
PCC-S-02322, found undefined identifier
Semantic error at line 53, column 30, file my_file:
EXEC SQL FETCH MY_CURSOR INTO :hnd_list[current_row].v2;
PCC-S-02327, struct or struct pointer required
Semantic error at line 53, column 30, file my_file:
EXEC SQL FETCH MY_CURSOR INTO :hnd_list[current_row].v2;
答案 0 :(得分:0)
类型和变量定义在PRO * C / C ++ DECLARE块之外声明。因此预编译器无法解析声明。尝试在块内移动它们,如下所示:
EXEC SQL BEGIN DECLARE SECTION;
typedef struct{
int v1;
int v2;
}INFOS_HND;
INFOS_HND hnd_list[100];
char statement[200];
int current_row = 0;
EXEC SQL END DECLARE SECTION;