On 9/19/06, Daniel Espinosa <[EMAIL PROTECTED]> 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.
This being said, here is how to get a dictionary (schematized, without
any error check):
cnc = gda_client_open_connection ();
dict = gda_dict_new ();
gda_dict_set_connection (dict, cnc);
db = gda_dict_get_database (dict); /* if you call this several times,
you'll always get the same db object */
if (filename)
/* if you want to load the dictionary from a file */
gda_dict_load_xml_file (dict, filename);
else {
/* if you don't have any XML file to load from */
gda_dict_update_dbms_data (dict);
}
table = gda_dict_database_get_table_by_name (db, "tablename");
About queries:
You don't need a dictionary to build a query, but the query can only
be "active" if it can identify (find) all the objects used in it
(tables, views, fields, functions, etc) in the dictionary which has
been passed when the query was created.
Having a "non active" query does not prevent you from using it, but if
it's a SELECT query, then the column types won't be known untill you
actually execute the query.
Of course the benefits of having an up to date dictionary and "active"
queries is that you can be sure they won't fail.
Cheers,
Vivien
_______________________________________________
gnome-db-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-db-list