]> saetta.ns0.it Git - libzakdbt/commitdiff
Execution of transformations inside a transaction.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 1 Jul 2010 17:16:00 +0000 (19:16 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 1 Jul 2010 17:16:00 +0000 (19:16 +0200)
src/dbtransformer.c
tests/test.db

index 3c107018ecd84f4c402a4fb4538d4a0225f00f06..d1f817d9ded474491ad4a664e2fe370cea0e1ce2 100644 (file)
@@ -433,6 +433,8 @@ dbt_transform (Dbt *dbt)
        xmlNodeSetPtr xnodeset;
        xmlNodePtr xnode;
 
+       GError *error;
+
        guint id;
        gboolean tosave;
 
@@ -474,6 +476,16 @@ dbt_transform (Dbt *dbt)
                                {
                                        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))
@@ -487,13 +499,14 @@ dbt_transform (Dbt *dbt)
                                                                                        gchar *sql = (gchar *)xmlNodeGetContent (xnode);
 
                                                                                        GdaStatement *stmt;
-                                                                                       GError *error = NULL;
 
+                                                                                       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");
+                                                                                                       tosave = FALSE;
                                                                                                }
                                                                                        else
                                                                                                {
@@ -502,6 +515,7 @@ dbt_transform (Dbt *dbt)
                                                                                                                {
                                                                                                                        g_warning ("NON SELECT error: %s\n%s\n", sql,
                                                                                                                                           error && error->message ? error->message : "No detail");
+                                                                                                                       tosave = FALSE;
                                                                                                                }
                                                                                                        g_object_unref (stmt);
                                                                                                }
@@ -509,6 +523,7 @@ dbt_transform (Dbt *dbt)
                                                                        else if (!xmlNodeIsText (xnode))
                                                                                {
                                                                                        g_warning ("Invalid tag: %s", xnode->name);
+                                                                                       tosave = FALSE;
                                                                                }
 
                                                                        xnode = xnode->next;
@@ -520,7 +535,21 @@ dbt_transform (Dbt *dbt)
                                                                        xmlBufferPtr xbuf = xmlBufferCreate ();
                                                                        xmlNodeDump (xbuf, priv->xml_doc, xnodeset->nodeTab[i], 0, 0);
                                                                        operation = g_strstrip (g_strdup (xbuf->content));
-                                                                       dbt_save_transformation (dbt, id, g_strstrip (operation));
+                                                                       tosave = dbt_save_transformation (dbt, id, g_strstrip (operation));
+                                                               }
+
+                                                       /* ending transaction */
+                                                       if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS))
+                                                               {
+                                                                       error = NULL;
+                                                                       if (tosave)
+                                                                               {
+                                                                                       gda_connection_commit_transaction (priv->gda_conn, NULL, &error);
+                                                                               }
+                                                                       else
+                                                                               {
+                                                                                       gda_connection_rollback_transaction (priv->gda_conn, NULL, &error);
+                                                                               }
                                                                }
                                                }
                                }
index d2bd5f9bbccb77ce95b239d9c493f855f2db840d..edaac89c7f6e978586425b38fb3d8e02cbf1bb35 100644 (file)
Binary files a/tests/test.db and b/tests/test.db differ