return ret;
}
+static gboolean
+dbt_save_transformation (Dbt *dbt, guint id, const gchar *operation)
+{
+ 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 ("INSERT INTO dbt_transformations"
+ " (id, operation)"
+ " VALUES (%d, '%s')",
+ id, operation);
+ stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
+ if (!stmt)
+ {
+ g_warning ("Unable to save operation: %s\n",
+ 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)
+ {
+ g_warning ("NON SELECT error: %s\n%s\n", sql,
+ error && error->message ? error->message : "No detail");
+ }
+ else
+ {
+ ret = TRUE;
+ }
+ g_object_unref (stmt);
+ }
+
+ return ret;
+}
+
void
dbt_transform (Dbt *dbt)
{
xmlNodeSetPtr xnodeset;
xmlNodePtr xnode;
+ guint id;
+ gboolean tosave;
+
guint i;
g_return_if_fail (IS_DBT (dbt));
}
xnodeset = xpresult->nodesetval;
+
+ if (xnodeset->nodeNr < 1)
+ {
+ g_warning ("No transformations found.");
+ }
+
for (i = 0; i < xnodeset->nodeNr; i++)
{
- xnode = xnodeset->nodeTab[i];
- if (xmlStrcmp (xnode->name, (const xmlChar *)"sql") == 0)
- {
- gchar *sql = (gchar *)xmlNodeGetContent (xnode);
+ tosave = TRUE;
- GdaStatement *stmt;
- GError *error = NULL;
+ id = strtol (xmlGetProp (xnodeset->nodeTab[i], (const gchar *)"id"), NULL, 10);
- 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
+ xnode = xnodeset->nodeTab[i]->children;
+ while (xnode != NULL)
+ {
+ if (!xmlNodeIsText (xnode)
+ && xmlStrcmp (xnode->name, (const xmlChar *)"sql") == 0)
{
- guint nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
- if (nrows == -1)
+ gchar *sql = (gchar *)xmlNodeGetContent (xnode);
+
+ GdaStatement *stmt;
+ GError *error = NULL;
+
+ stmt = gda_sql_parser_parse_string (parser, g_strstrip (sql), NULL, &error);
+ if (stmt == NULL)
{
- g_warning ("NON SELECT error: %s\n", 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;
+ }
+
+ if (tosave)
+ {
+ /*gchar *operation;
+ xmlBufferPtr xbuf = xmlBufferCreate ();
+ xmlNodeDump (xbuf, priv->xml_doc, xnodeset->nodeTab[i], 2, 1);
+ operation = xml
+ dbt_save_transformation (dbt, id, g_strstrip (operation));*/
}
}
}
+ else
+ {
+ g_warning ("No transformation found.");
+ }
}
/* PRIVATE */
<dbtransformation id="1">
<sql>
- CREATE TABLE clients (id integer, name varchar(50), CONSTRAINT PRIMARY KEY clients_pkey (id))
+ CREATE TABLE clients (id integer, name varchar(50), CONSTRAINT clients_pkey PRIMARY KEY (id))
</sql>
<sql>
- CREATE TABLE orders (id integer, id_client integer, "date" date, CONSTRAINT PRIMARY KEY orders_pkey (id))
+ CREATE TABLE orders (id integer, id_client integer, "date" date, CONSTRAINT orders_pkey PRIMARY KEY (id))
</sql>
</dbtransformation>
<dbtransformation id="2">
<sql>
- ALTER TABLE order ADD COLUMN (total double)
+ ALTER TABLE orders ADD COLUMN total double
</sql>
</dbtransformation>