From: Andrea Zagli Date: Thu, 27 Dec 2012 16:10:13 +0000 (+0100) Subject: Added command line arg --explicit, to bypass GdaMetaStore (closes #562). X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=19df5c1ace25128047939e50908217e16462880c;p=gdadbcopy Added command line arg --explicit, to bypass GdaMetaStore (closes #562). --- diff --git a/src/main.c b/src/main.c index 6098f62..bfcc471 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ static gchar *db_cnc = NULL; static gchar **tables_to_copy = NULL; static gboolean drop_tables = FALSE; static gchar *output_file = NULL; +static gboolean explicit = FALSE; static gboolean verbose = FALSE; static GdaConnection *gda_conn_ref_db = NULL; @@ -45,6 +46,7 @@ static GOptionEntry entries[] = { "table", 0, 0, G_OPTION_ARG_STRING_ARRAY, &tables_to_copy, "The table/view's name to copy (can be used multiple times)", "TABLE_NAME" }, { "drop-tables", 0, 0, G_OPTION_ARG_NONE, &drop_tables, "Drop tables before creating new ones", NULL }, { "output-file", 0, 0, G_OPTION_ARG_FILENAME, &output_file, "Ouput the whole operation in an xmlfile", "FILENAME" }, + { "explicit", 0, 0, G_OPTION_ARG_NONE, &explicit, "Read schema from sql statement, instead from GdaMetaStore (at least one --table must be provided)", NULL }, { "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "Verbose", NULL }, { NULL } }; @@ -189,7 +191,7 @@ copy_data () if (error != NULL) { g_warning ("Error executing insert into: %s", - (error != NULL && error->message != NULL ? error->message : "no details.")); + error != NULL && error->message != NULL ? error->message : "no details."); continue; } @@ -219,7 +221,7 @@ copy_data () else { g_warning ("Error executing select command: %s", - (error != NULL && error->message != NULL ? error->message : "no details.")); + error != NULL && error->message != NULL ? error->message : "no details."); continue; } } @@ -336,15 +338,26 @@ read_fields_explicit (Table *table, GdaServerOperation *op, GdaDataModel *dm) mt_column->default_value = gda_value_stringify (gda_column_get_default_value (gda_column)); table->fields = g_slist_append (table->fields, mt_column); + /*if (mt_column->column_type == NULL) + { + mt_column->column_type = g_strdup (gda_server_provider_get_default_dbms_type (gda_connection_get_provider (gda_conn_ref_db), + gda_conn_ref_db, + mt_column->gtype)); + }*/ + if (mt_column->column_type == NULL) + { + mt_column->column_type = g_strdup ("VARCHAR"); + } + if (verbose) { g_printf ("\t\tField: %s - %s - %d - %d - %d - %s\n", - mt_column->column_name, - mt_column->column_type, - mt_column->gtype, - mt_column->pkey, - mt_column->nullok, - mt_column->default_value); + mt_column->column_name, + mt_column->column_type, + mt_column->gtype, + mt_column->pkey, + mt_column->nullok, + mt_column->default_value); } field_server_operation (table, op, mt_column, col); @@ -1050,18 +1063,36 @@ main (int argc, char *argv[]) xroot = xmlNewNode (NULL, "gdadbcopy"); } - update_metastore (); + if (explicit) + { + if (tables_to_copy == NULL) + { + g_error ("Using parameter --explicit you must provide at least a table with parameter --table."); + return 0; + } + } + else + { + update_metastore (); + } g_printf ("* Reading tables of reference database (%s).\n", ref_db_cnc); tables = NULL; - read_tables (); + if (explicit) + { + read_tables_explicit (); + } + else + { + read_tables (); + } g_printf ("* Copying data.\n"); - //copy_data (); + copy_data (); g_printf ("* Reading views.\n"); - //read_views (); + read_views (); if (output_file != NULL) {