Hello, im trying to create an application that uses a mysql database to get its information, first a treeview is created from the information stored in one column, than when I select a row some more information should be displayed as GTK Labels and a picture is shown for each row. I have the whole thing working, with a simple treeview generated from data stored in a textfile.
How should I handle the database connection, i thought i can get the whole data once and put it into different varibles, but i havent found a way to extract the data from the rows. right now im trying to give the select Title to my label display function and do a query with "Select Info FROM table WHERE Title = "title"", but i always get Segmentation faults as soon as i try to use a WHERE or something else in may query. In the top of my main() i have the connection and i just give the *my to the functions where the queries are defined. Please give me some tips how I can solve this problem the best way, I think having a global structe which i can access via if() or something would be better than doing a SELECT everytime i need some information. //__________Datenbank___________________________________________________________________ MYSQL *my; my = mysql_init(NULL); if(my == NULL) { fprintf(stderr, " Initialisierung fehlgeschlagen\n"); return EXIT_SUCCESS; } /* Mit dem Server verbinden */ if( mysql_real_connect (my, NULL, "root", NULL, "shdf", 0, NULL, 0) == NULL) { fprintf (stderr, "Fehler mysql_real_connect():" "%u (%s)\n",mysql_errno (my), mysql_error (my)); } else printf("Erfolgreich mit dem MySQL-Server verbunden\n"); /* Hier befindet sich der Code für die Arbeit mit MySQL */ mysql_select_db(my, "shdf"); //_____________________________________________________________________________ //the function that fills the treeview list void make_list(GtkListStore *liste, GtkTreeIter iter, MYSQL *my){ MYSQL_ROW row; MYSQL_RES *result; MYSQL_FIELD *field; gint i=0; char *query; query = "SELECT Title FROM table WHERE nr < 107" ; mysql_real_query(my, query, strlen(query)); result = mysql_store_result(my); while ((row = mysql_fetch_row (result)) != NULL) { mysql_field_seek (result, 0); for (i = 0; i < mysql_num_fields(result); i++) { gtk_list_store_append(liste, &iter); gtk_list_store_set(liste, &iter, STRING_SPALTE, row[i],-1); } } free(query); greetings _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list