]> saetta.ns0.it Git - libzakdbt/commitdiff
Implemented Dbt::parse_gda_op.
authorAndrea Zagli <azagli@libero.it>
Fri, 2 Jul 2010 15:41:00 +0000 (17:41 +0200)
committerAndrea Zagli <azagli@libero.it>
Fri, 2 Jul 2010 15:41:00 +0000 (17:41 +0200)
.gitignore
src/dbtransformer.c
tests/test.db
tests/test.xml

index bb9762b1977c81a15895bf44fc812bfd49633e9f..d4cf8a5da6adefc6984a987b99cff108a1138065 100644 (file)
@@ -49,3 +49,4 @@ Rules-quot
 *.exe
 .cproject
 .project
+.settings
index afe2c943a77c1bddbc96e12ef9e0fb8319248ae5..94f758cdc680438ac43af1ece208e7dfaa3dd015 100644 (file)
@@ -304,6 +304,13 @@ dbt_check_db (Dbt *dbt)
                                        gda_server_operation_set_value_at (op, "operation", &error, "/FIELDS_A/@COLUMN_NAME/%d", i);
                                        gda_server_operation_set_value_at (op, "text", &error, "/FIELDS_A/@COLUMN_TYPE/%d", i);
 
+                                       /*
+                                       xmlNodePtr xnode2 = gda_server_operation_save_data_to_xml (op, &error);
+                                       xmlDocPtr xdoc2 = xmlNewDoc ("1.0");
+                                       xmlDocSetRootElement (xdoc2, xnode2);
+                                       xmlSaveFormatFile("-",xdoc2,2);
+                                       */
+
                                        /* execute the operation */
                                        if (!gda_server_provider_perform_operation (provider, priv->gda_conn, op, &error))
                                                {
@@ -467,6 +474,118 @@ dbt_parse_sql (Dbt *dbt, xmlNodePtr xnode)
        return ret;
 }
 
+static gboolean
+dbt_parse_gda_op (Dbt *dbt, xmlNodePtr xnode)
+{
+       DbtPrivate *priv;
+
+       gboolean ret;
+
+       xmlNodePtr cur;
+
+       gchar *str_operation_type;
+       GdaServerOperationType operation_type;
+       GdaServerProvider *provider;
+       GError *error;
+       GdaServerOperation *op;
+
+       ret = TRUE;
+
+       priv = DBT_GET_PRIVATE (dbt);
+
+       cur = xnode->children;
+       while (cur != NULL && ret)
+               {
+                       if (xmlNodeIsText (cur))
+                               {
+                                       cur = cur->next;
+                                       continue;
+                               }
+
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"serv_op_data") != 0)
+                               {
+                                       g_warning ("Invalid tag \"%s\".\n", cur->name);
+                                       ret = FALSE;
+                                       cur = cur->next;
+                                       continue;
+                               }
+
+                       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)
+                               {
+                                       g_warning ("Operation type \"%s\" not supported.\n%s\n", str_operation_type,
+                                                          error && error->message ? error->message : "No detail");
+                                       return FALSE;
+                               }
+
+                       provider = gda_connection_get_provider (priv->gda_conn);
+                       if (gda_server_provider_supports_operation (provider, priv->gda_conn, operation_type, NULL))
+                               {
+                                       error = NULL;
+                                       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");
+                                                       ret = FALSE;
+                                               }
+                                       else
+                                               {
+                                                       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");
+                                                                       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");
+                                                                                       ret = FALSE;
+                                                                               }
+                                                               }
+                                                       g_object_unref (op);
+                                               }
+                               }
+                       else
+                               {
+                                       g_warning ("Operation type \"%s\" not supported by the provider.\n", str_operation_type);
+                                       ret = FALSE;
+                               }
+
+                       cur = cur->next;
+               }
+
+       return ret;
+}
+
 void
 dbt_transform (Dbt *dbt)
 {
@@ -532,10 +651,10 @@ dbt_transform (Dbt *dbt)
                                                                                                {
                                                                                                        tosave = dbt_parse_sql (dbt, xnode);
                                                                                                }
-                                                                                       /*else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0)
+                                                                                       else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0)
                                                                                                {
                                                                                                        tosave = dbt_parse_gda_op (dbt, xnode);
-                                                                                               }*/
+                                                                                               }
                                                                                        else
                                                                                                {
                                                                                                        g_warning ("Invalid tag: %s", xnode->name);
index a8d2e0623528daa422ee491817b71f1c9d38584b..a9fddd1624212b486cf7307dff87f6dfbdd69a05 100644 (file)
Binary files a/tests/test.db and b/tests/test.db differ
index 7411538eb415620c98efce42e2f4b0748e7788eb..cd4b0f168be0e355cba115839fc9a6571f366452 100644 (file)
                </sql>
        </dbtransformation>
 
+       <dbtransformation id="3">
+               <gda_op>
+                       <serv_op_data type="CREATE_TABLE">
+                               <op_data path="/TABLE_DEF_P/TABLE_NAME">newtable</op_data>
+                               <op_data path="/TABLE_DEF_P/TABLE_TEMP">FALSE</op_data>
+                               <op_data path="/TABLE_DEF_P/TABLE_IFNOTEXISTS">FALSE</op_data>
+                               <op_data path="/FIELDS_A">
+                                       <gda_array_data>
+                                               <gda_array_row>
+                                                       <gda_array_value colid="COLUMN_NAME">id</gda_array_value>
+                                                       <gda_array_value colid="COLUMN_TYPE">integer</gda_array_value>
+                                                       <gda_array_value colid="COLUMN_SIZE" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_SCALE" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_NNUL" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_AUTOINC" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_UNIQUE" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_PKEY">TRUE</gda_array_value>
+                                                       <gda_array_value colid="COLUMN_DEFAULT" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_CHECK" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_COLLATE" isnull="t"/>
+                                                       <gda_array_value colid="COLUMN_CONFLICT" isnull="t"/>
+                                               </gda_array_row>
+                                       </gda_array_data>
+                               </op_data>
+                       </serv_op_data>
+               </gda_op>
+       </dbtransformation>
+
 </dbtransformer>