cry3212001 发表于 2009-3-27 16:24:17

mysql中插入double型数据的问题

程序是用c++编写的。我的情况是这样的:现在mysql中建立了个表:Temeputre,含myid与temp,其中temp是double型的。在客户端有个程序,如下:
int mysql_insert_temp(double data)
{
MYSQL mydata;
double insert_temp=0.0;
insert_temp = data;
cout<<"insert_temp"<<insert_temp<<endl;//data的值可以传给insert_temp
if(NULL==mysql_init(&mydata))
{
cout<<"failed to init mysql"<<endl;
}
if(NULL==mysql_real_connect(&mydata,"localhost","root","root","test",MYSQL_PORT,NULL,0))
{
cout<<"failed to connect to mysql"<<endl;
}
char *s_sql=NULL;
s_sql="insert into tempeture (temp) values('insert_temp')";
if(mysql_query(&mydata,s_sql)!=0)
{
cout<<"query db failed"<<endl<<mysql_error(&mydata)<<endl;
}
insert_temp=0.0;
mysql_close(&mydata);
return 1;
}
问题是:我现在运行程序后在mysql中temp项都是0.0000,但是我如果将insert_temp换成具体的数字。如63.45699时,表tempeture中的temp项就有数据(为63.45699)。所以在c++语言中怎么象mysql数据库中插入double型的数据呢?谢谢
页: [1]
查看完整版本: mysql中插入double型数据的问题