]> saetta.ns0.it Git - libzakdbt/commitdiff
Rationalized Dbt::transform.
authorAndrea Zagli <azagli@libero.it>
Fri, 2 Jul 2010 13:14:00 +0000 (15:14 +0200)
committerAndrea Zagli <azagli@libero.it>
Fri, 2 Jul 2010 13:14:00 +0000 (15:14 +0200)
.gitignore
src/dbtransformer.c

index bdde3954e42fb4c494258ae6160abaa2fbc6e3a3..bb9762b1977c81a15895bf44fc812bfd49633e9f 100644 (file)
@@ -47,3 +47,5 @@ stamp-it
 intltool-*
 Rules-quot
 *.exe
+.cproject
+.project
index d1f817d9ded474491ad4a664e2fe370cea0e1ce2..b96b10096ecd5beeceea1a7c3066610887ec7dbd 100644 (file)
@@ -92,7 +92,7 @@ dbt_get_connection_parser (Dbt *dbt)
 
        /* create an SQL parser */
        parser = gda_connection_create_parser (priv->gda_conn);
-       if (!parser) /* @cnc doe snot provide its own parser => use default one */
+       if (!parser) /* @cnc doenot provide its own parser => use default one */
                {
                        parser = gda_sql_parser_new ();
                }
@@ -424,6 +424,56 @@ dbt_save_transformation (Dbt *dbt, guint id, const gchar *operation)
        return ret;
 }
 
+static gboolean
+dbt_parse_sql (Dbt *dbt, xmlNodePtr xnode)
+{
+       DbtPrivate *priv;
+
+       gchar *sql;
+       GError *error;
+       GdaStatement *stmt;
+       GdaSqlParser *parser;
+
+       gboolean ret;
+
+       ret = TRUE;
+
+       priv = DBT_GET_PRIVATE (dbt);
+
+       parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser");
+       if (!parser)
+               {
+                       g_warning ("Invalid sql parser.");
+                       return;
+               }
+
+       sql = (gchar *)xmlNodeGetContent (xnode);
+
+       error = NULL;
+       stmt = gda_sql_parser_parse_string (parser, g_strstrip (sql), NULL, &error);
+       if (stmt == NULL)
+               {
+                       g_warning ("Unable to create GdaStatement from sql: %s\n%s",
+                                          sql, error && error->message ? error->message : "No detail");
+                       ret = FALSE;
+               }
+       else
+               {
+                       guint nrows;
+
+                       nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
+                       if (nrows == -1)
+                               {
+                                       g_warning ("NON SELECT error: %s\n%s\n", sql,
+                                                  error && error->message ? error->message : "No detail");
+                                       ret = FALSE;
+                               }
+                       g_object_unref (stmt);
+               }
+
+       return ret;
+}
+
 void
 dbt_transform (Dbt *dbt)
 {
@@ -458,13 +508,6 @@ dbt_transform (Dbt *dbt)
        xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::dbtransformation", xpcontext);
        if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
                {
-                       GdaSqlParser *parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser");
-                       if (!parser)
-                               {
-                                       g_warning ("Invalid sql parser.");
-                                       return;
-                               }
-
                        xnodeset = xpresult->nodesetval;
 
                        if (xnodeset->nodeNr < 1)
@@ -493,38 +536,22 @@ dbt_transform (Dbt *dbt)
                                                        xnode = xnodeset->nodeTab[i]->children;
                                                        while (xnode != NULL)
                                                                {
-                                                                       if (!xmlNodeIsText (xnode)
-                                                                               && xmlStrcmp (xnode->name, (const xmlChar *)"sql") == 0)
+                                                                       if (!xmlNodeIsText (xnode))
                                                                                {
-                                                                                       gchar *sql = (gchar *)xmlNodeGetContent (xnode);
-
-                                                                                       GdaStatement *stmt;
-
-                                                                                       error = NULL;
-                                                                                       stmt = gda_sql_parser_parse_string (parser, g_strstrip (sql), NULL, &error);
-                                                                                       if (stmt == NULL)
+                                                                                       if (xmlStrcmp (xnode->name, (const xmlChar *)"sql") == 0)
                                                                                                {
-                                                                                                       g_warning ("Unable to create GdaStatement from sql: %s\n%s",
-                                                                                                                          sql, error && error->message ? error->message : "No detail");
-                                                                                                       tosave = FALSE;
+                                                                                                       tosave = dbt_parse_sql (dbt, xnode);
+                                                                                               }
+                                                                                       else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0)
+                                                                                               {
+                                                                                                       //tosave = dbt_parse_gda_op (dbt, xnode);
                                                                                                }
                                                                                        else
                                                                                                {
-                                                                                                       guint nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
-                                                                                                       if (nrows == -1)
-                                                                                                               {
-                                                                                                                       g_warning ("NON SELECT error: %s\n%s\n", sql,
-                                                                                                                                          error && error->message ? error->message : "No detail");
-                                                                                                                       tosave = FALSE;
-                                                                                                               }
-                                                                                                       g_object_unref (stmt);
+                                                                                                       g_warning ("Invalid tag: %s", xnode->name);
+                                                                                                       tosave = FALSE;
                                                                                                }
                                                                                }
-                                                                       else if (!xmlNodeIsText (xnode))
-                                                                               {
-                                                                                       g_warning ("Invalid tag: %s", xnode->name);
-                                                                                       tosave = FALSE;
-                                                                               }
 
                                                                        xnode = xnode->next;
                                                                }