Ecere SDK/eC Forums • View topic - sqlite3 data binding to DataBox




Ecere SDK/eC Forums

Ecere Developers Community

sqlite3 data binding to DataBox

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.

sqlite3 data binding to DataBox

Postby samsam598 » Mon Aug 20, 2012 4:19 am

Hi ,

Could you please post here a piece of very simple code to demonstrate how to bind sqlite3 database to a (Saving)DataBox control?Thanks.

Regards,
Sam
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: sqlite3 data binding to DataBox

Postby jerome » Mon Aug 20, 2012 6:20 pm

Hi Sam,

First, you took a look at the MovieCollection sample already, right?

The genericEditor in that sample uses the FieldDataBox (which is a class that inherits from DataBox) which connects the DataBox to the SQLite database. This generic editor is meant to work with any schema: it will automatically let you edit all the fields in the table.

The FieldDataBox (as well as the other Field controls which inherit from it: FieldCheckButton, FieldDropDataBox and EditFieldDropDataBox) are used with the EditSection and ListSection components to automatically save and load from the database.
EditSection holds all the fields to edit, whereas ListSection lets you select the entry to modify as well as create/delete entries. By using EditSection and ListSection directly (i.e. as opposed to using them through the GenericEditor), you can have control on how to lay out your controls.

These classes are all defined in eda/gui.ec, so you can look at their implementation should you want to customize them even more. Also, the TableEditor (gui/TableEditor) is an alternate editing model still being worked on (we don't have a sample for this one yet), which works in conjunction with the FieldBox class. Smiliarly to the Edit/ListSection, it works with generic types.

Now I will try to explain the basics of connecting a plain (Saving)DataBox to a db. First, it is much simpler if you are implementing a DataBox for a specific type. You use the DataBox like you would use any data box... By settings its type and pointing it to a storage location for it. If you deal with a specific type, say an int, it's quite trivial. Here's sample code that retrieves and save an int from a DB row & field passed in:

Code: Select all
class MyEditor : Window
{
   int intStorage;
   SavingDataBox dBox { this, type = class(int), data = &intStorage };
 
   void Load(Row row, Field field)
   {
      row.GetData(field, intStorage);
      dBox.Refresh();
   }
   void Save(Row row, Field field)
   {
      row.SetData(field, intStorage);     
   }
}


Field(Data)Box have some fancy code to do all this generically, handling any data type, so it's a bit more complicated.

Hope this helps!

Regards,

Jerome

EDIT: Sorry, the class(int) was not necessary in there (eC automatically adds it from the type of 'intStorage')
jerome
Site Admin
 
Posts: 622
Joined: Sat Jan 16, 2010 11:16 pm


Return to GUI Toolkit & 2D Graphics

Who is online

Users browsing this forum: No registered users and 2 guests

cron