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 » 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 Go to next message
koldo is currently offline  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 #17813 is a reply to message #17704] Fri, 29 August 2008 20:18 Go to previous messageGo to next message
amrein is currently offline  amrein
Messages: 278
Registered: August 2008
Location: France
Experienced Member
I think the problem come from SQLite types support and from how the data is converted when it is saved (U++ bug):

http://sqlite.org/datatype3.html

[Updated on: Fri, 29 August 2008 20:19]

Report message to a moderator

Re: Date pasted in GridCtrl saved in sqlite. Problem and solution [message #17838 is a reply to message #17813] Sat, 30 August 2008 15:14 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3358
Registered: August 2008
Senior Veteran
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


Best regards
Iñaki
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 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

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 Smile :
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).
Re: Date pasted in GridCtrl saved in sqlite. Problem and solution [message #17861 is a reply to message #17841] Sun, 31 August 2008 20:01 Go to previous message
koldo is currently offline  koldo
Messages: 3358
Registered: August 2008
Senior Veteran
For me it is fine. Thank you!

Best regards
Iñaki
Previous Topic: Unicode character paste in GridCtrl
Next Topic: Hiding in GridCtrl. Special case.
Goto Forum:
  


Current Time: Mon Apr 29 00:16:44 CEST 2024

Total time taken to generate the page: 0.03681 seconds