|
|
Home » Community » Newbie corner » Help needed with Convert class
Help needed with Convert class [message #40753] |
Thu, 12 September 2013 20:50  |
pacoquintana
Messages: 12 Registered: December 2011 Location: Spain
|
Promising Member |
|
|
Hi all.:
I need some help about date time format and convert
In my application I use SQLITE 3 with a column to store date and time in a TIME column
in app.layout an sqlArray has to columns, one to display date and the next one to display time coming from the same colum time in sqlite.
Working with a convert class to display date in the first sqlArray.column and time in the next one so :
Convert& DateDateConvert();
Convert& DateTimeConvert();
struct DateDateConvertCls : Convert {
virtual Value Format(const Value& q) const;
};
Value DateDateConvertCls::Format(const Value& q) const
{
Time d = q;
return !d.IsValid() ? String() : ::Format("%1:04d-%2:02d-%3:02d", d.year, d.month, d.day);
}
Convert& DateDateConvert()
{
return Single<DateDateConvertCls>();
}
struct DateTimeConvertCls : Convert {
virtual Value Format(const Value& q) const;
};
Value DateTimeConvertCls::Format(const Value& q) const
{
Time d = q;
return !d.IsValid() ? String() : ::Format("%1:02d-%2:02d-%3:02d", d.hour, d.minute, d.second);
}
Convert& DateTimeConvert()
{
return Single<DateTimeConvertCls>();
}
In the Layout :
qs.AddColumn(O_DATE, "fecha").SetConvert(DateDateConvert());
qs.AddColumnAt(1, "Hora").SetConvert(DateTimeConvert());
It compiles and link but I get an Assertion error.
I can not understand how Convert class woks, so any "good Elmer" can explain me how it works ?
Thank you very much
1add1f71cc45f0a88caa948bf339b589
|
|
|
|
Re: Help needed with Convert class [message #40760 is a reply to message #40758] |
Fri, 13 September 2013 13:20   |
pacoquintana
Messages: 12 Registered: December 2011 Location: Spain
|
Promising Member |
|
|
Thanks for help.
In mainLayout I replaced my code with the one you suggested (adding Single template) but error is the same :
Assertion failed in E:\upp_portable_win32\src/uppsrc/Core/Value.hpp line 142 t<255 &&(t==STRING_V ? IsString() : Is((byte)t))
1add1f71cc45f0a88caa948bf339b589
|
|
|
Re: Help needed with Convert class [message #40764 is a reply to message #40760] |
Fri, 13 September 2013 17:55   |
 |
BioBytes
Messages: 308 Registered: October 2008 Location: France
|
Senior Member |
|
|
Hi,
Which version of UPP are you using ? I am running SVN 6331 Under Win 7 for example.
Another suggestion, why not using Date formatting scan functions :
Quote: |
void SetDateScan(const char *scan)
Sets date scan string - this string represents order of day, month and year for StrToDate function. Letters 'd', 'm' and 'y' are used in scan to designate the order. This is per-thread setting with threads inheriting the setting of main thread.
Example:
"mdy"
The month is first, day second and year third.
|
Regards
BioBytes
[Updated on: Fri, 13 September 2013 18:05] Report message to a moderator
|
|
|
|
Re: Help needed with Convert class [message #40768 is a reply to message #40766] |
Fri, 13 September 2013 22:50   |
 |
BioBytes
Messages: 308 Registered: October 2008 Location: France
|
Senior Member |
|
|
Perhaps you could consider to upgrade your Upp system to the most recent file ? and see if the same error still appears.
I tried the following code without any assert errors using MSC 9 or MSC 10 compilers : Sorry I do not use MingW.
Main file
#include "EsConvert.h"
void EsConvertMainWin::fillGrid()
{
for(int i=0;i<5;++i)aGridCtrl.Add(i+1,Date(2013,9,13)+i,Time(12,12,10)+i);
}
void EsConvertMainWin::close()
{
Close();
}
EsConvertMainWin::EsConvertMainWin()
{
CtrlLayout(*this, "Convert study");
SetRect(0,0,800,600);
CenterScreen();
aGridCtrl.AddColumn("N°",30,false).AlignCenter();
aGridCtrl.AddColumn("Date",100,false).AlignCenter().SetConvert(Single<MyDataDateConvert>());
aGridCtrl.AddColumn("Time",100,false).AlignCenter().SetConvert(Single<MyDataTimeConvert>());
fillBtn<<=THISBACK(fillGrid);
closeBtn<<=THISBACK(close);
}
GUI_APP_MAIN
{
SetLNGCharset(GetSystemLNG(),CHARSET_UTF8);
EsConvertMainWin().Run();
}
Header file
#ifndef _EsConvert_EsConvert_h
#define _EsConvert_EsConvert_h
#include <CtrlLib/CtrlLib.h>
#include <GridCtrl/GridCtrl.h>
using namespace Upp;
#define LAYOUTFILE <EsConvert/EsConvert.lay>
#include <CtrlCore/lay.h>
struct MyDataDateConvert : Convert
{
Value Format(const Value& q) const
{
const Date& d = q;
return !d.IsValid() ? String() : ::Format("%1:02d-%2:02d-%3:02d", d.day, d.month, d.year);
}
};
struct MyDataTimeConvert : Convert
{
Value Format(const Value& q) const
{
const Time& d = q;
return !d.IsValid() ? String() : ::Format("%1:02d-%2:02d-%3:02d", d.hour, d.minute, d.second);
}
};
class EsConvertMainWin : public WithEsConvertMainWinLayout<TopWindow> {
public:
typedef EsConvertMainWin CLASSNAME;
void fillGrid();
void close();
EsConvertMainWin();
};
#endif
Regards
Biobytes
[Updated on: Sat, 14 September 2013 08:42] Report message to a moderator
|
|
|
Re: Help needed with Convert class [message #40786 is a reply to message #40768] |
Mon, 16 September 2013 13:57   |
pacoquintana
Messages: 12 Registered: December 2011 Location: Spain
|
Promising Member |
|
|
Absolutely, your code compiles and link and has no assertion errors, I tried Microsoft linker and mingw.
The only difference with my code is that you assing dates to vars directly and mine obtains dates from a SQLite 3 database, as Sqlite works as if everything inside is a string maybe colums are returned to the programm as string and not as dates or some other structure that cannot be coverted to date inside the format public function of convert structure.
I will continue investigating.
Can you test to obtain dates from a column of a sqlite database ?
Thak you very much
Sorry about the delay (free weekend)
Best regards
Paco
1add1f71cc45f0a88caa948bf339b589
|
|
|
Re: Help needed with Convert class [message #40805 is a reply to message #40786] |
Fri, 20 September 2013 10:56   |
pacoquintana
Messages: 12 Registered: December 2011 Location: Spain
|
Promising Member |
|
|
I found an answer from Mirek to a problem lije this one and talk about the assertion error in case you got any structure not convertible to time estructure, maybe this is why in the example SQLAPP dates are stored in SQLite as integers and then converted into dates
Best regards
paco
1add1f71cc45f0a88caa948bf339b589
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 18:32:59 CEST 2025
Total time taken to generate the page: 0.02744 seconds
|
|
|