]> saetta.ns0.it Git - libgdaex/commitdiff
Implemented ILIKE where type.
authorAndrea Zagli <azagli@libero.it>
Sun, 8 May 2011 09:33:44 +0000 (11:33 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 8 May 2011 09:33:44 +0000 (11:33 +0200)
src/queryeditor.c
src/queryeditor.h
tests/query_editor.c

index 44eaeaa79def039e36fb8aa1168c3d6dcbfe23de..a1433715b82c6a8482df47af19425adc329214db 100644 (file)
@@ -599,7 +599,21 @@ const gchar
                                                {
                                                        from_str = g_strdup ("");
                                                }
-                                       if (to_str == NULL || g_strcmp0 (g_strstrip (to_str), "") == 0)
+                                       else
+                                               {
+                                                       if (where_type == GDAEX_QE_WHERE_TYPE_ILIKE)
+                                                               {
+                                                                       from_str = g_utf8_strdown (from_str, -1);
+                                                               }
+                                               }
+                                       if (to_str != NULL && g_strcmp0 (g_strstrip (to_str), "") != 0)
+                                               {
+                                                       if (where_type == GDAEX_QE_WHERE_TYPE_ILIKE)
+                                                               {
+                                                                       to_str = g_utf8_strdown (to_str, -1);
+                                                               }
+                                               }
+                                       else
                                                {
                                                        to_str = NULL;
                                                }
@@ -607,7 +621,11 @@ const gchar
                                        table = g_hash_table_lookup (priv->tables, table_name);
                                        field = g_hash_table_lookup (table->fields, field_name);
 
-                                       id_field = gda_sql_builder_add_id (sqlbuilder, g_strconcat (table->name, ".", field->name, NULL));
+                                       id_field = gda_sql_builder_add_id (sqlbuilder,
+                                                                          g_strconcat (where_type == GDAEX_QE_WHERE_TYPE_ILIKE ? "lower(" : "",
+                                                                                       table->name, ".", field->name,
+                                                                                       where_type == GDAEX_QE_WHERE_TYPE_ILIKE ? ")" : "",
+                                                                                       NULL));
 
                                        switch (field->type)
                                                {
@@ -647,6 +665,11 @@ const gchar
                                                                type = G_TYPE_DATE_TIME;
                                                                /* TODO */
                                                                break;
+
+                                                       case GDAEX_QE_FIELD_TYPE_TIME:
+                                                               type = G_TYPE_DATE_TIME;
+                                                               /* TODO */
+                                                               break;
                                                };
 
                                        switch (where_type)
@@ -656,12 +679,7 @@ const gchar
                                                                break;
 
                                                        case GDAEX_QE_WHERE_TYPE_LIKE:
-                                                               /* TODO */
-                                                               op = GDA_SQL_OPERATOR_TYPE_LIKE;
-                                                               break;
-
                                                        case GDAEX_QE_WHERE_TYPE_ILIKE:
-                                                               /* TODO */
                                                                op = GDA_SQL_OPERATOR_TYPE_LIKE;
                                                                break;
 
@@ -1434,7 +1452,7 @@ gdaex_query_editor_get_where_type_str_from_type (guint where_type)
                                break;
 
                        case GDAEX_QE_WHERE_TYPE_ILIKE:
-                               ret = g_strdup ("Non case sensitive like");
+                               ret = g_strdup ("Case-insensitive like");
                                break;
 
                        case GDAEX_QE_WHERE_TYPE_GREAT:
@@ -1654,7 +1672,7 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
                                                        }
                                                else
                                                        {
-                                                               g_strstrip (val1);
+                                                               val1 = g_strstrip (g_strdup (val1));
                                                        }
                                                gtk_list_store_set (priv->lstore_show, &iter,
                                                                    COL_SHOW_ALIAS, val1,
@@ -1694,7 +1712,7 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
                                                        }
                                                else
                                                        {
-                                                               g_strstrip (val1);
+                                                               val1 = g_strstrip (g_strdup (val1));
                                                        }
 
                                                val2 = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt2));
