]> saetta.ns0.it Git - libgdaex/commitdiff
Added function GdaExQueryEditor::get_sql_as_xml.
authorAndrea Zagli <azagli@libero.it>
Sat, 5 Mar 2011 15:04:14 +0000 (16:04 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 5 Mar 2011 15:04:14 +0000 (16:04 +0100)
src/queryeditor.c
src/queryeditor.h
tests/query_editor.c

index a00b525e5e28b3c288b554ef2a84c1fa61589e0a..d5ba5d3130ae81a423e426429f54988c45ca2929 100644 (file)
@@ -722,6 +722,151 @@ const gchar
        return ret;
 }
 
+xmlNode
+*gdaex_query_editor_get_sql_as_xml (GdaExQueryEditor *qe)
+{
+       GdaExQueryEditorPrivate *priv;
+
+       xmlNode *ret;
+
+       GtkTreeIter iter;
+
+       gchar *table_name;
+       gchar *field_name;
+
+       xmlNode *node;
+
+       ret = NULL;
+
+       g_return_val_if_fail (GDAEX_IS_QUERY_EDITOR (qe), NULL);
+
+       priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
+
+       ret = xmlNewNode (NULL, "gdaex_query_editor_choices");
+
+       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->lstore_show), &iter))
+               {
+                       xmlNode *node_show;
+
+                       node_show = xmlNewNode (NULL, "show");
+                       xmlAddChild (ret, node_show);
+
+                       do
+                               {
+                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_show), &iter,
+                                                           COL_SHOW_TABLE_NAME, &table_name,
+                                                           COL_SHOW_NAME, &field_name,
+                                                           -1);
+
+                                       node = xmlNewNode (NULL, "field");
+                                       xmlAddChild (node_show, node);
+                                       xmlNewProp (node, "table", table_name);
+                                       xmlNewProp (node, "field", field_name);
+                               } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->lstore_show), &iter));
+               }
+
+       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->tstore_where), &iter))
+               {
+                       xmlNode *node_where;
+
+                       gboolean not;
+                       guint where_type;
+                       gchar *from_str;
+                       gchar *to_str;
+                       gchar *str_op;
+
+                       node_where = xmlNewNode (NULL, "where");
+                       xmlAddChild (ret, node_where);
+
+                       do
+                               {
+                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_where), &iter,
+                                                           COL_WHERE_TABLE_NAME, &table_name,
+                                                           COL_WHERE_NAME, &field_name,
+                                                           COL_WHERE_CONDITION_NOT, &not,
+                                                           COL_WHERE_CONDITION_TYPE, &where_type,
+                                                           COL_WHERE_CONDITION_FROM, &from_str,
+                                                           COL_WHERE_CONDITION_TO, &to_str,
+                                                           -1);
+
+                                       node = xmlNewNode (NULL, "field");
+                                       xmlAddChild (node_where, node);
+                                       xmlNewProp (node, "table", table_name);
+                                       xmlNewProp (node, "field", field_name);
+                                       xmlNewProp (node, "not", (not ? "y" : "n"));
+
+                                       switch (where_type)
+                                               {
+                                                       case GDAEX_QE_WHERE_TYPE_EQUAL:
+                                                               str_op = g_strdup ("EQUAL");
+                                                               break;
+
+                                                       case GDAEX_QE_WHERE_TYPE_LIKE:
+                                                               str_op = g_strdup ("LIKE");
+                                                               break;
+
+                                                       case GDAEX_QE_WHERE_TYPE_ILIKE:
+                                                               str_op = g_strdup ("ILIKE");
+                                                               break;
+
+                                                       case GDAEX_QE_WHERE_TYPE_GREAT:
+                                                               str_op = g_strdup ("GREAT");
+                                                               break;
+
+                                                       case GDAEX_QE_WHERE_TYPE_GREAT_EQUAL:
+                                                               str_op = g_strdup ("GREAT_EQUAL");
+                                                               break;
+
+                                                       case GDAEX_QE_WHERE_TYPE_LESS:
+                                                               str_op = g_strdup ("LESS");
+                                                               break;
+
+                                                       case GDAEX_QE_WHERE_TYPE_LESS_EQUAL:
+                                                               str_op = g_strdup ("LESS_EQUAL");
+                                                               break;
+
+                                                       case GDAEX_QE_WHERE_TYPE_BETWEEN:
+                                                               str_op = g_strdup ("BETWEEN");
+                                                               break;
+
+                                                       default:
+                                                               g_warning ("Where type «%d» not valid.", where_type);
+                                                               continue;
+                                               }
+                                       xmlNewProp (node, "where_type", str_op);
+
+                                       xmlNewProp (node, "from", from_str);
+                                       xmlNewProp (node, "to", to_str);
+                               } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->tstore_where), &iter));
+               }
+
+       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->lstore_order), &iter))
+               {
+                       gchar *asc_desc;
+                       xmlNode *node_order;
+
+                       node_order = xmlNewNode (NULL, "order");
+                       xmlAddChild (ret, node_order);
+
+                       do
+                               {
+                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_order), &iter,
+                                                           COL_ORDER_TABLE_NAME, &table_name,
+                                                           COL_ORDER_NAME, &field_name,
+                                                           COL_ORDER_ORDER, &asc_desc,
+                                                           -1);
+
+                                       node = xmlNewNode (NULL, "field");
+                                       xmlAddChild (node_order, node);
+                                       xmlNewProp (node, "table", table_name);
+                                       xmlNewProp (node, "field", field_name);
+                                       xmlNewProp (node, "asc_desc", asc_desc);
+                               } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->lstore_order), &iter));
+               }
+
+       return ret;
+}
+
 /* PRIVATE */
 static void
 gdaex_query_editor_set_property (GObject *object,
index 74eeb4cb1dc1c7bd50a034f5883cde3ff2b52c22..9193ce19413b055956c8a66b1d0774851c26e320 100644 (file)
@@ -87,16 +87,10 @@ typedef struct
                gchar *name_visible;
                gchar *description;
                gchar *alias;
-               /* - tipo di campo (string, integer, double, date, datetime) */
                GdaExQueryEditorFieldType type;
-               /* - sceglibile per la parte show (es. le chiavi esterne non ha senno che lo siano) */
                gboolean for_show;
-               /* - sempre presente nelle query, quindi non sceglibile per la parte show */
                gboolean always_showed;
-               /* - sceglibile per la parte where */
                gboolean for_where;
-               /* - condizioni where che è possibile applicare (es. i campi id_* non ha senso che abbiano un between, */
-               /*                                             ma ci deve essere la possibilità di fare ricerche anche sulle decodifiche) */
                guint available_where_type;
                gchar *decode_table2;
                /* TODO 
@@ -122,6 +116,8 @@ gboolean gdaex_query_editor_add_relation (GdaExQueryEditor *qe,
 
 const gchar *gdaex_query_editor_get_sql (GdaExQueryEditor *qe);
 
+xmlNode *gdaex_query_editor_get_sql_as_xml (GdaExQueryEditor *qe);
+
 
 G_END_DECLS
 
index 0a3dd0e0280c7848d0ef8af3c3c4b34388f27bc4..c709babec59d05a83dbcc1b49411d29b2b170ba7 100644 (file)
@@ -129,5 +129,16 @@ main (int argc, char *argv[])
 
        g_message (gdaex_query_editor_get_sql (qe));
 
+       xmlDoc *doc;
+       xmlNode *node;
+       xmlChar *buf;
+       gint size;
+
+       doc = xmlNewDoc ("1.0");
+       node = gdaex_query_editor_get_sql_as_xml (qe);
+       xmlDocSetRootElement (doc, node);
+       xmlDocDumpMemory (doc, &buf, &size);
+       g_message (buf);
+
        return 0;
 }