Re: list view & mysql tables



On Tue, 2005-03-08 at 14:49 +1100, Grant wrote:
Greetings,
Does anybody know of some example code/tutorial or even a application 
which pulls rows of data out of a mysql database and puts it into a list 
view? (I am using gtk 2.4 and mysql 4.1).

I recommend you gnome-db if you can use Gnome libs, or libgda instead.

http://gnome-db.org 

It have some data access widgets that can ease your live. You can even
use glade for the UI and get most bits in place.

Here you've got - libgomedb/libgda - a code snippet that could fit your
needs:

GdaConnection* con;
GdaClient* client;
GdaCommand *command;
GList *list;
GList *node;
gboolean errors=FALSE;          
GdaDataModel *dm;

// create a gda client
client = gda_client_new ();
con = gda_client_open_connection   (client,"mydatabase", NULL, NULL,
GDA_CONNECTION_OPTIONS_DONT_SHARE);

// create en push an SQL command
command = gda_command_new ("select * from table", GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
list = gda_connection_execute_command (con, command, NULL);

// fill the data model
if (list!=NULL) {
    for (node=g_list_first(list); node != NULL; node=g_list_next(node))
      {
        dm=(GdaDataModel *) node->data;
        if (dm == NULL)
          {
            errors=TRUE;
          }
      }
  }

gda_command_free (command);

// This is gnomedb not libgda - create a db grid and bind the model
dbtableeditor = gnome_db_grid_new ();
gtk_widget_show (dbtableeditor);
gtk_container_add (GTK_CONTAINER (my_top_level_window), dbtableeditor);

if(!errors){
    gnome_db_grid_set_model( (GnomeDbGrid*) dbtableeditor, dm);
}

-- 
Iago Rubio



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