{ NULL }
};
+typedef struct
+{
+ gchar *name;
+
+ GdaSqlBuilder *sqlbuilder;
+
+ GSList *fields;
+} Table;
+
+GSList *tables;
+
static void
update_metastore ()
{
}
static void
-read_fields (const gchar *table_name, GdaServerOperation *op)
+copy_data ()
+{
+ Table *table;
+
+ GSList *lst_tables;
+ GSList *lst_fields;
+
+ gchar *sql;
+ GdaDataModel *dm;
+ const GValue *gval;
+
+ GError *error;
+
+ GdaDataModelIter *iter;
+ GdaMetaTableColumn *column;
+
+ for (lst_tables = tables; lst_tables; lst_tables = lst_tables->next)
+ {
+ table = (Table *)lst_tables->data;
+ sql = g_strdup_printf ("SELECT * FROM %s",
+ table->name);
+ error = NULL;
+ dm = gda_execute_select_command (gda_conn_db,
+ sql,
+ &error);
+ if (dm != NULL)
+ {
+ iter = gda_data_model_create_iter (dm);
+ 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;
+ gval = gda_data_model_iter_get_value_for_field (iter,
+ column->column_name);
+ }
+ }
+ }
+ else
+ {
+ g_warning ("Error executing select command: %s",
+ (error != NULL && error->message != NULL ? error->message : "no details."));
+ continue;
+ }
+ }
+}
+
+static void
+read_fields (Table *table, GdaServerOperation *op)
{
GError *error;
mcontext.column_values[0] = gda_value_new (G_TYPE_STRING);
g_value_take_string (mcontext.column_values[0],
- gda_sql_identifier_quote (table_name, gda_conn_ref_db, NULL, FALSE, FALSE));
+ gda_sql_identifier_quote (table->name, gda_conn_ref_db, NULL, FALSE, FALSE));
error = NULL;
if (!gda_connection_update_meta_store (gda_conn_ref_db, &mcontext, &error))
error = NULL;
gval = gda_value_new (G_TYPE_STRING);
- g_value_take_string (gval, (gchar *)table_name);
+ g_value_take_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);
gda_value_free (gval);
if (dbo != NULL)
{
- GdaMetaTable *table = GDA_META_TABLE (dbo);
+ GdaMetaTable *meta_table = GDA_META_TABLE (dbo);
+
+ table->fields = meta_table->columns;
i = 0;
- for (list = table->columns; list; list = list->next, i++)
+ for (list = meta_table->columns; list; list = list->next, i++)
{
column = (GdaMetaTableColumn *)list->data;
g_message ("\t\tField: %s - %s - %d - %d - %d - %s",
column->nullok,
column->default_value);
+ /* sql builder */
+ 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->gtype,
+ FALSE));
+
+ /* server operation */
error = NULL;
if (!gda_server_operation_set_value_at (op,
column->column_name,
guint rows;
guint row;
- gchar *table_name;
+ Table *table;
GdaServerOperation *op;
+ GdaStatement *stmt;
error = NULL;
dm_tables = gda_connection_get_meta_store_data (gda_conn_ref_db,
rows = gda_data_model_get_n_rows (dm_tables);
for (row = 0; row < rows; row++)
{
- table_name = gda_value_stringify (gda_data_model_get_value_at (dm_tables, 0, row, NULL));
- g_message ("\tTable: %s", table_name);
+ 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));
+ g_message ("\tTable: %s", table->name);
+
+ /* sql builder for insert into */
+ table->sqlbuilder = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
+ gda_sql_builder_set_table (table->sqlbuilder, table->name);
/* starting server operation */
error = NULL;
}
error = NULL;
- if (!gda_server_operation_set_value_at (op, table_name, &error,
+ if (!gda_server_operation_set_value_at (op, table->name, &error,
"/TABLE_DEF_P/TABLE_NAME"))
{
g_warning ("Error on setting GdaServerOperation's value: %s.",
continue;
}
- read_fields (table_name, op);
+ read_fields (table, op);
error = NULL;
if (!gda_connection_perform_operation (gda_conn_db, op, &error))
continue;
}
+ error = NULL;
+ stmt = gda_sql_builder_get_statement (table->sqlbuilder, &error);
+ error = NULL;
+ g_message ("\t\tSql: %s",
+ gda_statement_to_sql (stmt, NULL, &error));
+
g_object_unref (op);
}
}
update_metastore ();
g_message ("Reading tables of reference database (%s).", ref_db_cnc);
- read_tables (gda_conn_ref_db);
+ tables = g_slist_alloc ();
+ read_tables ();
+
+ /*g_message ("Copying data.");
+ copy_data ();*/
g_object_unref (gda_conn_ref_db);
g_object_unref (gda_conn_db);