GError *error;
+ GdaStatement *stmt;
GdaDataModelIter *iter;
GdaMetaTableColumn *column;
+ GdaSet *params;
+ GdaHolder *holder;
+ gchar *param_name;
for (lst_tables = tables; lst_tables; lst_tables = lst_tables->next)
{
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
{
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";
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);
{
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,
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;
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 */
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)
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);