From 1197d77465d4822d61dd589804ef0829ed356423 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Fri, 2 Jul 2010 15:14:00 +0200 Subject: [PATCH] Rationalized Dbt::transform. --- .gitignore | 2 + src/dbtransformer.c | 93 +++++++++++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index bdde395..bb9762b 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ stamp-it intltool-* Rules-quot *.exe +.cproject +.project diff --git a/src/dbtransformer.c b/src/dbtransformer.c index d1f817d..b96b100 100644 --- a/src/dbtransformer.c +++ b/src/dbtransformer.c @@ -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 does not 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; } -- 2.49.0