return ret;
}
+static gboolean
+dbt_check_to_execute (Dbt *dbt, guint id)
+{
+ DbtPrivate *priv;
+
+ gboolean ret;
+
+ gchar *sql;
+ GError *error;
+ GdaStatement *stmt;
+
+ priv = DBT_GET_PRIVATE (dbt);
+
+ ret = FALSE;
+
+ GdaSqlParser *parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser");
+ if (!parser)
+ {
+ g_warning ("Invalid sql parser.");
+ return ret;
+ }
+
+ sql = g_strdup_printf ("SELECT id FROM dbt_transformations"
+ " WHERE id = %d",
+ id);
+ stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
+ if (!stmt)
+ {
+ g_warning ("Unable to check operation existance: %s\n",
+ error && error->message ? error->message : "No detail");
+ }
+ else
+ {
+ GdaDataModel *dm;
+
+ dm = gda_connection_statement_execute_select (priv->gda_conn, stmt, NULL, &error);
+ g_object_unref (stmt);
+ if (dm && gda_data_model_get_n_rows (dm) == 0)
+ {
+ ret = TRUE;
+ }
+ }
+
+ if (!ret)
+ {
+ g_message ("Operation id %d already executed.", id);
+ }
+
+ return ret;
+}
+
static gboolean
dbt_save_transformation (Dbt *dbt, guint id, const gchar *operation)
{
id = strtol (xmlGetProp (xnodeset->nodeTab[i], (const gchar *)"id"), NULL, 10);
- xnode = xnodeset->nodeTab[i]->children;
- while (xnode != NULL)
+ if (dbt_check_to_execute (dbt, id))
{
- if (!xmlNodeIsText (xnode)
- && xmlStrcmp (xnode->name, (const xmlChar *)"sql") == 0)
+ xnode = xnodeset->nodeTab[i]->children;
+ while (xnode != NULL)
{
- gchar *sql = (gchar *)xmlNodeGetContent (xnode);
+ if (!xmlNodeIsText (xnode)
+ && xmlStrcmp (xnode->name, (const xmlChar *)"sql") == 0)
+ {
+ gchar *sql = (gchar *)xmlNodeGetContent (xnode);
- GdaStatement *stmt;
- GError *error = NULL;
+ GdaStatement *stmt;
+ GError *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");
- }
- else
- {
- guint nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
- if (nrows == -1)
+ stmt = gda_sql_parser_parse_string (parser, g_strstrip (sql), NULL, &error);
+ if (stmt == NULL)
{
- g_warning ("NON SELECT error: %s\n%s\n", sql,
- error && error->message ? error->message : "No detail");
+ g_warning ("Unable to create GdaStatement from sql: %s\n%s",
+ sql, error && error->message ? error->message : "No detail");
}
- g_object_unref (stmt);
+ 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");
+ }
+ g_object_unref (stmt);
+ }
+ }
+ else if (!xmlNodeIsText (xnode))
+ {
+ g_warning ("Invalid tag: %s", xnode->name);
}
+
+ xnode = xnode->next;
}
- else if (!xmlNodeIsText (xnode))
+
+ if (tosave)
{
- g_warning ("Invalid tag: %s", xnode->name);
+ gchar *operation;
+ 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));
}
-
- xnode = xnode->next;
- }
-
- if (tosave)
- {
- gchar *operation;
- 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));
}
}
}