From a9c976ff3cedd8dff93857fc059d5bf9e443633f Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 24 Nov 2012 16:14:30 +0100 Subject: [PATCH] Copying data. --- .anjuta/session/anjuta.session | 28 ++++++++++ .anjuta/session/dock-layout.xml | 4 ++ .anjuta_sym_db.db | Bin 34816 -> 34816 bytes src/main.c | 91 ++++++++++++++++++++++++++++---- tests/db.db | Bin 3072 -> 3072 bytes 5 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 .anjuta/session/anjuta.session create mode 100644 .anjuta/session/dock-layout.xml diff --git a/.anjuta/session/anjuta.session b/.anjuta/session/anjuta.session new file mode 100644 index 0000000..f6b6037 --- /dev/null +++ b/.anjuta/session/anjuta.session @@ -0,0 +1,28 @@ +[Anjuta] +Maximized=1 +Geometry=1024x687+0+24 + +[File Loader] +Files=../../src/main.c#10 + +[Document Manager] +bookmarks=\n\n + +[Project Manager] +Shortcut=gdadbcopy//src//gdadbcopy +Expand=gdadbcopy + +[Execution] +Run in terminal=2 +Working directories=../../../gdadbcopy + +[Build] +Configuration list=1:Default:%%%1:Debug:Debug%%%1:Profiling:Profiling%%%1:Optimized:Optimized +Selected Configuration=Default +BuildArgs/Default=--enable-maintainer-mode +BuildArgs/Debug=--enable-maintainer-mode 'CFLAGS=-g -O0' 'CXXFLAGS=-g -O0' 'JFLAGS=-g -O0' 'FFLAGS=-g -O0' +BuildArgs/Profiling=--enable-maintainer-mode 'CFLAGS=-g -pg' 'CXXFLAGS=-g -pg' 'JFLAGS=-g -pg' 'FFLAGS=-g -pg' +BuildArgs/Optimized=--enable-maintainer-mode 'CFLAGS=-O2' 'CXXFLAGS=-O2' 'JFLAGS=-O2' 'FFLAGS=-O2' + +[Debugger] +Stop at beginning=2 diff --git a/.anjuta/session/dock-layout.xml b/.anjuta/session/dock-layout.xml new file mode 100644 index 0000000..aea89b1 --- /dev/null +++ b/.anjuta/session/dock-layout.xml @@ -0,0 +1,4 @@ + + + + diff --git a/.anjuta_s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copy_data () sql = g_strdup_printf ("SELECT * FROM %s", table->name); error = NULL; - dm = gda_execute_select_command (gda_conn_db, + dm = gda_execute_select_command (gda_conn_ref_db, sql, &error); + g_free (sql); if (dm != NULL) { + g_message ("\tTable: %s", table->name); + iter = gda_data_model_create_iter (dm); + if (iter == NULL) + { + g_warning ("Unable to create model iter."); + continue; + } + + error = NULL; + stmt = gda_sql_builder_get_statement (table->sqlbuilder, &error); + error = NULL; + gda_statement_get_parameters (stmt, ¶ms, &error); + while (gda_data_model_iter_move_next (iter)) { for (lst_fields = table->fields; lst_fields; lst_fields = lst_fields->next) { column = (GdaMetaTableColumn *)lst_fields->data; + param_name = g_strdup_printf ("p_%s", column->column_name); + holder = gda_set_get_holder (params, param_name); + if (holder == NULL) + { + g_warning ("Unable to get holder for parameter «%s».", + param_name); + g_free (param_name); + continue; + } gval = gda_data_model_iter_get_value_for_field (iter, column->column_name); + error = NULL; + if (!gda_holder_set_value (holder, gval, &error)) + { + g_warning ("Unable to set the holder for parameter «%s»: %s.", + param_name, + error != NULL && error->message != NULL ? error->message : "no details"); + } + g_free (param_name); + } + + error = NULL; + gda_connection_statement_execute_non_select (gda_conn_db, + stmt, + params, + NULL, + &error); + if (error != NULL) + { + g_warning ("Error executing insert into: %s", + (error != NULL && error->message != NULL ? error->message : "no details.")); + continue; } } + + g_object_unref (params); + g_object_unref (stmt); } else { @@ -130,9 +181,12 @@ read_fields (Table *table, GdaServerOperation *op) GdaMetaStruct *mstruct; GdaMetaDbObject *dbo; GSList *list; + + GdaMetaTableColumn *mt_column; GdaMetaTableColumn *column; guint i; + gchar *column_name; mcontext.column_names = g_new (gchar *, 1); mcontext.column_names[0] = "table_name"; @@ -153,7 +207,7 @@ read_fields (Table *table, GdaServerOperation *op) error = NULL; gval = gda_value_new (G_TYPE_STRING); - g_value_take_string (gval, table->name); + g_value_set_string (gval, table->name); store = gda_connection_get_meta_store (gda_conn_ref_db); mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_NONE); @@ -166,12 +220,22 @@ read_fields (Table *table, GdaServerOperation *op) { GdaMetaTable *meta_table = GDA_META_TABLE (dbo); - table->fields = meta_table->columns; + table->fields = NULL; i = 0; for (list = meta_table->columns; list; list = list->next, i++) { - column = (GdaMetaTableColumn *)list->data; + mt_column = (GdaMetaTableColumn *)list->data; + + column = g_new0 (GdaMetaTableColumn, 1); + column->column_name = g_strdup (mt_column->column_name); + column->column_type = g_strdup (mt_column->column_type); + column->gtype = mt_column->gtype; + column->pkey = mt_column->pkey; + column->nullok = mt_column->nullok; + column->default_value = g_strdup (mt_column->default_value); + table->fields = g_slist_append (table->fields, column); + g_message ("\t\tField: %s - %s - %d - %d - %d - %s", column->column_name, column->column_type, @@ -181,12 +245,14 @@ read_fields (Table *table, GdaServerOperation *op) column->default_value); /* sql builder */ + column_name = g_strdup_printf ("p_%s", column->column_name); gda_sql_builder_add_field_value_id (table->sqlbuilder, gda_sql_builder_add_id (table->sqlbuilder, column->column_name), gda_sql_builder_add_param (table->sqlbuilder, - g_strdup_printf ("p_%s", column->column_name), + column_name, column->gtype, FALSE)); + g_free (column_name); /* server operation */ error = NULL; @@ -241,8 +307,10 @@ read_tables () for (row = 0; row < rows; row++) { table = g_new0 (Table, 1); - tables = g_slist_append (tables, table); - table->name = gda_value_stringify (gda_data_model_get_value_at (dm_tables, 0, row, NULL)); + table->name = g_strdup (gda_value_stringify (gda_data_model_get_value_at (dm_tables, 0, row, NULL))); + table->sqlbuilder = NULL; + table->fields = NULL; + g_message ("\tTable: %s", table->name); /* sql builder for insert into */ @@ -284,8 +352,11 @@ read_tables () error = NULL; g_message ("\t\tSql: %s", gda_statement_to_sql (stmt, NULL, &error)); + g_object_unref (stmt); g_object_unref (op); + + tables = g_slist_append (tables, table); } } if (dm_tables != NULL) @@ -349,11 +420,11 @@ main (int argc, char *argv[]) update_metastore (); g_message ("Reading tables of reference database (%s).", ref_db_cnc); - tables = g_slist_alloc (); + tables = NULL; read_tables (); - /*g_message ("Copying data."); - copy_data ();*/ + g_message ("Copying data."); + copy_data (); g_object_unref (gda_conn_ref_db); g_object_unref (gda_conn_db); diff --git a/tests/db.db b/tests/db.db index c4808c7d4e014244f84aa0215f0459ca1eca476c..2c0d58c323e98ad11a79021502c21e74677b5961 100644 GIT binary patch delta 75 zcmZpWXpop7Ex3h&fq@x_nV@*nL>*(Gpzb3zUZ4mA3sAP2>BHtm=4K|w?umt6lk1o} SSs8&c%s{a=mdz8G^OylJQ4qHP delta 74 zcmZpWXpop7EvUl4z`zW}Oh8&?qK+|8Q1_84FObK;!oa}vf$77>!X_prMuCZiU6bpW UI~Oaku&^=$Wtlb$vV36%0K_&8{{R30 -- 2.49.0