From: Andrea Zagli Date: Fri, 30 Jul 2010 17:27:18 +0000 (+0200) Subject: Added and managed drop_view tag. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=ffa45326b19680262e414e50f36bc2d7b1601b3f;p=libzakdbt Added and managed drop_view tag. --- diff --git a/docs/dbtransformer.dtd b/docs/dbtransformer.dtd index b040d08..28f1e99 100644 --- a/docs/dbtransformer.dtd +++ b/docs/dbtransformer.dtd @@ -1,6 +1,10 @@ - + + + + + diff --git a/src/dbtransformer.c b/src/dbtransformer.c index ad40381..8f25b00 100644 --- a/src/dbtransformer.c +++ b/src/dbtransformer.c @@ -667,7 +667,75 @@ dbt_parse_drop_table (Dbt *dbt, xmlNodePtr xnode) } else { - g_warning ("You must provide the name of the table."); + g_warning ("You must provide the name of the table to drop."); + ret = FALSE; + } + + return ret; +} + +static gboolean +dbt_parse_drop_view (Dbt *dbt, xmlNodePtr xnode) +{ + DbtPrivate *priv; + + gboolean ret; + + xmlNodePtr cur; + gchar *view_name; + + GError *error; + + ret = TRUE; + + priv = DBT_GET_PRIVATE (dbt); + + view_name = NULL; + cur = xnode->children; + while (cur != NULL && ret) + { + if (xmlStrcmp (cur->name, (const xmlChar *)"view_name") == 0) + { + view_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur))); + } + + cur = cur->next; + } + + if (view_name != NULL && g_strcmp0 (view_name, "") != 0) + { + gchar *sql; + GdaStatement *stmt; + + sql = g_strdup_printf ("DROP VIEW %s", view_name); + + error = NULL; + 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", + error != NULL && error->message != NULL ? error->message : "no detail", + sql); + 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", + error != NULL && error->message != NULL ? error->message : "no detail", + sql); + ret = FALSE; + } + g_object_unref (stmt); + } + } + else + { + g_warning ("You must provide the name of the view to drop."); ret = FALSE; } @@ -752,6 +820,10 @@ dbt_transform (Dbt *dbt) { tosave = dbt_parse_drop_table (dbt, xnode); } + else if (xmlStrcmp (xnode->name, (const xmlChar *)"drop_view") == 0) + { + tosave = dbt_parse_drop_view (dbt, xnode); + } else { g_warning ("Invalid tag: %s.", xnode->name);