Created
July 31, 2014 22:16
-
-
Save gergelypolonkai/760fc710b56cb6b77ea5 to your computer and use it in GitHub Desktop.
GdauiDataStore strangeness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
sqlite3 test.db "CREATE TABLE IF NOT EXISTS test (id integer not null primary key, name varchar(20) not null)" | |
sqlite3 test.db "DELETE FROM test" | |
sqlite3 test.db "INSERT INTO test VALUES (1, 'a')" | |
gcc -o test -Wall -g -O2 `pkg-config --cflags --libs gtk+-3.0 libgda-ui-5.0 libgda-sqlite-5.0` test.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sql-parser/gda-sql-parser.h> | |
#include <libgda-ui/libgda-ui.h> | |
#include <gtk/gtk.h> | |
#include <libgda/libgda.h> | |
int | |
main(int argc, char **argv) | |
{ | |
GdaConnection *conn; | |
GdaSqlParser *parser; | |
GdaStatement *sth; | |
GdaDataModel *result; | |
GdauiDataStore *store; | |
gint test_int; | |
const gchar *test_string; | |
GtkTreeIter iter; | |
const GValue *value; | |
GError *err = NULL; | |
gtk_init(&argc, &argv); | |
gda_init(); | |
if ((conn = gda_connection_open_from_string( | |
NULL, | |
"SQLite://DB_DIR=/home/polesz/gdaui-test;DB_NAME=test", | |
NULL, | |
GDA_CONNECTION_OPTIONS_NONE, | |
&err)) == NULL) { | |
g_error("Open: %s", err->message); | |
} | |
parser = gda_connection_create_parser(conn); | |
sth = gda_sql_parser_parse_string( | |
parser, | |
"SELECT id, name FROM test WHERE id = 1", | |
NULL, | |
NULL | |
); | |
result = gda_connection_statement_execute_select(conn, sth, NULL, &err); | |
store = GDAUI_DATA_STORE(gdaui_data_store_new(result)); | |
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) { | |
gtk_tree_model_get( | |
GTK_TREE_MODEL(store), &iter, | |
0, &test_int, | |
1, &test_string, | |
-1); | |
g_warning("ID: %d; name: '%s'", test_int, test_string); | |
} else { | |
g_error("No such row!"); | |
} | |
value = gda_data_model_get_value_at(result, 0, 0, &err); | |
test_int = g_value_get_int(value); | |
value = gda_data_model_get_value_at(result, 1, 0, &err); | |
test_string = g_value_get_string(value); | |
g_warning("ID: %d; name: '%s'", test_int, test_string); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment