]> saetta.ns0.it Git - libgdaex/commitdiff
On GdaExQueryEditor added join_type to relation.
authorAndrea Zagli <azagli@libero.it>
Sat, 22 Oct 2011 13:07:52 +0000 (15:07 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 22 Oct 2011 13:07:52 +0000 (15:07 +0200)
src/queryeditor.c
src/queryeditor.h
tests/query_editor.c

index f2f63a712b1e2a64b7ca6f5d245a31b77676dd4c..3432c1216022a61a0493aa6cfbd58324dcbcffbd 100644 (file)
@@ -40,6 +40,8 @@ typedef struct
                GdaExQueryEditorTable *table1;
                GdaExQueryEditorTable *table2;
 
+               GdaExQueryEditorJoinType join_type;
+
                GSList *fields1;
                GSList *fields2;
        } GdaExQueryEditorRelation;
@@ -595,6 +597,7 @@ gboolean
 gdaex_query_editor_add_relation (GdaExQueryEditor *qe,
                                  const gchar *table1,
                                  const gchar *table2,
+                                 GdaExQueryEditorJoinType join_type,
                                  ...)
 {
        GdaExQueryEditorPrivate *priv;
@@ -636,7 +639,7 @@ gdaex_query_editor_add_relation (GdaExQueryEditor *qe,
                }
        relation->table2 = table;
 
-       va_start (fields, table2);
+       va_start (fields, join_type);
 
        while ((field_name1 = va_arg (fields, gchar *)) != NULL
               && (field_name2 = va_arg (fields, gchar *)) != NULL)
@@ -662,6 +665,7 @@ gdaex_query_editor_add_relation (GdaExQueryEditor *qe,
 
        if (create_relation)
                {
+                       relation->join_type = join_type;
                        priv->relations = g_slist_append (priv->relations, relation);
                }
        else
@@ -773,6 +777,7 @@ GdaSqlBuilder
 
        sqlbuilder = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
 
+       /* SHOW */
        if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->lstore_show), &iter))
                {
                        guint id_target1;
@@ -825,6 +830,7 @@ GdaSqlBuilder
                                } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->lstore_show), &iter));
                }
 
+       /* WHERE */
        if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->tstore_where), &iter))
                {
                        guint link_type;
@@ -921,7 +927,7 @@ GdaSqlBuilder
                                        field = g_hash_table_lookup (table->fields, field_name);
 
                                        id_field = gda_sql_builder_add_id (sqlbuilder,
-                                                                          g_strconcat (case_insensitive ? "lower(" : "",
+                                                                          g_strconcat (case_insensitive ? "LOWER(" : "",
                                                                                        table->name, ".", field->name,
                                                                                        case_insensitive ? ")" : "",
                                                                                        NULL));
@@ -1064,6 +1070,7 @@ GdaSqlBuilder
                                }
                }
 
+       /* ORDER */
        if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->lstore_order), &iter))
                {
                        do
index 89e8306cee1e24dd067257dd8e9c5064894182d5..e2c9c09a6b6f8c1a3c0a8d5d105e0724cdb0de3c 100644 (file)
@@ -142,6 +142,7 @@ gboolean gdaex_query_editor_table_add_field (GdaExQueryEditor *qe,
 gboolean gdaex_query_editor_add_relation (GdaExQueryEditor *qe,
                                           const gchar *table1,
                                           const gchar *table2,
+                                          GdaExQueryEditorJoinType join_type,
                                           ...);
 
 void gdaex_query_editor_clean_choices (GdaExQueryEditor *qe);
index a05a925ccf761792c94e1ef5d254901c6a08d430..86fbfd75b3293068851a8f5ccf69cf580a41a8ca 100644 (file)
@@ -275,6 +275,22 @@ main (int argc, char *argv[])
        gdaex_query_editor_table_add_field (qe, "orders", *field);
        g_free (field);
 
+       gdaex_query_editor_add_relation (qe,
+                                        "clients", "orders",
+                                        GDAEX_QE_JOIN_TYPE_LEFT,
+                                        "id", "id_clients",
+                                        NULL);
+
+       field = g_new0 (GdaExQueryEditorField, 1);
+       field->name = g_strdup ("amount");
+       field->name_visible = g_strdup ("Amount");
+       field->type = GDAEX_QE_FIELD_TYPE_DOUBLE;
+       field->for_show = TRUE;
+       field->for_where = TRUE;
+       field->available_where_type = GDAEX_QE_WHERE_TYPE_NUMBER;
+       gdaex_query_editor_table_add_field (qe, "orders", *field);
+       g_free (field);
+
        w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_default_size (GTK_WINDOW (w), 610, 400);
        gtk_window_set_modal (GTK_WINDOW (w), TRUE);