我有 Sybase ASE CPRE 嵌入式 SQL С 代码:
void MyFunc( MyClass*unit_address )
{
EXEC SQL BEGIN DECLARE SECTION;
CS_BINARY var1[sizeof(MyClass)];
EXEC SQL END DECLARE SECTION;
}
尝试迁移到 PostgreSQL ECPG Embedded SQLС 代码:
void MyFunc( MyClass*unit_address )
{
EXEC SQL BEGIN DECLARE SECTION;
unsigned char var1[sizeof(MyClass)];
EXEC SQL END DECLARE SECTION;
}
但是 ecpg.exec 预编译器返回:
d:\>"c:\Program Files\PostgreSQL\9.3\bin\ecpg.exe"-o 1.c 1.pgc
1.pgc: 4: ERROR: syntax error at or near "("
error deleting output file "1.c"
我的解决方案:
void MyFunc( MyClass*unit_address )
{
#define VAR1_SIZEOF sizeof(MyClass)
EXEC SQL BEGIN DECLARE SECTION;
unsigned char var1[VAR1_SIZEOF];
EXEC SQL END DECLARE SECTION;
#undef VAR1_SIZEOF
}
预编译后的函数C代码:
void MyFunc( MyClass*unit_address )
{
#define VAR1_SIZEOF sizeof(MyClass)
/* exec sql begin declare section */
#line 1 "1.pgc"
void MyFunc( MyClass*unit_address )
{
#define VAR1_SIZEOF sizeof(MyClass)
/* exec sql begin declare section */
#line 5 "1.pgc"
unsigned char var1 [ VAR1_SIZEOF ] ;
/* exec sql end declare section */
#line 6 "1.pgc"
#undef VAR1_SIZEOF
}
但也许有一个更正确的决定。