//g++ gettableFIEldNum.cpp pqcopy.cpp -I /usr/local/pgsql/include/ -L/usr/local/pgsql/lib -lpq -o get -g
#include <libpq-fe.h>
#include <iostream>
#include "pqcopy.h"
using namespace std;
char pDBServer[STR_LEN+1];
char g_strDBname[STR_LEN +1];
char pDBUser[STR_LEN+1];
char pDBPwd[STR_LEN+1];
int g_nClIEntEn@R_301_5563@;
bool gettableColumn(char *par_strtablename,int &par_usColumnNO)
{
PGconn* pDBconn = NulL;
pDBconn = connectDB();
int status = -1;
PGresult *res = NulL;
char psql[STR_LEN +1] = {0};
snprintf(psql,STR_LEN,"select * from td_usergrp_waphost_d_20120416 limit 1;");
res = PQexec(pDBconn,"BEGIN");
if(PQresultStatus(res) != PGRES_COMMAND_OK) //成功完成一个不返回数据的命令
{
//LOG("执行BEGIN失败[%s]",PQerrorMessage(PGconn));
}
PQclear(res);
res = PQexec(pDBconn,psql);
status = PQresultStatus(res);
if (status != PGRES_TUPLES_OK) //成功执行一个返回数据的查询查询
{
LOG("查询表失败");
char *pStrError = PQerrorMessage(pDBconn);
printf("sql: %s\n",pStrError);
PQclear(res);
}
par_usColumnNO = PQnfIElds(res);
cout << PQnfIElds(res) << endl;
PQclear(res);
res = PQexec(pDBconn,"END");
PQclear(res);
}
int main()
{
strncpy( pDBServer,"192.168.227.128",STR_LEN );
strncpy(g_strDBname,"test",STR_LEN);
strncpy(pDBUser,"postgres",STR_LEN);
strncpy(pDBPwd,"123456",STR_LEN);
char strtable[100];
int usColumnNO = 0;
gettableColumn(strtable,usColumnNO);
cout << usColumnNO << endl; }
总结以上是内存溢出为你收集整理的postgreSQL获得指定表的列数全部内容,希望文章能够帮你解决postgreSQL获得指定表的列数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)