U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ SQL » SqlFormat() bug with Date and Time types
SqlFormat() bug with Date and Time types [message #9603] Sun, 20 May 2007 15:03 Go to next message
zsolt is currently offline  zsolt
Messages: 702
Registered: December 2005
Location: Budapest, Hungary
Contributor
SqlFormat() generates some trash characters with Date and Time arguments.
As a result, you can not use dates and times in your SQL queries.
Here is the testcase:
#include <Core/Core.h>
#include <Sql/Sql.h>

using namespace Upp;


CONSOLE_APP_MAIN
{
	Date sysdate = GetSysDate();	
	String s = SqlFormat(sysdate);
	Cout() << "Todays date is: " << s;
	while(1)
		Sleep(1000);
}

Re: SqlFormat() bug with Date and Time types [message #9604 is a reply to message #9603] Sun, 20 May 2007 15:21 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 702
Registered: December 2005
Location: Budapest, Hungary
Contributor
As a fast hack, I use this code in SqlCase.cpp
String SqlFormat(Date x)
{
	return FormatDate(x, "'YYYY-MM-DD'");
	//return MakeSqlValue(SQLC_DATE, x);
}

String SqlFormat(Time x)
{
	return FormatTime(x, "'YYYY-MM-DD hh:mm:ss'");
	//return MakeSqlValue(SQLC_TIME, x);
}



But I think, this should depend on current database handler.
Re: SqlFormat() bug with Date and Time types [message #9605 is a reply to message #9604] Sun, 20 May 2007 18:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Sorry, I should have perhaps renamed (or hide) SqlFormat.

It works OK. Just it creates the text that is to be compiled for target RDBMS (those odd characters...).

Use SqlCompile to get the final text.

Mirek
Re: SqlFormat() bug with Date and Time types [message #9607 is a reply to message #9605] Sun, 20 May 2007 22:06 Go to previous message
zsolt is currently offline  zsolt
Messages: 702
Registered: December 2005
Location: Budapest, Hungary
Contributor
Quote:

Use SqlCompile to get the final text.

Thanks, this is the key sentence Smile
Previous Topic: SQL "AS" for PostgreSQL fixed
Next Topic: PostgreSQL fieldname case bug
Goto Forum:
  


Current Time: Sun Apr 26 15:08:01 GMT+2 2026

Total time taken to generate the page: 0.00571 seconds