@@ -2086,9 +2104,6 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection,
                        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cb_where_type), renderer, TRUE);
                        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->cb_where_type), renderer, "text", 1);
 
-                       g_signal_connect (G_OBJECT (priv->cb_where_type), "changed",
-                                         G_CALLBACK (gdaex_query_editor_on_cb_where_type_changed), user_data);
-
                        gtk_list_store_clear (priv->lstore_where_type);
                        if (field->available_where_type & GDAEX_QE_WHERE_TYPE_EQUAL)
                                {
@@ -2246,6 +2261,17 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection,
                                                gtk_table_attach (GTK_TABLE (tbl), priv->txt2, 5, 6, 1, 2, 0, 0, 0, 0);
                                                break;
 
+                                       case GDAEX_QE_FIELD_TYPE_TIME:
+                                               priv->txt1 = gtk_entry_new ();
+                                               gtk_entry_set_max_length (GTK_ENTRY (priv->txt1), 19);
+                                               gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from);
+                                               gtk_table_attach (GTK_TABLE (tbl), priv->txt1, 3, 4, 1, 2, 0, 0, 0, 0);
+
+                                               priv->txt2 = gtk_entry_new ();
+                                               gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to);
+                                               gtk_table_attach (GTK_TABLE (tbl), priv->txt2, 5, 6, 1, 2, 0, 0, 0, 0);
+                                               break;
+
                                        default:
                                                g_warning ("Field's type «%d» not valid.", field->type);
                                                break;
@@ -2256,10 +2282,11 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection,
                        gtk_widget_show_all (priv->vbx_values);
                        gtk_widget_show (priv->vbx_values_container);
 
-                       gtk_widget_set_visible (priv->txt2, FALSE);
-
                        gtk_widget_set_visible (priv->lbl_txt2, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN);
                        gtk_widget_set_visible (priv->txt2, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN);
+
+                       g_signal_connect (G_OBJECT (priv->cb_where_type), "changed",
+                                         G_CALLBACK (gdaex_query_editor_on_cb_where_type_changed), user_data);
                }
 }
 
index 17409d7342301a012fd62e1221116844f2c78262..6638020200b953c8c22a0a24ac9a014fd14dd2c2 100644 (file)
@@ -63,7 +63,8 @@ typedef enum
                GDAEX_QE_FIELD_TYPE_INTEGER,
                GDAEX_QE_FIELD_TYPE_DOUBLE,
                GDAEX_QE_FIELD_TYPE_DATE,
-               GDAEX_QE_FIELD_TYPE_DATETIME
+               GDAEX_QE_FIELD_TYPE_DATETIME,
+               GDAEX_QE_FIELD_TYPE_TIME,
        } GdaExQueryEditorFieldType;
 
 typedef enum
index 9631a009e347f0a39b35d5037cc03e54df8226e7..81c12c938120308d4d3461f184ffef6d555bb767 100644 (file)
@@ -95,13 +95,18 @@ on_btn_get_sql_clicked (GtkButton *button,
        xmlDoc *doc;
        xmlNode *node;
        xmlChar *buf;
+
+       gchar *sql;
+
        gint size;
 
+       sql = (gchar *)gdaex_query_editor_get_sql ((GdaExQueryEditor *)user_data);
+       sql = g_strjoinv ("%%", g_strsplit (sql, "%", -1));
        GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (w),
                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                                    GTK_MESSAGE_INFO,
                                                    GTK_BUTTONS_OK,
-                                                   gdaex_query_editor_get_sql ((GdaExQueryEditor *)user_data));
+                                                   sql);
        gtk_dialog_run (GTK_DIALOG (dialog));
        gtk_widget_destroy (dialog);;
 
@@ -109,6 +114,7 @@ on_btn_get_sql_clicked (GtkButton *button,
        node = gdaex_query_editor_get_sql_as_xml ((GdaExQueryEditor *)user_data);
        xmlDocSetRootElement (doc, node);
        xmlDocDumpMemory (doc, &buf, &size);
+       buf = g_strjoinv ("%%", g_strsplit (buf, "%", -1));
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (w),
                                                    GTK_DIALOG_DESTROY_WITH_PARENT,