static GdaConnection *gda_conn_ref_db;
static GdaConnection *gda_conn_db;
-typedef struct
-{
- gchar *name;
- GHashTable *ht_fields;
-} Table;
-
-typedef struct
-{
- gchar *name;
-} Field;
-
static GOptionEntry entries[] =
{
{ "ref-db-cnc", 0, 0, G_OPTION_ARG_STRING, &ref_db_cnc, "Reference database connection string", "CNC_STRING" },
}
static void
-read_fields (GdaConnection *gdacon, Table *table)
+read_fields (const gchar *table_name)
{
GError *error;
guint rows;
guint row;
- Field *field;
-
error = NULL;
mcontext.column_names = g_new (gchar *, 1);
mcontext.column_values[0] = gda_value_new (G_TYPE_STRING);
g_value_take_string (mcontext.column_values[0],
- gda_sql_identifier_quote (table->name, gdacon, NULL, FALSE, FALSE));
+ gda_sql_identifier_quote (table_name, gda_conn_ref_db, NULL, FALSE, FALSE));
- if (!gda_connection_update_meta_store (gdacon, &mcontext, &error))
+ if (!gda_connection_update_meta_store (gda_conn_ref_db, &mcontext, &error))
{
g_warning ("Unable to update database metastore: %s",
(error != NULL && error->message != NULL ? error->message : "no details."));
error = NULL;
gval = gda_value_new (G_TYPE_STRING);
- g_value_take_string (gval, table->name);
- dm_fields = gda_connection_get_meta_store_data (gdacon,
+ g_value_take_string (gval, (gchar *)table_name);
+ dm_fields = gda_connection_get_meta_store_data (gda_conn_ref_db,
GDA_CONNECTION_META_FIELDS,
&error,
1,
rows = gda_data_model_get_n_rows (dm_fields);
for (row = 0; row < rows; row++)
{
- field = g_new0 (Field, 1);
- field->name = gda_value_stringify (gda_data_model_get_value_at (dm_fields, 0, row, NULL));
- g_message ("\t\tField: %s - %s - %s - %d - %d", field->name,
+ g_message ("\t\tField: %s - %s - %s - %d - %d", gda_value_stringify (gda_data_model_get_value_at (dm_fields, 0, row, NULL)),
gda_value_stringify (gda_data_model_get_value_at (dm_fields, 1, row, NULL)),
gda_value_stringify (gda_data_model_get_value_at (dm_fields, 2, row, NULL)),
g_value_get_int (gda_data_model_get_value_at (dm_fields, 3, row, NULL)),
g_value_get_int (gda_data_model_get_value_at (dm_fields, 4, row, NULL)));
-
- g_hash_table_insert (table->ht_fields, field->name, field);
}
}
if (dm_fields != NULL)
}
static void
-read_tables (GdaConnection *gdacon, GHashTable *ht)
+read_tables ()
{
GError *error;
guint rows;
guint row;
- Table *table;
+ gchar *table_name;
+
+ GdaServerOperation *op;
error = NULL;
- dm_tables = gda_connection_get_meta_store_data (gdacon,
+ dm_tables = gda_connection_get_meta_store_data (gda_conn_ref_db,
GDA_CONNECTION_META_TABLES,
&error,
0);
rows = gda_data_model_get_n_rows (dm_tables);
for (row = 0; row < rows; row++)
{
- table = g_new0 (Table, 1);
- table->ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
-
- table->name = gda_value_stringify (gda_data_model_get_value_at (dm_tables, 0, row, NULL));
- g_message ("\tTable: %s", table->name);
-
- g_hash_table_insert (ht, table->name, table);
-
- read_fields (gdacon, table);
+ table_name = gda_value_stringify (gda_data_model_get_value_at (dm_tables, 0, row, NULL));
+ g_message ("\tTable: %s", table_name);
+
+ /* starting server operation */
+ error = NULL;
+ op = gda_connection_create_operation (gda_conn_db, GDA_SERVER_OPERATION_CREATE_TABLE, NULL, &error);
+ if (op == NULL
+ || error != NULL)
+ {
+ g_warning ("Error on creating GdaServerOperation: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ error = NULL;
+ 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.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ /*read_fields (gdacon, table_name);*/
+ if (!gda_server_operation_set_value_at (op, "id", &error,
+ "/FIELDS_A/@COLUMN_NAME/0"))
+ {
+ g_warning ("Error on setting GdaServerOperation's value: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+ if (!gda_server_operation_set_value_at (op, "INTEGER", &error,
+ "/FIELDS_A/@COLUMN_TYPE/0"))
+ {
+ g_warning ("Error on setting GdaServerOperation's value: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+
+ error = NULL;
+ if (!gda_connection_perform_operation (gda_conn_db, op, &error))
+ {
+ g_warning ("Error on performing GdaServerOperation: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ g_object_unref (op);
}
}
if (dm_tables != NULL)
GError *error;
GOptionContext *context;
- GHashTable *ht_ref_db_tables;
-
g_type_init ();
error = NULL;
update_metastore ();
g_message ("Reading tables of reference database (%s).", ref_db_cnc);
- ht_ref_db_tables = g_hash_table_new (g_str_hash, g_str_equal);
- read_tables (gda_conn_ref_db, ht_ref_db_tables);
+ read_tables (gda_conn_ref_db);
g_object_unref (gda_conn_ref_db);
g_object_unref (gda_conn_db);