#include<stdio.h>
#include<error.h>
#include<sys/shm.h>
#include "/opt/PostgreSQL/9.1/include/libpq-fe.h"
int main()
{
PGconn *conn;
int buf_ptr=0;
int i;
{
fprintf(stderr,"connection to database failed:%s",PQerrorMessage(conn));
exit(0);
}
else
{
printf("connection to database successful \n");
}
printf("Do you want to create a table enter 1 \n ");
scanf("%d",&i);
if(i==1)
{
EXEC SQl CREATE TABLE EMPOYE(
ENO INT,
ENAME VARCHAR(10));
}
return 0;
}
你好,我是一个新手,我正在学习嵌入式c 我想创建一个简单的代码,其中在 c 中创建一个表 当我编译上面的程序时,我收到如下错误
embc.c:25: error: âEXECâ undeclared (first use in this function)
embc.c:25: error: (Each undeclared identifier is reported only once
embc.c:25: error: for each function it appears in.)
embc.c:25: error: expected â;â before âSQlâ
please help
最佳答案
首先,与数据库的连接丢失,您应该有类似的内容:
int i=0;
EXEC SQL CONNECT TO target [AS connection-name] [USER user-name];
或者
PGconn *conn;
int buf_ptr=0;
int i=0;
conn = PQconnectdbParams(const char **keywords, const char **values, int expand_dbname);
然后将源文件另存为 prog.pgc 并运行:
ecpg prog.pgc
这将创建一个名为 prog.c 的文件,该文件可以编译为标准 C 文件。
关于sql - 嵌入sql的程序出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18120121/