Re: [gnome-db] Getting a Table by name



On 9/20/06, Daniel Espinosa <esodan gmail com> wrote:


2006/9/20, Vivien Malerba <vmalerba gmail com>:
> On 9/19/06, Daniel Espinosa <esodan gmail com> wrote:
> > If I have a GdaConnection and the table name I want to insert data into,
how
> > can I do it?
> >
> > I'm trying to use GdaDictDatabase but it seems not be completly
implement
> > (it doesn't declare any code to assing a Dict as a property using
> > g_object_set_property); then I can't get the GdaDictTable using its
name.
> >
> > But most of it, is that I can't create a dictionary and update the XML
file,
> > could you help me?
> >
> > I think if the dict isn't correctly created, you can't have a valid
> > GdaQuery?
> >
> > Can I pass directly to gda_query_target_new(query, table_name) a string
> > given for the user caller?
> >
> > I have the following code:
> >
> >     dict = gda_dict_new();
> >     gda_dict_set_connection(dict, cnn);
> >
> >     gda_dict_set_xml_filename(dict,
> >
> > gda_dict_compute_xml_filename(dict,
> >
> > gda_connection_get_dsn(cnn),
> >
> > "GDAAPP", error));
> >     g_message("File dict = %s\n",
> > gda_dict_get_xml_filename(dict));
> >     gda_dict_load(dict, error);
> >
> >     if(gda_dict_update_dbms_data (dict, 0, NULL,
> >                                 error))
> >         g_message("Error Dict Not updated...\n");
> >
> >     /* Getting the Table from the Dictionary */
> >     db = gda_dict_database_new(dict);
> >     table = gda_dict_database_get_table_by_name(db,
> > table_name);
> >
>
> About dictionaries:
> If all you want to do is add data to a table, then you don't need a
> dictionary: a dictionary is usefull only if you need to get
> information about what a database structure is.

I just want to add a row and set the values in that new row. Do I need a
Dict and/or a GdaQuery?

If you mean you want to add a row to a table in your database, then
the easiest is something like:

GdaCommand *command;
command = gda_command_new ("INSERT INTO .....");
gda_connection_execute_non_select_command (cnc, command);

If you have a GdaDataModel returned from a SELECT command, then the
general case is you can't add a row to it without any further work -
the reason is that there is no abvious way of inserting data from a
SELECT statement (for example what would you insert from a query like
"SELECT count(*) FROM mytable"?). In this case you should create a
GdaDataModelQuery specifying the SELECT query you want, then tell that
object what queries to use for INSERT (UPDATE/DELETE) and then you can
use gda_data_model_append_row() on that object.


Any schematized code for do it?

GdaQuery *qurery;
GdaDataModel *model;

query = gda_query_new_from_sql (dict (or NULL if you have no dict),
"SELECT ...");
model = gda_data_model_query_new (query);
g_object_unref (query);
gda_data_model_query_set_modification_query (model, "INSERT INTO
mytable (field) VALUES (##[:name="+0" :type="gint"])";

Now you can insert data in 'model' because it knows which query to
actually execute to insert data. Please see the documentation of
gda_data_model_query_set_modification_query() for the "+0"
signification.


[...]

I can see that I need do some tests to understand "the GdaQuery way" and why
I can't use the gda_data_model_append_values function; do you plan to
deprecate that function and others that *must* use  a GdaQuery Object to
perform operations?

You must understand the GdaDataModel is an interface which is
implemented by various objects which may or may not let you modify
their contents; for example the GdaDataModelImport loads data from a
file (CVS for example), and you can't modify what's in it. The
GdaDataModel documentation will show you all the objects which
actually implement this interface.

The GdaDataModel returned by the providers when you use
gda_connection_execute_select_command() is most of the time read only
and its implementation is provider-dependant.

Vivien



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]