sql - 嵌入sql的程序出现编译错误

标签 sql c embedded-sql

#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/

相关文章:

c - Pro *C 查询 IN 子句中的多个动态值

php - 如何访问嵌套 MySQL 查询内部的行

mysql - SQL GROUP BY 不保持正确的顺序

php - Mysql创建排序索引性能简单频繁查询

c - 请验证我对这个与结构相关的事情的想法是否正确

oracle - 将记录从 Oracle 数组移动到 Cobol

c - 查询执行中的 Oracle pro*c 指标变量与 NVL

sql - 从另一个表中加入具有最大值的表

c - 减去两个时间间隔

c - 努力按整数搜索文件中的结构数组