]> saetta.ns0.it Git - gdadbcopy/commitdiff
Trying to read explicitly also table's fields.
authorAndrea Zagli <azagli@libero.it>
Mon, 24 Dec 2012 10:41:32 +0000 (11:41 +0100)
committerAndrea Zagli <azagli@libero.it>
Mon, 24 Dec 2012 10:41:32 +0000 (11:41 +0100)
.cproject
src/main.c

index dcf18920cdda3c5e1d9135e716071e2cb411d1a3..d9f764fa83841b90bd2996cfe661a6492a509ae0 100644 (file)
--- a/.cproject
+++ b/.cproject
@@ -3,8 +3,8 @@
 
 <cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
        <storageModule moduleId="org.eclipse.cdt.core.settings">
-               <cconfiguration id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.444330930">
-                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.444330930" moduleId="org.eclipse.cdt.core.settings" name="Build (GNU)">
+               <cconfiguration id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.1442100906">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.1442100906" moduleId="org.eclipse.cdt.core.settings" name="Build (GNU)">
                                <externalSettings/>
                                <extensions>
                                        <extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
                                </extensions>
                        </storageModule>
                        <storageModule moduleId="cdtBuildSystem" version="4.0.0">
-                               <configuration buildProperties="" description="" id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.444330930" name="Build (GNU)" parent="org.eclipse.cdt.build.core.emptycfg">
-                                       <folderInfo id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.444330930.1685407473" name="/" resourcePath="">
-                                               <toolChain id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.836272450" name="org.eclipse.linuxtools.cdt.autotools.core.toolChain" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolChain">
-                                                       <targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.1031969505" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform"/>
-                                                       <builder id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.1197732403" keepEnvironmentInBuildfile="false" managedBuildOn="false" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder"/>
-                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.9367114" name="configure" superClass="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure">
-                                                               <option id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name.1131657011" name="Name" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name" value="org.eclipse.linuxtools.cdt.autotools.core.toolChain.444330930" valueType="string"/>
+                               <configuration buildProperties="" description="" id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.1442100906" name="Build (GNU)" parent="org.eclipse.cdt.build.core.emptycfg">
+                                       <folderInfo id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.1442100906.224399110" name="/" resourcePath="">
+                                               <toolChain id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.454212349" name="org.eclipse.linuxtools.cdt.autotools.core.toolChain" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolChain">
+                                                       <targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.1294595179" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform"/>
+                                                       <builder id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.1137626508" keepEnvironmentInBuildfile="false" managedBuildOn="false" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder"/>
+                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.366962293" name="configure" superClass="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure">
+                                                               <option id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name.2134586507" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name" value="org.eclipse.linuxtools.cdt.autotools.core.toolChain.1442100906" valueType="string"/>
                                                        </tool>
-                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.autogen.155784590" name="autogen.sh" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.autogen"/>
-                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gcc.867105742" name="GCC C Compiler" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gcc">
-                                                               <option id="gnu.c.compiler.option.include.paths.621876005" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.autogen.726647795" name="autogen.sh" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.autogen"/>
+                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gcc.268465676" name="GCC C Compiler" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gcc">
+                                                               <option id="gnu.c.compiler.option.include.paths.2002526018" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\glib-2.0&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\libxml2&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\libgda-4.0&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\libgda-4.0\libgda&quot;"/>
                                                                </option>
-                                                               <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.842059199" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1374899466" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
                                                        </tool>
-                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gpp.985338712" name="GCC C++ Compiler" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gpp"/>
+                                                       <tool id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gpp.1477690685" name="GCC C++ Compiler" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gpp"/>
                                                </toolChain>
                                        </folderInfo>
                                </configuration>
                </cconfiguration>
        </storageModule>
        <storageModule moduleId="cdtBuildSystem" version="4.0.0">
-               <project id="gdadbcopy.null.366714648" name="gdadbcopy"/>
+               <project id="gdadbcopy.null.1010149427" name="gdadbcopy"/>
        </storageModule>
        <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
        <storageModule moduleId="scannerConfiguration">
                <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               <scannerConfigBuildInfo instanceId="org.eclipse.linuxtools.cdt.autotools.core.toolChain.1442100906;org.eclipse.linuxtools.cdt.autotools.core.toolChain.1442100906.224399110;org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gcc.268465676;cdt.managedbuild.tool.gnu.c.compiler.input.1374899466">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
+               </scannerConfigBuildInfo>
                <scannerConfigBuildInfo instanceId="org.eclipse.linuxtools.cdt.autotools.core.toolChain.444330930;org.eclipse.linuxtools.cdt.autotools.core.toolChain.444330930.1685407473;org.eclipse.linuxtools.cdt.autotools.core.toolchain.tool.gcc.867105742;cdt.managedbuild.tool.gnu.c.compiler.input.842059199">
                        <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
                </scannerConfigBuildInfo>
index 7ff1c5b2e492b103103da819fa3c86eb8e9ed108..6098f6210336b61081aceff4bf0c09cf0e67177f 100644 (file)
@@ -313,6 +313,44 @@ field_server_operation (Table *table,
        return TRUE;
 }
 
