GNOME Data Access manual |
---|
Each time we execute a normal query, we will obtain a GdaDataModel object, which is the way to see what the query returned. As GdaDataModel is an object, we can manage it with GdaDataModel class.
Before continuing, we must say that it is possible to modify a data model, but as we are accessing using SQL, it is not recommended to modify it, so modifications on the database must be done using SQL.
Let's see the functions we need:
This functions are very easy to use, so let's see some clear examples:
This function accesses the data model by directly accessing cells (using gda_data_model_get_value_at () )
void show_table (GdaDataModel * dm) { gint row_id; gint column_id; GdaValue *value; for (column_id = 0; column_id < gda_data_model_get_n_columns (dm); column_id++) g_print("%s\t",gda_data_model_get_column_title (dm, column_id)); g_print("\n"); for (row_id = 0; row_id < gda_data_model_get_n_rows (dm); row_id++) { for (column_id = 0; column_id < gda_data_model_get_n_columns (dm); column_id++) { value = (GdaValue *) gda_data_model_get_value_at (dm, column_id, row_id); g_print ("%s\t", gda_value_stringify (value)); } g_print("\n"); } }
This function accesses the data model by accessing rows (using gda_data_model_get_row () and gda_row_get_value () )
void show_table2 (GdaDataModel * dm) { gint row_id; gint column_id; GdaValue *value; GdaRow *row; for (column_id = 0; column_id < gda_data_model_get_n_columns (dm); column_id++) g_print("%s\t",gda_data_model_get_column_title (dm, column_id)); g_print("\n"); for (row_id = 0; row_id < gda_data_model_get_n_rows (dm); row_id++) { row = (GdaRow *) gda_data_model_get_row (dm, row_id); for (column_id = 0; column_id < gda_data_model_get_n_columns (dm); column_id++) { /* We don't need to free this value! */ value = gda_row_get_value (row, column_id); string=gda_value_stringify (value); g_print ("%s\t", string); g_free(string); } g_print ("\n"); } }
<<< Processing queries | Managing values >>> |