After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 650016 - datamodel gdouble operations locale sensivity
datamodel gdouble operations locale sensivity
Status: RESOLVED FIXED
Product: libgda
Classification: Other
Component: general
4.2.x
Other Linux
: Normal normal
: ---
Assigned To: malerba
gnome-db Maintainers
Depends on:
Blocks:
 
 
Reported: 2011-05-12 09:06 UTC by Adam Jabłoński
Modified: 2011-05-18 16:27 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Adam Jabłoński 2011-05-12 09:06:09 UTC
Updating DataModel with gdouble value cuts off decimal part if locale decimal point is set to comma, so

Gda::DataModel::ValueVector vec;
vec.push_back (Gda::Value((gdouble)7364.23));
...
datamodel->set_values(0,vec);

above updates value 7364.0 to the database
Tested db was mysql
Tested locale were pl_PL.utf8

Workaround is to set locale for application to en_US.utf8 (or any other where default numerical decimal point is dot)
Comment 1 malerba 2011-05-15 08:02:05 UTC
Could you provide a standalone program which shows the bug (program + test data)? That would help a lot.
Thanks
Comment 2 Adam Jabłoński 2011-05-17 08:23:41 UTC
/*
create database test;
use test;
create table taxrates(
taxrateid int primary key auto_increment,
taxname varchar(20),
taxrate decimal (18,5)
);
insert into taxrates (taxname,taxrate) values ('22%',22.5);
*/

#include <iostream>
#include <libgdamm.h>
#include <libgdamm/handlernumerical.h>
using namespace Gnome;
int main()
{
	std::cout << "Hello world!" << std::endl;
	setlocale(LC_NUMERIC,"pl_PL.utf8");
	Gda::init();
	
	Glib::RefPtr<Gda::Connection> con = Gda::Connection::open_from_string("MySQL","HOST=localhost;DB_NAME=test","USERNAME=root;PASSWORD=pass");	
	
	Glib::RefPtr<Gda::SqlParser> parser= con->create_parser();
	Glib::RefPtr<Gda::Statement> stmt = parser->parse_string("SELECT taxrateid,taxname,taxrate FROM taxrates");
	Glib::RefPtr<Gda::DataModel> model = con->statement_execute_select(stmt,Gda::STATEMENT_MODEL_ALLOW_NOPARAM | Gda::STATEMENT_MODEL_RANDOM_ACCESS);
	con->update_meta_store ();
	
	Glib::RefPtr<Gda::DataSelect> ds= Glib::RefPtr<Gda::DataSelect>::cast_dynamic(model)	;
	stmt = parser->parse_string("INSERT INTO taxrates (taxname,taxrate) VALUES (##+1::string,##+2::gdouble)");
	ds->set_modification_statement (stmt);
	stmt = parser->parse_string("UPDATE taxrates SET taxname=##+1::string::NULL,taxrate=##+2::gdouble::NULL WHERE taxrateid=##-0::gint");
	ds->set_modification_statement (stmt);
	stmt = parser->parse_string("DELETE FROM taxrates WHERE taxrateid=##-0::gint:NULL");
	ds->set_modification_statement (stmt);	

	
	Gda::DataModel::ValueVector vec;

	vec.push_back (Gda::Value((int)1));
	vec.push_back (Gda::Value(Glib::ustring("22%")));
	vec.push_back (Gda::Value((gdouble)7364.23));
	Glib::RefPtr<Gda::HandlerNumerical> nh=Gda::HandlerNumerical::create();
	std::cout<<nh->get_str_from_value (Gda::Value((gdouble)7364.23)) <<std::endl;
	model->set_values(0,vec);		
	return 0;
}
/*
select taxname,taxrate from taxrates 
will give improper value  
+---------+------------+
| taxname | taxrate    |
+---------+------------+
| 22%     | 7364.00000 |

changing setlocale(LC_NUMERIC,"en_US.utf8");
will cause proper value
+---------+------------+
| taxname | taxrate    |
+---------+------------+
| 22%     | 7364.23000 |


*/
Comment 3 malerba 2011-05-18 16:27:23 UTC
This is now corrected in git/master and LIBGDA_4.2 branches: http://git.gnome.org/browse/libgda/commit/?h=LIBGDA_4.2&id=32be9b20cb8c3b2918e8fdd2c1952c6c91b16d8e
Thanks for the bug report!