Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » Huge error of Postgresql! Double fields by transmission to the program lose a fractional part!
Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47491] Mon, 23 January 2017 02:28 Go to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Huge error of Postgresql!
Double fields by transmission to the program from sql table lose a fractional part!

The decision is extremely simple. To scan a string not as int (atoi), but as Double (ScanDouble).
The request to correct quickly as soon as it is possible!

Place to correct:
file PostgreSQL.cpp
Fucntion: void PostgreSQLConnection::GetColumn(int i, Ref f) const
Line: 644
Now:
	switch(info[i].type)
	{
		case INT64_V:
			f.SetValue(ScanInt64(s));
			break;
		case INT_V:
			f.SetValue(atoi(s));
			break;
		case DOUBLE_V:
			f.SetValue(atoi(s));         //<========THIS LINE NEED TO CORRECT
			break;
		case BOOL_V:
			f.SetValue(*s == 't' ? "1" : "0");
			break;
		case DATE_V:
			f.SetValue(sDate(s));
			break;
		case TIME_V: {
				Time t = ToTime(sDate(s));
				t.hour = atoi(s + 11);
				t.minute = atoi(s + 14);
				t.second = atoi(s + 17);
				f.SetValue(t);
			}
			break;
		default: {

   . . . . . 


Must be:
	switch(info[i].type)
	{
		case INT64_V:
			f.SetValue(ScanInt64(s));
			break;
		case INT_V:
			f.SetValue(atoi(s));
			break;
		case DOUBLE_V:
			f.SetValue(ScanDouble(s));
			break;
		case BOOL_V:
			f.SetValue(*s == 't' ? "1" : "0");
			break;
		case DATE_V:
			f.SetValue(sDate(s));
			break;
		case TIME_V: {
				Time t = ToTime(sDate(s));
				t.hour = atoi(s + 11);
				t.minute = atoi(s + 14);
				t.second = atoi(s + 17);
				f.SetValue(t);
			}
			break;
		default: {

   . . . . . 


Thanks!


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47492 is a reply to message #47491] Mon, 23 January 2017 07:34 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

That proves one thing - noone uses double fields Smile
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47494 is a reply to message #47492] Mon, 23 January 2017 08:38 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

There is a way that I had to first use. It was necessary to specify in the query string conversion.

SQL.Execute("DBL_FIELD::text FROM SOMETABLE");


But yesterday I thought: Yes, how am I going to suffer. Opened in debugger with incremental execution. And I horrified, how all of this is simple.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47496 is a reply to message #47494] Mon, 23 January 2017 09:38 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

It seems like release blocker Wink Added to redmine - I believe we should fix this before release - http://www.ultimatepp.org/redmine/issues/1617.

Sergey can you monitor redmine ticket?

Sincerely,
Klugier


U++ - one framework to rule them all.
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47499 is a reply to message #47496] Mon, 23 January 2017 09:46 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Yes. I can. I've Add myself to this issue.

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Mon, 23 January 2017 09:51]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47514 is a reply to message #47499] Wed, 25 January 2017 11:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Mon, 23 January 2017 09:46
Yes. I can. I've Add myself to this issue.


I really wonder what U++ revision you are using, because in trunk it is:

void PostgreSQLConnection::GetColumn(int i, Ref f) const
{
	if(PQgetisnull(result, fetched_row, i))
	{
		f = Null;
		return;
	}
	char *s = PQgetvalue(result, fetched_row, i);
	switch(info[i].type)
	{
		case INT64_V:
			f.SetValue(ScanInt64(s));
			break;
		case INT_V:
			f.SetValue(atoi(s));
			break;
		case DOUBLE_V:
			f.SetValue(atof(s));
			break;


and it is really really unlikely that this bug could get there in last 8 years, because in that period my major project is PGSQL and customers would really notice this within hours...

I have checked svn history and oldest revision available from 2009 has "atof" there...

Mirek

[Updated on: Wed, 25 January 2017 11:31]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47519 is a reply to message #47514] Wed, 25 January 2017 18:18 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

mirek wrote on Wed, 25 January 2017 13:30
sergeynikitin wrote on Mon, 23 January 2017 09:46
Yes. I can. I've Add myself to this issue.


I really wonder what U++ revision you are using, because in trunk it is:

void PostgreSQLConnection::GetColumn(int i, Ref f) const
{
	if(PQgetisnull(result, fetched_row, i))
	{
		f = Null;
		return;
	}
	char *s = PQgetvalue(result, fetched_row, i);
	switch(info[i].type)
	{
		case INT64_V:
			f.SetValue(ScanInt64(s));
			break;
		case INT_V:
			f.SetValue(atoi(s));
			break;
		case DOUBLE_V:
			f.SetValue(atof(s));
			break;


and it is really really unlikely that this bug could get there in last 8 years, because in that period my major project is PGSQL and customers would really notice this within hours...

I have checked svn history and oldest revision available from 2009 has "atof" there...

Mirek

I use summer svn code. (with c++11 support).

If all correct, - it's OK! I've locally corrected version of PostgreSQL.cpp.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47520 is a reply to message #47519] Wed, 25 January 2017 18:35 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I've just tested variant of atof(s):
Result on picture:

index.php?t=getfile&id=5183&private=0

May be ScanDouble with language settings can be accurater?...


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47521 is a reply to message #47520] Wed, 25 January 2017 18:37 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Sorry... I do it best regards, and with hope.

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47522 is a reply to message #47521] Wed, 25 January 2017 18:42 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Sergey,

The issue was closed on redmine as "Rejected".

Sincerely and thanks for feedback,
Klugier


U++ - one framework to rule them all.

[Updated on: Wed, 25 January 2017 18:43]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47523 is a reply to message #47522] Wed, 25 January 2017 18:54 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Why closed? I place there picture, where error is still exists!

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Wed, 25 January 2017 18:54]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47524 is a reply to message #47523] Wed, 25 January 2017 19:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Wed, 25 January 2017 18:54
Why closed? I place there picture, where error is still exists!


Actually, I have suspiction here...

Can you check how that 's' looks like? (E.g. put DUMP(s) before atof).

I suspect that maybe, your PGSQL is returning decimal comma and atof is unable to handle that, which ScanDouble is.

It would be strange borderline issue, but really worth fixing.

(OTOH, 'atoi' was NEVER there, sorry. You can check svn log....)

Mirek
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47526 is a reply to message #47523] Wed, 25 January 2017 19:03 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

Upps sorry, please close it by yourself when everything will be ok. I will not touch this issue any more.

Sincerely,
Klugier


U++ - one framework to rule them all.
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47529 is a reply to message #47524] Wed, 25 January 2017 19:31 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

When I place there code of, I mistaken, because already correct in my home code. But atof return same result as you can see at picture.

May be will different result if use other Set Language
( I use
	SetLanguage(LNGFromText("RU-RU"));
	
	SetDateFormat("%3:02d.%2:02d.%1:4d");




It's not tested yet. But ScanDouble work fine!


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Wed, 25 January 2017 19:33]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47530 is a reply to message #47529] Wed, 25 January 2017 19:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sure, but I need to know the root of the problem...
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47531 is a reply to message #47530] Wed, 25 January 2017 20:31 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I'll try to prepare test case tonight .

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47532 is a reply to message #47531] Wed, 25 January 2017 20:40 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Wed, 25 January 2017 20:31
I'll try to prepare test case tonight .


You do not understand...

I need to know what your PostgreSQL instance returns (before atof), so that I am sure we are doing the right fix.

Because very likely the problem is that your PostgreSQL is configured somehow differently than my PostgreSQL.

So pretty please, place DUMP(s) before atof (or ScanDouble), like

switch(info[i].type)
	{
		case INT64_V:
			f.SetValue(ScanInt64(s));
			break;
		case INT_V:
			f.SetValue(atoi(s));
			break;
		case DOUBLE_V:
DUMP(s);
			f.SetValue(ScanDouble(s));
			break;


then post here a log (a couple of lines is enough).

Thanks,

Mirek

[Updated on: Wed, 25 January 2017 20:48]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47534 is a reply to message #47532] Thu, 26 January 2017 01:00 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I see, I will.

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47535 is a reply to message #47534] Thu, 26 January 2017 01:25 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Modified code (while lang settings SetLanguage(LNGFromText("RU-RU"));:
	char *s = PQgetvalue(result, fetched_row, i);
	switch(info[i].type)
	{
		case INT64_V:
			f.SetValue(ScanInt64(s));
			break;
		case INT_V:
			f.SetValue(atoi(s));
			break;
		case DOUBLE_V:
			RLOG("===start analysis===");
			RDUMP(s);
			double da,dS;
			da = atof(s);
			dS = ScanDouble(s);
			RDUMP(da);
			RDUMP(dS);
			static String test_format_and_lang_settings;
			test_format_and_lang_settings = Format("%f",dS);
			RDUMP(test_format_and_lang_settings);
			RLOG("====end analysis====");
			RLOG(" ");
			f.SetValue(ScanDouble(s));
			break;
		case BOOL_V:
			f.SetValue(*s == 't' ? "1" : "0");
			break;
		case DATE_V:



Log:
26.01.2017 03:22:15 ===start analysis===
26.01.2017 03:22:15 s = 90
26.01.2017 03:22:15 da = 90
26.01.2017 03:22:15 dS = 90
26.01.2017 03:22:15 test_format_and_lang_settings = 90,000000
26.01.2017 03:22:15 ====end analysis====
26.01.2017 03:22:15  
26.01.2017 03:22:15 ===start analysis===
26.01.2017 03:22:15 s = 40
26.01.2017 03:22:15 da = 40
26.01.2017 03:22:15 dS = 40
26.01.2017 03:22:15 test_format_and_lang_settings = 40,000000
26.01.2017 03:22:15 ====end analysis====
26.01.2017 03:22:15  
26.01.2017 03:22:15 ===start analysis===
26.01.2017 03:22:15 s = 269.96336996337
26.01.2017 03:22:15 da = 269
26.01.2017 03:22:15 dS = 269.96336996337
26.01.2017 03:22:15 test_format_and_lang_settings = 269,963370
26.01.2017 03:22:15 ====end analysis====
26.01.2017 03:22:15  
26.01.2017 03:22:15 ===start analysis===
26.01.2017 03:22:15 s = 381.556455240666
26.01.2017 03:22:15 da = 381
26.01.2017 03:22:15 dS = 381.556455240666
26.01.2017 03:22:15 test_format_and_lang_settings = 381,556455
26.01.2017 03:22:15 ====end analysis====
26.01.2017 03:22:15  
26.01.2017 03:22:15 ===start analysis===
26.01.2017 03:22:15 s = 282.083413662361
26.01.2017 03:22:15 da = 282
26.01.2017 03:22:15 dS = 282.083413662361
26.01.2017 03:22:15 test_format_and_lang_settings = 282,083414
26.01.2017 03:22:15 ====end analysis====


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Thu, 26 January 2017 01:28]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47536 is a reply to message #47535] Thu, 26 January 2017 01:33 Go to previous messageGo to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

While lang settings SetLanguage(LNGFromText("EN-US");:

26.01.2017 03:26:34 ===start analysis===
26.01.2017 03:26:34 s = 40
26.01.2017 03:26:34 da = 40
26.01.2017 03:26:34 dS = 40
26.01.2017 03:26:34 test_format_and_lang_settings = 40,000000
26.01.2017 03:26:34 ====end analysis====
26.01.2017 03:26:34  
26.01.2017 03:26:34 ===start analysis===
26.01.2017 03:26:34 s = 269.96336996337
26.01.2017 03:26:34 da = 269
26.01.2017 03:26:34 dS = 269.96336996337
26.01.2017 03:26:34 test_format_and_lang_settings = 269,963370
26.01.2017 03:26:34 ====end analysis====
26.01.2017 03:26:34  
26.01.2017 03:26:34 ===start analysis===
26.01.2017 03:26:34 s = 59.95115995116
26.01.2017 03:26:34 da = 59
26.01.2017 03:26:34 dS = 59.95115995116
26.01.2017 03:26:34 test_format_and_lang_settings = 59,951160
26.01.2017 03:26:34 ====end analysis====
26.01.2017 03:26:34  
26.01.2017 03:26:34 ===start analysis===
26.01.2017 03:26:34 s = 222.435897435897
26.01.2017 03:26:34 da = 222
26.01.2017 03:26:34 dS = 222.435897435897
26.01.2017 03:26:34 test_format_and_lang_settings = 222,435897
26.01.2017 03:26:34 ====end analysis====
26.01.2017 03:26:34  


Both test under UBUNTU 16.04 (with Russian main language)


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Thu, 26 January 2017 01:52]

Report message to a moderator

Previous Topic: I propose to Add Postgresql to topic header
Next Topic: How can .sch express a many-to-many relationship ?
Goto Forum:
  


Current Time: Thu Mar 28 13:26:00 CET 2024

Total time taken to generate the page: 0.02095 seconds