0
#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;
}

你好我是一个新手我正在学习嵌入式ci想要创建一个简单的代码,当我编译上面的程序时在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   
4

1 回答 1

1

首先,缺少与数据库的连接,您应该有以下内容:

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 文件。

于 2013-08-08T08:00:21.557 回答