+static void
+read_fields_explicit (Table *table, GdaServerOperation *op, GdaDataModel *dm)
+{
+       guint col;
+       guint cols;
+
+       GdaColumn *gda_column;
+       GdaMetaTableColumn *mt_column;
+
+       cols = gda_data_model_get_n_columns (dm);
+       for (col = 0; col < cols; col++)
+               {
+                       gda_column = gda_data_model_describe_column (dm, col);
+
+                       mt_column = g_new0 (GdaMetaTableColumn, 1);
+                       mt_column->column_name = g_strdup (gda_column_get_name (gda_column));
+                       mt_column->column_type = g_strdup (gda_column_get_dbms_type (gda_column));
+                       mt_column->gtype = gda_column_get_g_type (gda_column);
+                       /*mt_column->pkey = gda_column_get_*/
+                       mt_column->nullok = gda_column_get_allow_null (gda_column);
+                       mt_column->default_value = gda_value_stringify (gda_column_get_default_value (gda_column));
+                       table->fields = g_slist_append (table->fields, mt_column);
+
+                       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);
+                               }
+
+                       field_server_operation (table, op, mt_column, col);
+               }
+}
+
 static void
 read_fields (Table *table, GdaServerOperation *op)
 {
@@ -365,6 +403,8 @@ read_fields (Table *table, GdaServerOperation *op)
 
                        table->fields = NULL;
 
+                       if (meta_table->columns != NULL && meta_table->columns->data != NULL)
+                       {
                        i = 0;
                        for (list = meta_table->columns; list; list = list->next, i++)
                                {
@@ -399,6 +439,34 @@ read_fields (Table *table, GdaServerOperation *op)
 
                                        field_server_operation (table, op, column, i);
                                }
+                       }
+                       else
+                               {
+                                       /* no columns; trying to read explicitly */
+                                       GdaSqlParser *parser;
+                                       gchar *sql;
+                                       GdaStatement *stmt;
+                                       GdaDataModel *dm;
+
+                                       g_printf ("* No columns from MetaStore: trying to read them from a select.\n");
+
+                                       parser = gda_connection_create_parser (gda_conn_ref_db);
+                                       if (!parser)
+                                               {
+                                                       /* @cnc doe snot provide its own parser => use default one */
+                                                       parser = gda_sql_parser_new ();
+                                               }
+
+                                       sql = g_strdup_printf ("SELECT * FROM %s", table->name);
+                                       stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
+                                       g_free (sql);
+                                       dm = gda_connection_statement_execute_select (gda_conn_ref_db, stmt, NULL, &error);
+                                       g_object_unref (stmt);
+                                       if (dm != NULL)
+                                               {
+                                                       read_fields_explicit (table, op, dm);
+                                               }
+                               }
                }
        g_object_unref (mstruct);
 }
@@ -546,8 +614,6 @@ read_tables_explicit ()
 
                        Table *table;
                        GdaServerOperation *op;
-                       GdaColumn *gda_column;
-                       GdaMetaTableColumn *mt_column;
 
                        g_printf ("* Reading tables on reference database declared on command line.\n");
 
@@ -591,32 +657,7 @@ read_tables_explicit ()
                                                                                }
                                                                }
 
-                                                       for (col = 0; col < cols; col++)
-                                                               {
-                                                                       gda_column = gda_data_model_describe_column (dm, col);
-
-                                                                       mt_column = g_new0 (GdaMetaTableColumn, 1);
-                                                                       mt_column->column_name = g_strdup (gda_column_get_name (gda_column));
-                                                                       mt_column->column_type = g_strdup (gda_column_get_dbms_type (gda_column));
-                                                                       mt_column->gtype = gda_column_get_g_type (gda_column);
-                                                                       /*mt_column->pkey = gda_column_get_*/
-                                                                       mt_column->nullok = gda_column_get_allow_null (gda_column);
-                                                                       mt_column->default_value = gda_value_stringify (gda_column_get_default_value (gda_column));
-                                                                       table->fields = g_slist_append (table->fields, mt_column);
-
-                                                                       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);
-                                                                               }
-
-                                                                       field_server_operation (table, op, mt_column, col);
-                                                               }
+                                                       read_fields_explicit (table, op, dm);
 
                                                        if (cols > 0)
                                                                {
@@ -731,6 +772,12 @@ read_tables ()
                                        tables = g_slist_append (tables, table);
                                }
                }
+       else
+               {
+                       g_printf ("* No table on reference database.\n");
+                       read_tables_explicit ();
+               }
+
        if (dm_tables != NULL)
                {
                        g_object_unref (dm_tables);
@@ -1011,10 +1058,10 @@ main (int argc, char *argv[])
        read_tables ();
 
        g_printf ("* Copying data.\n");
-       copy_data ();
+       //copy_data ();
 
        g_printf ("* Reading views.\n");
-       read_views ();
+       //read_views ();
 
        if (output_file != NULL)
                {