From: Andrea Zagli Date: Fri, 30 Jul 2010 17:17:20 +0000 (+0200) Subject: Depends on libgda 4.1.8. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=42eeb5549c4743e3a2c9c78383a684b2774475ac;p=libzakdbt Depends on libgda 4.1.8. Some adjustments. Added and managed drop_table tag. Some gtk-doc. Managed includes on xml file. --- diff --git a/configure.ac b/configure.ac index 5507bcb..2866069 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ AC_PROG_RANLIB GTK_DOC_CHECK # Checks for libraries. -PKG_CHECK_MODULES(DBT, [libgda-4.0 >= 4.0.0]) +PKG_CHECK_MODULES(DBT, [libgda-4.0 >= 4.1.8]) AC_SUBST(DBT_CFLAGS) AC_SUBST(DBT_LIBS) diff --git a/docs/dbtransformer.dtd b/docs/dbtransformer.dtd index eef1a95..b040d08 100644 --- a/docs/dbtransformer.dtd +++ b/docs/dbtransformer.dtd @@ -1,6 +1,6 @@ - + + + + + diff --git a/src/dbtransformer.c b/src/dbtransformer.c index 94f758c..ad40381 100644 --- a/src/dbtransformer.c +++ b/src/dbtransformer.c @@ -21,6 +21,7 @@ #endif #include +#include #include #include "libdbtransformer.h" @@ -102,6 +103,12 @@ dbt_get_connection_parser (Dbt *dbt) return TRUE; } +/** + * dbt_set_db_connection: + * @dbt: + * @gda_conn: + * + */ void dbt_set_db_connection (Dbt *dbt, GdaConnection *gda_conn) { @@ -117,10 +124,19 @@ dbt_set_db_connection (Dbt *dbt, GdaConnection *gda_conn) if (!dbt_get_connection_parser (dbt)) { priv->gda_conn= NULL; + + g_warning ("Unable to obtain the GdaSqlParser from the connection."); + return; } } +/** + * dbt_set_db_connection_from_string: + * @dbt: + * @cnc_string: + * + */ void dbt_set_db_connection_from_string (Dbt *dbt, const gchar *cnc_string) { @@ -145,8 +161,8 @@ dbt_set_db_connection_from_string (Dbt *dbt, const gchar *cnc_string) &error); if (!priv->gda_conn) { - g_warning ("Could not open connection: %s\n", - error && error->message ? error->message : "No detail"); + g_warning ("Could not open connection: %s.\n", + error != NULL && error->message != NULL ? error->message : "no detail"); return; } @@ -171,6 +187,12 @@ dbt_check_xml_root (xmlNodePtr xml_root) } } +/** + * dbt_set_xml: + * @dbt: + * @xml_root: + * + */ void dbt_set_xml (Dbt *dbt, xmlNodePtr xml_root) { @@ -191,9 +213,20 @@ dbt_set_xml (Dbt *dbt, xmlNodePtr xml_root) /* creation of an xmlDoc */ priv->xml_doc = xmlNewDoc ("1.0"); xmlDocSetRootElement (priv->xml_doc, priv->xml_root); + + /* xmlinclude */ + if (xmlXIncludeProcess (priv->xml_doc) < 0) + { + g_warning ("Unable to include xml external files."); + } } } - +/** + * dbt_set_xml_from_filename: + * @dbt: + * @filename: + * + */ void dbt_set_xml_from_filename (Dbt *dbt, const gchar *filename) { @@ -211,7 +244,6 @@ dbt_set_xml_from_filename (Dbt *dbt, const gchar *filename) g_return_if_fail (g_strcmp0 (filen, "") != 0); /* TODO validate against DTD */ - /* TODO allow include */ xdoc = xmlParseFile (filen); if (xdoc == NULL) @@ -223,6 +255,13 @@ dbt_set_xml_from_filename (Dbt *dbt, const gchar *filename) priv = DBT_GET_PRIVATE (dbt); priv->xml_doc = xdoc; + + /* xmlinclude */ + if (xmlXIncludeProcess (priv->xml_doc) < 0) + { + g_warning ("Unable to include xml external files."); + } + priv->xml_root = xmlDocGetRootElement (priv->xml_doc); if (priv->xml_root == NULL) { @@ -284,8 +323,8 @@ dbt_check_db (Dbt *dbt) op = gda_server_provider_create_operation (provider, priv->gda_conn, GDA_SERVER_OPERATION_CREATE_TABLE, NULL, &error); if (!op) { - g_print ("CREATE TABLE operation is not supported by the provider: %s\n", - error && error->message ? error->message : "No detail"); + g_warning ("CREATE TABLE operation is not supported by the provider: %s.", + error != NULL && error->message != NULL ? error->message : "no detail"); return ret; } @@ -314,8 +353,8 @@ dbt_check_db (Dbt *dbt) /* execute the operation */ if (!gda_server_provider_perform_operation (provider, priv->gda_conn, op, &error)) { - g_print ("Error executing the operation: %s\n", - error && error->message ? error->message : "No detail"); + g_warning ("Error executing the operation: %s.", + error != NULL && error->message != NULL ? error->message : "No detail"); return ret; } g_object_unref (op); @@ -354,8 +393,8 @@ dbt_check_to_execute (Dbt *dbt, guint id) stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error); if (!stmt) { - g_warning ("Unable to check operation existance: %s\n", - error && error->message ? error->message : "No detail"); + g_warning ("Unable to check operation existance: %s.", + error != NULL && error->message != NULL ? error->message : "no detail"); } else { @@ -405,16 +444,17 @@ dbt_save_transformation (Dbt *dbt, guint id, const gchar *operation) stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error); if (!stmt) { - g_warning ("Unable to save operation: %s\n", - error && error->message ? error->message : "No detail"); + g_warning ("Unable to save operation: %s.", + error != NULL && error->message != NULL ? 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"); + g_warning ("NON SELECT error: %s.\n%s", + error != NULL && error->message != NULL ? error->message : "no detail", + sql); } else { @@ -453,8 +493,9 @@ dbt_parse_sql (Dbt *dbt, xmlNodePtr xnode) 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", - sql, error && error->message ? error->message : "No detail"); + g_warning ("Unable to create GdaStatement from sql: %s.\n%s", + error != NULL && error->message != NULL ? error->message : "no detail", + sql); ret = FALSE; } else @@ -464,8 +505,9 @@ dbt_parse_sql (Dbt *dbt, xmlNodePtr xnode) 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_warning ("NON SELECT error: %s.\n%s", + error != NULL && error->message != NULL ? error->message : "no detail", + sql); ret = FALSE; } g_object_unref (stmt); @@ -504,7 +546,7 @@ dbt_parse_gda_op (Dbt *dbt, xmlNodePtr xnode) if (xmlStrcmp (cur->name, (const xmlChar *)"serv_op_data") != 0) { - g_warning ("Invalid tag \"%s\".\n", cur->name); + g_warning ("Invalid tag \"%s\".", cur->name); ret = FALSE; cur = cur->next; continue; @@ -512,33 +554,11 @@ dbt_parse_gda_op (Dbt *dbt, xmlNodePtr xnode) str_operation_type = (gchar *)xmlGetProp(cur, (const xmlChar *)"type"); - /* TODO - * must find the GdaServerOperationType of the string - * i asked on gda mailing list - * for now i implement it - */ - operation_type = GDA_SERVER_OPERATION_LAST; - if (g_strcmp0 (str_operation_type, "CREATE_DB") == 0) operation_type = GDA_SERVER_OPERATION_CREATE_DB; - if (g_strcmp0 (str_operation_type, "DROP_DB") == 0) operation_type = GDA_SERVER_OPERATION_DROP_DB; - if (g_strcmp0 (str_operation_type, "CREATE_TABLE") == 0) operation_type = GDA_SERVER_OPERATION_CREATE_TABLE; - if (g_strcmp0 (str_operation_type, "DROP_TABLE") == 0) operation_type = GDA_SERVER_OPERATION_DROP_TABLE; - if (g_strcmp0 (str_operation_type, "CREATE_INDEX") == 0) operation_type = GDA_SERVER_OPERATION_CREATE_INDEX; - if (g_strcmp0 (str_operation_type, "DROP_INDEX") == 0) operation_type = GDA_SERVER_OPERATION_DROP_INDEX; - if (g_strcmp0 (str_operation_type, "RENAME_TABLE") == 0) operation_type = GDA_SERVER_OPERATION_RENAME_TABLE; - if (g_strcmp0 (str_operation_type, "COMMENT_TABLE") == 0) operation_type = GDA_SERVER_OPERATION_COMMENT_TABLE; - if (g_strcmp0 (str_operation_type, "ADD_COLUMN") == 0) operation_type = GDA_SERVER_OPERATION_ADD_COLUMN; - if (g_strcmp0 (str_operation_type, "DROP_COLUMN") == 0) operation_type = GDA_SERVER_OPERATION_DROP_COLUMN; - if (g_strcmp0 (str_operation_type, "COMMENT_COLUMN") == 0) operation_type = GDA_SERVER_OPERATION_COMMENT_COLUMN; - if (g_strcmp0 (str_operation_type, "CREATE_VIEW") == 0) operation_type = GDA_SERVER_OPERATION_CREATE_VIEW; - if (g_strcmp0 (str_operation_type, "DROP_VIEW") == 0) operation_type = GDA_SERVER_OPERATION_DROP_VIEW; - if (g_strcmp0 (str_operation_type, "CREATE_USER") == 0) operation_type = GDA_SERVER_OPERATION_CREATE_USER; - if (g_strcmp0 (str_operation_type, "DROP_USER") == 0) operation_type = GDA_SERVER_OPERATION_DROP_USER; - if (g_strcmp0 (str_operation_type, "ALTER_USER") == 0) operation_type = GDA_SERVER_OPERATION_ALTER_USER; - - if (operation_type == GDA_SERVER_OPERATION_LAST) + operation_type = gda_server_operation_string_to_op_type (str_operation_type); + if (operation_type == G_MAXINT) { - g_warning ("Operation type \"%s\" not supported.\n%s\n", str_operation_type, - error && error->message ? error->message : "No detail"); + g_warning ("Operation type \"%s\" not supported: %s.", str_operation_type, + error != NULL && error->message != NULL ? error->message : "no detail"); return FALSE; } @@ -549,8 +569,8 @@ dbt_parse_gda_op (Dbt *dbt, xmlNodePtr xnode) op = gda_server_provider_create_operation (provider, priv->gda_conn, operation_type, NULL, &error); if (!op) { - g_warning ("Unable to create operation type \"%s\".\n%s\n", str_operation_type, - error && error->message ? error->message : "No detail"); + g_warning ("Unable to create operation type \"%s\": %s.", str_operation_type, + error != NULL && error->message != NULL ? error->message : "no detail"); ret = FALSE; } else @@ -558,16 +578,16 @@ dbt_parse_gda_op (Dbt *dbt, xmlNodePtr xnode) error = NULL; if (!gda_server_operation_load_data_from_xml (op, cur, &error)) { - g_warning ("Unable to load GdaServerOperation from the file.\n%s\n", - error && error->message ? error->message : "No detail"); + g_warning ("Unable to load GdaServerOperation from the file: %s.\n", + error != NULL && error->message != NULL ? error->message : "no detail"); ret = FALSE; } else { if (!gda_server_provider_perform_operation (provider, priv->gda_conn, op, &error)) { - g_warning ("Error on executing GdaServerOperation from the file.\n%s\n", - error && error->message ? error->message : "No detail"); + g_warning ("Error on executing GdaServerOperation from the file: %s.\n", + error != NULL && error->message != NULL ? error->message : "no detail"); ret = FALSE; } } @@ -576,7 +596,7 @@ dbt_parse_gda_op (Dbt *dbt, xmlNodePtr xnode) } else { - g_warning ("Operation type \"%s\" not supported by the provider.\n", str_operation_type); + g_warning ("Operation type \"%s\" not supported by the provider.", str_operation_type); ret = FALSE; } @@ -586,6 +606,79 @@ dbt_parse_gda_op (Dbt *dbt, xmlNodePtr xnode) return ret; } +static gboolean +dbt_parse_drop_table (Dbt *dbt, xmlNodePtr xnode) +{ + DbtPrivate *priv; + + gboolean ret; + + xmlNodePtr cur; + gchar *table_name; + + GError *error; + + ret = TRUE; + + priv = DBT_GET_PRIVATE (dbt); + + table_name = NULL; + cur = xnode->children; + while (cur != NULL && ret) + { + if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0) + { + table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur))); + } + + cur = cur->next; + } + + if (table_name != NULL && g_strcmp0 (table_name, "") != 0) + { + gchar *sql; + GdaStatement *stmt; + + sql = g_strdup_printf ("DROP TABLE %s", table_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 table."); + ret = FALSE; + } + + return ret; +} + +/** + * dbt_transform: + * @dbt: + * + */ void dbt_transform (Dbt *dbt) { @@ -636,8 +729,8 @@ dbt_transform (Dbt *dbt) 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"); + g_warning ("Unable to start the transaction: %s.\n", + error != NULL && error->message != NULL ? error->message : "no detail"); continue; } } @@ -655,9 +748,13 @@ dbt_transform (Dbt *dbt) { tosave = dbt_parse_gda_op (dbt, xnode); } + else if (xmlStrcmp (xnode->name, (const xmlChar *)"drop_table") == 0) + { + tosave = dbt_parse_drop_table (dbt, xnode); + } else { - g_warning ("Invalid tag: %s", xnode->name); + g_warning ("Invalid tag: %s.", xnode->name); tosave = FALSE; } } diff --git a/tests/test.db b/tests/test.db index a9fddd1..71d519c 100644 Binary files a/tests/test.db and b/tests/test.db differ diff --git a/tests/test.xml b/tests/test.xml index cd4b0f1..a406bd6 100644 --- a/tests/test.xml +++ b/tests/test.xml @@ -2,6 +2,18 @@ + + clients + + + orders + + + newtable + + + +