用C接口PGgetvalue 获取PG数据库里面的interge类型的数据时,输出的是负数,但是interge类型数据本身是正数,PGgetvalue 返回类型为char * ,已被强转为int *型,求高人指点
解决方案 »
- 关于hibernate 条件差旬 的问题 (mysql)
- mysql如何应付千万级别的数据量查询,愿闻其详
- mysql中该用什么语句赋值?
- 在windows上如何实现两个mysql?
- sql语句 查询
- [MySQL] 找不到要更新的资料行, 最后读取的值已被变更
- 使用query()循环插入出现MySQL server has gone away错误
- 如何自动删除数据库???
- 问一个mysql子查询的问题
- 提示Table storage engine for 'table_name' doesn't have this option,我该如何解决
- MySQL开机不能自动启动
- 关于mysql数据库Transfer的疑问
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
static void exit_nicely(PGconn* conn)
{
PQfinish(conn);
exit(1);
}int
main(int argc, char **argv)
{
const char *conninfo;
PGconn *conn;
PGresult *res;
int nFields;
int i,
j; if (argc > 1)
conninfo = argv[1];
else
conninfo = "dbname = iihero"; conn = PQconnectdb(conninfo); if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
exit_nicely(conn);
} /* create a table in advance */
/* create table t123(id integer primary key, col2 varchar(32)) */
/* insert into t123 values(100, 'wang') */
/* Start a transaction block */
res = PQexec(conn, "SELECT * FROM t123");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "BEGIN command failed: %s", PQerrorMessage(conn));
PQclear(res);
exit_nicely(conn);
} /* first, print out the attribute names */
nFields = PQnfields(res);
for (i = 0; i < nFields; i++)
printf("%-15s", PQfname(res, i));
printf("\n\n"); for (i = 0; i < PQntuples(res); i++)
{
for (j = 0; j < nFields; j++)
printf("%-15s", PQgetvalue(res, i, j));
printf("\n");
} PQclear(res); PQfinish(conn); return 0;
}
结果是:
id col2100 wang
char* res = PQgetvalue(....);
判断一下res是否为空,或者调用PQgetisnull()先。
int n = atoi(res);
这样也会溢出?
那你的正数是如何读出来的?通过psql命令行?
你的客户端程序,是在x86平台上,服务器用的是sparc或者别的不同架构上?
能具体说说你的环境吗?
psql也是用c api实现的。
你是在什么情况下得到正数的(通过什么客户端,客户端机器的具体环境(CPU,操作系统))?
什么情况下得到负数的(通过什么客户端,客户端机器的具体环境(CPU,操作系统))?
只有弄清楚了这些,才知道根本原因。
谨慎怀疑是环境问题。
这个是cpu的信息,其实是在本机的虚拟机上运行的
内核版本:Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux
正数和负数都是通过这个虚拟机上的linux获得