[gnome-db] libgda samples not ajour
- From: Stian Skjelstad <stian nixia no>
- To: gnome-db list <gnome-db-list gnome org>
- Subject: [gnome-db] libgda samples not ajour
- Date: Sun, 19 Nov 2006 20:30:58 +0100
I tried to update one of the samples. I haven't tried it yet, since I
don't have postgresql installed. Is this patch correct?
Stian Skjelstad
diff -ur libgda-mysql/samples/sample-firebird.c libgda/samples/sample-firebird.c
--- libgda-mysql/samples/sample-firebird.c 2006-09-10 16:19:21.000000000 +0200
+++ libgda/samples/sample-firebird.c 2006-11-19 20:25:26.000000000 +0100
@@ -44,38 +44,70 @@
GdaDataModel *dm_schema = NULL;
GdaParameterList *prm_list;
GdaParameter *prm;
- GdaRow *row;
- GValue *value;
+ const GValue *value;
gint n_row;
+ gint n_col;
+ GError *error = NULL;
prm_list = gda_parameter_list_new (NULL);
prm = gda_parameter_new_boolean ("systables", show_systables);
gda_parameter_list_add_param (prm_list, prm);
- dm_schema = gda_connection_get_schema (cnc, cnc_schema, prm_list, NULL);
+ dm_schema = gda_connection_get_schema (cnc, cnc_schema, prm_list, &error);
if (dm_schema) {
+ for (n_col = 0; n_col < gda_data_model_get_n_columns (dm_schema); n_col++) {
+ g_print ("%s\n", gda_data_model_get_column_title (dm_schema, n_col));
+ }
+ g_print ("\n");
+
for (n_row = 0; n_row < gda_data_model_get_n_rows (dm_schema); n_row++) {
- row = (GdaRow *) gda_data_model_get_row (dm_schema, n_row);
- value = gda_row_get_value (row, 0);
- g_print (" %s\n", g_value_get_string (value));
+ for (n_col = 0; n_col < gda_data_model_get_n_columns (dm_schema); n_col++) {
+ value = gda_data_model_get_value_at (dm_schema, n_col, n_row);
+ if (value && !gda_value_is_null (value))
+ g_print ("%s\n", g_value_get_string (value));
+ else
+ g_print ("NULL\n");
+ }
+ g_print ("\n");
}
-
g_print ("\n");
-
+ g_object_unref (dm_schema);
} else {
g_print ("* Error getting schema *\n");
+ if (error)
+ {
+ g_print ("%s\n", error->message);
+ g_error_free (error);
+ error = 0;
+ show_errors (cnc);
+ }
}
- g_object_unref (dm_schema);
g_object_unref (prm_list);
}
gboolean
-create_database (GdaConnection *cnc)
+create_database (GdaClient *client)
{
- return (gda_connection_create_database (cnc, "127.0.0.1:/tmp/test_firebird.fdb"));
+ GError *error = 0;
+ GdaServerOperation* operation = gda_client_prepare_create_database(client, "127.0.0.1:/tmp/test_firebird.fdb");
+ if ( ! operation )
+ {
+ g_print ("gda_client_prepare_create_database failed\n");
+ return FALSE;
+ }
+ if ( ! gda_client_perform_create_database (client, operation, &error))
+ {
+ g_print ("gda_client_permform_create_database failed: %s\n", error->message);
+ g_error_free (error);
+ error = 0;
+ g_object_unref (operation);
+ return FALSE;
+ }
+ g_object_unref (operation);
+ return FALSE;
}
void
@@ -84,9 +116,9 @@
gchar *dsn;
dsn = g_strdup_printf ("DATABASE=127.0.0.1:%s", FIREBIRD_RO_DATABASE);
- gda_config_save_data_source ("test_firebird_dummy", "Firebird", dsn, "Dummy read only database", NULL, NULL);
+ gda_config_save_data_source ("test_firebird_dummy", "Firebird", dsn, "Dummy read only database", NULL, NULL, FALSE);
gda_config_save_data_source ("test_firebird", "Firebird", "DATABASE=127.0.0.1:/tmp/test_firebird.fdb",
- "Test database", NULL, NULL);
+ "Test database", NULL, NULL, FALSE);
g_free (dsn);
}
@@ -101,12 +133,11 @@
create_some_stuff (GdaConnection *cnc)
{
GdaCommand *command;
- GdaTransaction *transaction;
gboolean res = FALSE;
+ GError *error = 0;
g_print ("Creating some tables and a view ... ");
- transaction = gda_transaction_new ("some_stuff");
- if (gda_connection_begin_transaction (cnc, transaction)) {
+ if (gda_connection_begin_transaction (cnc, "mytrans", GDA_TRANSACTION_ISOLATION_SERIALIZABLE, &error)) {
command = gda_command_new ("CREATE TABLE BIG(AN_INTEGER INTEGER NOT NULL,"
"A_VARCHAR VARCHAR(30), A_SMALLINT SMALLINT NOT NULL,"
"A_DATE DATE, A_TIME TIME, A_TS TIMESTAMP,"
@@ -115,21 +146,18 @@
"A_DOUBLE DOUBLE PRECISION, A_NULL CHAR(1))",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
gda_connection_execute_non_select_command (cnc, command, NULL, NULL);
gda_command_free (command);
command = gda_command_new ("CREATE TABLE CHICA(EN_ESPANIOL INTEGER NOT NULL)",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
gda_connection_execute_non_select_command (cnc, command, NULL, NULL);
gda_command_free (command);
command = gda_command_new ("CREATE TABLE KLEINE(AUS_DEUTSCHE INTEGER NOT NULL)",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
gda_connection_execute_non_select_command (cnc, command, NULL, NULL);
gda_command_free (command);
@@ -137,20 +165,24 @@
"SELECT * FROM BIG",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
- gda_connection_execute_nonselect_command (cnc, command, NULL, NULL);
+ gda_connection_execute_non_select_command (cnc, command, NULL, NULL);
gda_command_free (command);
- gda_connection_commit_transaction (cnc, transaction);
-
- res = TRUE;
- g_print ("OK\n");
-
+ if ( ! gda_connection_commit_transaction (cnc, "mytrans", &error))
+ {
+ g_print ("gda_connection_commit_transaction failed: %s\n", error->message);
+ g_error_free (error);
+ error = 0;
+ } else {
+ res = TRUE;
+ g_print ("OK\n");
+ }
} else {
- g_print ("ERROR\n");
+ g_print ("gda_connection_begin_transaction failed: %s\n", error->message);
+ g_error_free (error);
+ error = 0;
}
show_errors (cnc);
- g_object_unref (transaction);
return res;
}
@@ -159,17 +191,15 @@
populate_table_big (GdaConnection *cnc)
{
GdaCommand *command;
- GdaTransaction *transaction;
+ GError *error = 0;
g_print ("Populating table BIG ... ");
- transaction = gda_transaction_new ("populate");
- if (gda_connection_begin_transaction (cnc, transaction)) {
+ if (gda_connection_begin_transaction (cnc, "mytrans2", GDA_TRANSACTION_ISOLATION_SERIALIZABLE, &error)) {
command = gda_command_new ("INSERT INTO BIG VALUES(11,'Some varying string',0,'8-Nov-1977',"
"'17:20','NOW','Some fixed char','134.5','67923.45','1234.5',"
"'78123.45',NULL)",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
gda_connection_execute_non_select_command (cnc, command, NULL, NULL);
gda_command_free (command);
@@ -178,7 +208,6 @@
"'67891.45',NULL)",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
gda_connection_execute_non_select_command (cnc, command, NULL, NULL);
gda_command_free (command);
@@ -188,26 +217,29 @@
"'6923.45',NULL)",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
gda_connection_execute_non_select_command (cnc, command, NULL, NULL);
gda_command_free (command);
- gda_connection_commit_transaction (cnc, transaction);
- g_print ("OK\n");
-
+ if ( ! gda_connection_commit_transaction (cnc, "mytrans2", &error) )
+ {
+ g_print ("gda_connection_commit_transaction failed: %s\n", error->message);
+ g_error_free (error);
+ error = 0;
+ show_errors (cnc);
+ } else
+ g_print ("OK\n");
} else {
- g_print ("ERROR\n");
+ g_print ("gda_connection_begin_transaction failed: %s\n", error->message);
+ g_error_free (error);
+ error = 0;
show_errors (cnc);
}
-
- g_object_unref (transaction);
}
void
select_table_big (GdaConnection *cnc)
{
GdaCommand *command;
- GdaTransaction *transaction;
GdaDataModel *dm;
GList *list, *node;
GValue *valor;
@@ -216,16 +248,15 @@
const GDate *d;
const GdaTimestamp *ts;
const GdaNumeric *numeric;
+ GError *error = 0;
g_print("Selecting data from table BIG ... ");
- transaction = gda_transaction_new ("show_big");
- if (gda_connection_begin_transaction (cnc, transaction)) {
+ if (gda_connection_begin_transaction (cnc, "mytrans3", GDA_TRANSACTION_ISOLATION_SERIALIZABLE, &error)) {
command = gda_command_new (
"SELECT * FROM LIST_BIG",
GDA_COMMAND_TYPE_SQL,
GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction (command, transaction);
list = gda_connection_execute_command (cnc, command, NULL, NULL);
if (list != NULL) {
g_print ("OK\n");
@@ -292,7 +323,12 @@
}
- gda_connection_rollback_transaction (cnc, transaction);
+ if ( ! gda_connection_rollback_transaction (cnc, "mytrans3", &error) )
+ {
+ g_print ("gda_connection_rollback_transaction failed: %s\n", error->message);
+ g_error_free (error);
+ error = 0;
+ }
gda_command_free (command);
}
@@ -301,10 +337,10 @@
}
} else {
- g_print ("ERROR\n");
+ g_print ("gda_connection_begin_transaction failed: %s\n", error->message);
+ g_error_free (error);
+ error = 0;
}
-
- g_object_unref (transaction);
}
void
@@ -312,6 +348,7 @@
{
GdaClient *client;
GdaConnection *connection;
+ GError *error = 0;
g_print ("* Creating datasources (test_firebird and dummy_test_firebird) *\n");
save_datasource ();
@@ -323,11 +360,12 @@
"test_firebird_dummy",
FIREBIRD_USER,
FIREBIRD_PWD,
- GDA_CONNECTION_OPTIONS_READ_ONLY);
-
+ GDA_CONNECTION_OPTIONS_READ_ONLY,
+ &error);
+
if (connection) {
g_print ("OK\nCreating database \"/tmp/test_firebird.fdb\" ...");
- if (!create_database (connection)) {
+ if (!create_database (client)) {
g_print ("ERROR\nCan't create test database :-( .Removing datasources, reporting error and exiting.\n");
show_errors (connection);
remove_datasource (connection);
@@ -340,10 +378,13 @@
connection = NULL;
g_print ("Connecting to test database ... ");
- connection = gda_client_open_connection (client, "test_firebird", FIREBIRD_USER, FIREBIRD_PWD, 0);
+ connection = gda_client_open_connection (client, "test_firebird", FIREBIRD_USER, FIREBIRD_PWD, 0, &error);
if (!connection) {
g_print ("ERROR\n");
+ g_print ("%s\n", error->message);
+ g_error_free (error);
+ error = 0;
remove_datasource (connection);
return;
@@ -379,6 +420,9 @@
remove_datasource (connection);
} else {
g_print ("ERROR\nCan't connect to dummy read-only database :-( .\n");
+ g_print ("%s\n", error->message);
+ g_error_free (error);
+ error = 0;
}
gda_connection_close (connection);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]