Table of Contents
As you perhaps already noticed, the example from the previous chapter has some limitations: It allows the user to change values in the grid but instead of being committed back to the database, the old values reappear.
libgnomedbmm provides a pretty elegant way to add this functionality without much extra-code, but before we get there, two new libgda concepts will be introduced.
A Gnome::Gda::Dict
is a dictionary that manages most objects used by libgda, such as
pre-defined SQL queries or objects existing in a database (such as data types,
functions and aggregates). It can be saved to and loaded from XML files. Also,
each Gnome::Gda::Dict
has an assigned connection so that it can operate on the
database.
If you do not have a dictionary available, you might acquire an initial one from the database management system (DBMS):
Glib::RefPtr<Gnome::Gda::Dict> dict = Gnome::Gda::Dict::create(); dict->set_connection(...); dict->update_dbms_meta_data();
Do make sure that a connection is available to the Gnome::Gda::Dict
before
calling update_dbms_meta_data()
because it uses the
connection to query the database management system about available data types,
functions, etc.
However, note that the dictionary can contain additional objects that the
DBMS does not know about, such as graph items or pre-defined queries, specified by
your application. You may therefore wish to save the Dict
to an XML file using
Gnome::Gda::Dict::save_xml_file()
and read it back next time
with Gnome::Gda::Dict::load_xml_file()
. This way, those
additional objects will not be lost. Also, you will not need to query the database
next time you need the dictionary.