From: Andrea Zagli Date: Fri, 2 Jul 2010 13:35:00 +0000 (+0200) Subject: Bugfix: transaction started on worng place. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=e5bc25ffc814e0e2c7c5641b1c0847648f4045cf;p=libzakdbt Bugfix: transaction started on worng place. Made GdaSqlParser a private member of Dbt structure. --- diff --git a/src/dbtransformer.c b/src/dbtransformer.c index b96b100..afe2c94 100644 --- a/src/dbtransformer.c +++ b/src/dbtransformer.c @@ -43,6 +43,7 @@ typedef struct _DbtPrivate DbtPrivate; struct _DbtPrivate { GdaConnection *gda_conn; + GdaSqlParser *gda_parser; xmlDocPtr xml_doc; xmlNodePtr xml_root; @@ -67,6 +68,7 @@ dbt_init (Dbt *dbt) DbtPrivate *priv = DBT_GET_PRIVATE (dbt); priv->gda_conn = NULL; + priv->gda_parser = NULL; priv->xml_doc = NULL; priv->xml_root = NULL; } @@ -91,15 +93,12 @@ dbt_get_connection_parser (Dbt *dbt) priv = DBT_GET_PRIVATE (dbt); /* create an SQL parser */ - parser = gda_connection_create_parser (priv->gda_conn); - if (!parser) /* @cnc does not provide its own parser => use default one */ + priv->gda_parser = gda_connection_create_parser (priv->gda_conn); + if (!priv->gda_parser) /* @cnc does not provide its own parser => use default one */ { - parser = gda_sql_parser_new (); + priv->gda_parser = gda_sql_parser_new (); } - /* attach the parser object to the connection */ - g_object_set_data_full (G_OBJECT (priv->gda_conn), "parser", parser, g_object_unref); - return TRUE; } @@ -242,7 +241,6 @@ dbt_check_db (Dbt *dbt) { DbtPrivate *priv; - GdaSqlParser *parser; GdaStatement *stmt; GdaDataModel *dm; GError *error; @@ -255,8 +253,7 @@ dbt_check_db (Dbt *dbt) priv = DBT_GET_PRIVATE (dbt); - parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser"); - if (!parser) + if (!GDA_IS_SQL_PARSER (priv->gda_parser)) { g_warning ("Invalid sql parser."); return ret; @@ -265,7 +262,7 @@ dbt_check_db (Dbt *dbt) /* dbtransformer tables check */ sql = "SELECT id FROM dbt_transformations WHERE 0=1"; error = NULL; - stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error); + stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error); if (stmt == NULL) { g_warning ("Unable to create GdaStatement from sql: %s\n%s", @@ -338,17 +335,16 @@ dbt_check_to_execute (Dbt *dbt, guint id) ret = FALSE; - GdaSqlParser *parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser"); - if (!parser) + if (!GDA_IS_SQL_PARSER (priv->gda_parser)) { g_warning ("Invalid sql parser."); return ret; } - sql = g_strdup_printf ("SELECT id FROM dbt_transformations" + sql = g_strdup_printf ("SELECT id FROM dbt_transformations" " WHERE id = %d", id); - stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error); + stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error); if (!stmt) { g_warning ("Unable to check operation existance: %s\n", @@ -389,8 +385,7 @@ dbt_save_transformation (Dbt *dbt, guint id, const gchar *operation) ret = FALSE; - GdaSqlParser *parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser"); - if (!parser) + if (!GDA_IS_SQL_PARSER (priv->gda_parser)) { g_warning ("Invalid sql parser."); return ret; @@ -400,7 +395,7 @@ dbt_save_transformation (Dbt *dbt, guint id, const gchar *operation) " (id, operation)" " VALUES (%d, '%s')", id, operation); - stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error); + stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error); if (!stmt) { g_warning ("Unable to save operation: %s\n", @@ -432,7 +427,6 @@ dbt_parse_sql (Dbt *dbt, xmlNodePtr xnode) gchar *sql; GError *error; GdaStatement *stmt; - GdaSqlParser *parser; gboolean ret; @@ -440,17 +434,16 @@ dbt_parse_sql (Dbt *dbt, xmlNodePtr xnode) priv = DBT_GET_PRIVATE (dbt); - parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser"); - if (!parser) + if (!GDA_IS_SQL_PARSER (priv->gda_parser)) { g_warning ("Invalid sql parser."); - return; + return FALSE; } sql = (gchar *)xmlNodeGetContent (xnode); error = NULL; - stmt = gda_sql_parser_parse_string (parser, g_strstrip (sql), NULL, &error); + stmt = gda_sql_parser_parse_string (priv->gda_parser, g_strstrip (sql), NULL, &error); if (stmt == NULL) { g_warning ("Unable to create GdaStatement from sql: %s\n%s", @@ -506,33 +499,30 @@ dbt_transform (Dbt *dbt) xpcontext->node = priv->xml_root; xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::dbtransformation", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) || xpresult->nodesetval->nodeNr < 1) { xnodeset = xpresult->nodesetval; - if (xnodeset->nodeNr < 1) - { - g_warning ("No transformations found."); - } - for (i = 0; i < xnodeset->nodeNr; i++) { tosave = TRUE; - /* starting the transaction */ - if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS)) - { - error = NULL; - if (!gda_connection_begin_transaction (priv->gda_conn, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, &error)) - { - continue; - } - } - id = strtol (xmlGetProp (xnodeset->nodeTab[i], (const gchar *)"id"), NULL, 10); if (dbt_check_to_execute (dbt, id)) { + /* starting the transaction */ + if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS)) + { + error = NULL; + if (!gda_connection_begin_transaction (priv->gda_conn, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, &error)) + { + g_warning ("Unable to start the transaction: %s\n", + error && error->message ? error->message : "No detail"); + continue; + } + } + xnode = xnodeset->nodeTab[i]->children; while (xnode != NULL) { @@ -542,10 +532,10 @@ dbt_transform (Dbt *dbt) { tosave = dbt_parse_sql (dbt, xnode); } - else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0) + /*else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0) { - //tosave = dbt_parse_gda_op (dbt, xnode); - } + tosave = dbt_parse_gda_op (dbt, xnode); + }*/ else { g_warning ("Invalid tag: %s", xnode->name); @@ -559,7 +549,9 @@ dbt_transform (Dbt *dbt) if (tosave) { gchar *operation; - xmlBufferPtr xbuf = xmlBufferCreate (); + xmlBufferPtr xbuf; + + xbuf = xmlBufferCreate (); xmlNodeDump (xbuf, priv->xml_doc, xnodeset->nodeTab[i], 0, 0); operation = g_strstrip (g_strdup (xbuf->content)); tosave = dbt_save_transformation (dbt, id, g_strstrip (operation)); diff --git a/tests/test.db b/tests/test.db index edaac89..a8d2e06 100644 Binary files a/tests/test.db and b/tests/test.db differ