Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Date pasted in GridCtrl saved in sqlite. Problem and solution
Date pasted in GridCtrl saved in sqlite. Problem and solution [message #17704] |
Tue, 26 August 2008 22:05 |
|
koldo
Messages: 3358 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
I have found another problem and I propose you a solution.
The source of this is because when pasting in GridCtrl:
- From the GridCTrl, as it knows the type of the cells, the type of the Value of the cells is right
- From outside, as it does not know the type, all data are Values of type String
Using the standard SetDateScan there is no problem, but when changing it (for examle SetDateScan("dmy")), when inserting or updating the row in GridCtrl through grid.WhenInsertRow() callback the function called:
SQL & ::Insert(MYTABLE)
(NAME, grid(NAME))
(DATE, grid(DATE));
grid(ID) = SQL.GetInsertedId();
goes wrong because although the date looks right in GridCtrl, it has been saved wrong in sqlite file.
Solution, not perfect but it works: I convert the Value String in a Value Date before inserting or updating in sqlite, so the last code would be:
SQL & ::Insert(MYTABLE)
(NAME, grid(NAME))
(DATE, FixDate(grid(DATE)));
grid(ID) = SQL.GetInsertedId();
where FixDate is defined:
Value FixDate(Value &val)
{
if (!val.IsNull()) {
if (!val.Is<Date>()) {
Date d;
StrToDate(d, val.ToString());
return d;
}
}
return val;
}
StrToDate cares of converting the String into a right Date considering the SetDateScan defined.
Comments?
Best regards
Iñaki
[Updated on: Tue, 26 August 2008 22:08] Report message to a moderator
|
|
|
|
|
Re: Date pasted in GridCtrl saved in sqlite. Problem and solution [message #17841 is a reply to message #17838] |
Sat, 30 August 2008 21:22 |
|
koldo wrote on Sat, 30 August 2008 09:14 | Hello amrein
I do not know if calling it a bug, but perhaps it is an improvement.
When you add a column, for example:
myGrid.AddColumn(BIRTHDAY, t_("Birthday")).Edit(birthdate);
GridCtrl does not know the type, so it can only manage the data as Value(String).
Perhaps it would be possible to do a kind of SQLGridCtrl class that:
- You could include the database table, so it would know about the type of every column
- It would include inside the functions LoadTable, InsertRow, UpdateRow and RemoveRow.
Well, a little soon for me and perhaps it is a thing that unodgs has to decide.
Best regards
|
I have added WhenPasteCell<int row, int col, Value& v> callback. It's called when you paste data from clipboard. If you create your own method and assign it to this callback you will be able to return back the correct value (with correct type). In Excel scenario that means Value(String) will be passed to the callback method. Now you know what type of column number "col" is and you know how to convert String to this value. Maybe better will be example :
void MyConventer(int row, int col, Value& v)
{
if(col == 0) //int
{
v = StrToInt(v);
}
else if(col = 10)
{
v = DblToInt(v);
}
}
grid.WhenPasteCell = THISBACK(MyConventer);
I think this will help in your "clipboard problem"
Regarding SqlGridCtrl. It's a good idea but it will be part of GridCtrl 2.0. Generaly 2.0 will be much more sql related (of course I'll try to do my best to save backward compatibility).
|
|
|
|
Goto Forum:
Current Time: Sun Apr 28 22:58:35 CEST 2024
Total time taken to generate the page: 0.02852 seconds
|