Re: [gnome-db] Re: understanding data sources



On Tue, 2004-10-26 at 08:26, Neil Zanella wrote:
> I wonder if someone could please answer my question:
> 
> Can I use libgda and connect and execute queries without
> having to create a file called ~/.libgda? It just doesn't make
> sense to me that that file would have to be there. I would
> rather let my users specify connection parameters on
> the command line or on the GUI itself.

I'm just starting to play with libgda, and libgnome-db so I can be
wrong.

I don't know if you can access libgda without a data source file, but
the API is really rich in this field, and you can create a data source
on the fly and delete it when you close the connection.

The programming should look like:

if( !g_file_test("~/.libgda", G_FILE_EXISTS|G_FILE_IS_DIRECTORY ) ){
	mkdir("~/.libgda");
	// check if everything is ok (I mean ~/.libgda exists)
}

// ... get data from your UI or cmd line ...

gda_config_save_data_source 
	("foo",
	 "PostgreSQL",
	 "DATABASE=foo_db",
	 "description of foo",
	 "foo_username",
	 "foo_password");

// ... connect ...
// ... make something useful
// ... disconnect ...

gda_config_remove_data_source ("foo");

From my point of view, the data source being stored on disk or on memory
is irrelevant.

You can even ask your user, "Do you want to save this data source ?" and
act according.

GtkWidget* confirm;
gint response;

confirm =
	gtk_message_dialog_new 
		(NULL,
		GTK_DIALOG_MODAL,
		GTK_MESSAGE_QUESTION,
                GTK_BUTTONS_YES_NO,
                "Do you want to save this data source ?");

response = gtk_dialog_run( GTK_DIALOG(confirm));

if( respose == GTK_RESPOSE_NO ){
	gda_config_remove_data_source ("foo");
}
gtk_widget_destroy(confirm);

More on this at:
http://www.gnome-db.org/docs/libgda/libgda-gda-config.html
http://www.gnome-db.org/docs/libgda/installation-configuring.html

The only glitch I expect with this approach, are multi threaded
applications, where you should play with mutex, or file locking to avoid
two threads writting the configuration file at the same time.

I *suposse* it can mess the configuration file.

> Thank you for answering my questions,

I hope this helps, but better wait for an authoritative answer.

Remember I'm just starting to play with libgda :)

Cheers.
-- 
Iago Rubio         

Attachment: signature.asc
Description: This is a digitally signed message part



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