]> saetta.ns0.it Git - libgdaex/commitdiff
Added functions GdaExQueryEditor::get_sql_select, get_sql_from, get_sql_where and...
authorAndrea Zagli <azagli@libero.it>
Sat, 22 Oct 2011 13:37:04 +0000 (15:37 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 22 Oct 2011 13:37:04 +0000 (15:37 +0200)
src/queryeditor.c
src/queryeditor.h
tests/query_editor.c

index 3432c1216022a61a0493aa6cfbd58324dcbcffbd..eb4de7d20741123d5381fa25447e5483daa9352e 100644 (file)
@@ -1141,6 +1141,132 @@ const gchar
        return ret;
 }
 
+const gchar
+*gdaex_query_editor_get_sql_select (GdaExQueryEditor *qe)
+{
+       gchar *ret;
+       const gchar *sql;
+
+       gchar *start;
+       gchar *end;
+
+       ret = NULL;
+
+       sql = gdaex_query_editor_get_sql (qe);
+       if (sql == NULL)
+               {
+                       return ret;
+               }
+
+       start = g_strstr_len (sql, -1, "SELECT");
+       if (start == NULL)
+               {
+                       return ret;
+               }
+
+       end = g_strstr_len (sql, -1, "FROM");
+       if (end == NULL)
+               {
+                       return ret;
+               }
+
+       ret = g_strndup (start + 7, strlen (sql) - 8 - strlen (end));
+
+       return ret;
+}
+
+const gchar
+*gdaex_query_editor_get_sql_from (GdaExQueryEditor *qe)
+{
+       gchar *ret;
+       const gchar *sql;
+
+       gchar *start;
+       gchar *end;
+
+       ret = NULL;
+
+       sql = gdaex_query_editor_get_sql (qe);
+       if (sql == NULL)
+               {
+                       return ret;
+               }
+
+       start = g_strstr_len (sql, -1, "FROM");
+       if (start == NULL)
+               {
+                       return ret;
+               }
+
+       end = g_strstr_len (sql, -1, "WHERE");
+       if (end == NULL)
+               {
+                       end = g_strstr_len (sql, -1, "ORDER BY");
+               }
+
+       ret = g_strndup (start + 5, strlen (start) - (end != NULL ? 6 : 5) - (end != NULL ? strlen (end) : 0));
+
+       return ret;
+}
+
+const gchar
+*gdaex_query_editor_get_sql_where (GdaExQueryEditor *qe)
+{
+       gchar *ret;
+       const gchar *sql;
+
+       gchar *start;
+       gchar *end;
+
+       ret = NULL;
+
+       sql = gdaex_query_editor_get_sql (qe);
+       if (sql == NULL)
+               {
+                       return ret;
+               }
+
+       start = g_strstr_len (sql, -1, "WHERE");
+       if (start == NULL)
+               {
+                       return ret;
+               }
+
+       end = g_strstr_len (sql, -1, "ORDER BY");
+
+       ret = g_strndup (start + 6, strlen (start) - (end != NULL ? 7 : 6) - (end != NULL ? strlen (end) : 0));
+
+       return ret;
+}
+
+const gchar
+*gdaex_query_editor_get_sql_order (GdaExQueryEditor *qe)
+{
+       gchar *ret;
+       const gchar *sql;
+
+       gchar *start;
+
+       ret = NULL;
+
+       sql = gdaex_query_editor_get_sql (qe);
+       if (sql == NULL)
+               {
+                       return ret;
+               }
+
+       start = g_strstr_len (sql, -1, "ORDER BY");
+       if (start == NULL)
+               {
+                       return ret;
+               }
+
+       ret = g_strndup (start + 9, strlen (start) - 9);
+
+       return ret;
+}
+
+
 xmlNode
 *gdaex_query_editor_get_sql_as_xml (GdaExQueryEditor *qe)
 {
index e2c9c09a6b6f8c1a3c0a8d5d105e0724cdb0de3c..a86f9c1e216e00edc34e3086d278837f2ab2e4b2 100644 (file)
@@ -150,6 +150,10 @@ void gdaex_query_editor_clean_choices (GdaExQueryEditor *qe);
 GdaSqlBuilder *gdaex_query_editor_get_sql_as_gdasqlbuilder (GdaExQueryEditor *qe);
 
 const gchar *gdaex_query_editor_get_sql (GdaExQueryEditor *qe);
+const gchar *gdaex_query_editor_get_sql_select (GdaExQueryEditor *qe);
+const gchar *gdaex_query_editor_get_sql_from (GdaExQueryEditor *qe);
+const gchar *gdaex_query_editor_get_sql_where (GdaExQueryEditor *qe);
+const gchar *gdaex_query_editor_get_sql_order (GdaExQueryEditor *qe);
 
 xmlNode *gdaex_query_editor_get_sql_as_xml (GdaExQueryEditor *qe);
 
index 86fbfd75b3293068851a8f5ccf69cf580a41a8ca..6b90baa45d3ab77b8762b0decb5ed8fdc05e876c 100644 (file)
@@ -100,6 +100,7 @@ on_btn_get_sql_clicked (GtkButton *button,
 
        gint size;
 
+       /* SQL */
        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),
@@ -108,8 +109,57 @@ on_btn_get_sql_clicked (GtkButton *button,
                                                    GTK_BUTTONS_OK,
                                                    sql);
        gtk_dialog_run (GTK_DIALOG (dialog));
-       gtk_widget_destroy (dialog);;
+       gtk_widget_destroy (dialog);
+
+       /* SQL SELECT */
+       sql = (gchar *)gdaex_query_editor_get_sql_select ((GdaExQueryEditor *)user_data);
+       sql = g_strjoinv ("%%", g_strsplit (sql, "%", -1));
+       dialog = gtk_message_dialog_new (GTK_WINDOW (w),
+                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        GTK_MESSAGE_INFO,
+                                        GTK_BUTTONS_OK,
+                                        sql);
+       gtk_dialog_run (GTK_DIALOG (dialog));
+       gtk_widget_destroy (dialog);
+       g_free (sql);
+
+       /* SQL FROM */
+       sql = (gchar *)gdaex_query_editor_get_sql_from ((GdaExQueryEditor *)user_data);
+       sql = g_strjoinv ("%%", g_strsplit (sql, "%", -1));
+       dialog = gtk_message_dialog_new (GTK_WINDOW (w),
+                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        GTK_MESSAGE_INFO,
+                                        GTK_BUTTONS_OK,
+                                        sql);
+       gtk_dialog_run (GTK_DIALOG (dialog));
+       gtk_widget_destroy (dialog);
+       g_free (sql);
 
+       /* SQL WHERE */
+       sql = (gchar *)gdaex_query_editor_get_sql_where ((GdaExQueryEditor *)user_data);
+       sql = g_strjoinv ("%%", g_strsplit (sql, "%", -1));
+       dialog = gtk_message_dialog_new (GTK_WINDOW (w),
+                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        GTK_MESSAGE_INFO,
+                                        GTK_BUTTONS_OK,
+                                        sql);
+       gtk_dialog_run (GTK_DIALOG (dialog));
+       gtk_widget_destroy (dialog);
+       g_free (sql);
+
+       /* SQL ORDER */
+       sql = (gchar *)gdaex_query_editor_get_sql_order ((GdaExQueryEditor *)user_data);
+       sql = g_strjoinv ("%%", g_strsplit (sql, "%", -1));
+       dialog = gtk_message_dialog_new (GTK_WINDOW (w),
+                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        GTK_MESSAGE_INFO,
+                                        GTK_BUTTONS_OK,
+                                        sql);
+       gtk_dialog_run (GTK_DIALOG (dialog));
+       gtk_widget_destroy (dialog);
+       g_free (sql);
+
+       /* XML */
        doc = xmlNewDoc ("1.0");
        node = gdaex_query_editor_get_sql_as_xml ((GdaExQueryEditor *)user_data);
        xmlDocSetRootElement (doc, node);
@@ -122,7 +172,7 @@ on_btn_get_sql_clicked (GtkButton *button,
                                         GTK_BUTTONS_OK,
                                         buf);
        gtk_dialog_run (GTK_DIALOG (dialog));
-       gtk_widget_destroy (dialog);;
+       gtk_widget_destroy (dialog);
 }
 
 int
@@ -186,6 +236,7 @@ main (int argc, char *argv[])
        field->type = GDAEX_QE_FIELD_TYPE_TEXT;
        field->for_show = TRUE;
        field->for_where = TRUE;
+       field->for_order = TRUE;
        field->available_where_type = GDAEX_QE_WHERE_TYPE_STARTS
                                      | GDAEX_QE_WHERE_TYPE_CONTAINS
                                      | GDAEX_QE_WHERE_TYPE_ENDS
@@ -202,6 +253,7 @@ main (int argc, char *argv[])
        field->type = GDAEX_QE_FIELD_TYPE_TEXT;
        field->for_show = TRUE;
        field->for_where = TRUE;
+       field->for_order = TRUE;
        field->available_where_type = GDAEX_QE_WHERE_TYPE_STRING
                                      | GDAEX_QE_WHERE_TYPE_IS_NULL;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
@@ -214,6 +266,7 @@ main (int argc, char *argv[])
        field->type = GDAEX_QE_FIELD_TYPE_DATE;
        field->for_show = TRUE;
        field->for_where = TRUE;
+       field->for_order = TRUE;
        field->available_where_type = GDAEX_QE_WHERE_TYPE_DATETIME
                                      | GDAEX_QE_WHERE_TYPE_IS_NULL;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
@@ -227,6 +280,7 @@ main (int argc, char *argv[])
        field->type = GDAEX_QE_FIELD_TYPE_INTEGER;
        field->for_show = TRUE;
        field->for_where = TRUE;
+       field->for_order = TRUE;
        field->available_where_type = GDAEX_QE_WHERE_TYPE_NUMBER;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
        g_free (field);
@@ -238,6 +292,7 @@ main (int argc, char *argv[])
        field->type = GDAEX_QE_FIELD_TYPE_DATETIME;
        field->for_show = TRUE;
        field->for_where = TRUE;
+       field->for_order = TRUE;
        field->available_where_type = GDAEX_QE_WHERE_TYPE_DATETIME
                                      | GDAEX_QE_WHERE_TYPE_IS_NULL;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
@@ -250,6 +305,7 @@ main (int argc, char *argv[])
        field->type = GDAEX_QE_FIELD_TYPE_INTEGER;
        field->for_show = TRUE;
        field->for_where = TRUE;
+       field->for_order = TRUE;
        field->decode_table2 = g_strdup ("cities");
        field->decode_join_type = GDAEX_QE_JOIN_TYPE_LEFT;
        /*field->decode_fields1 = g_slist_append (field->decode_fields1, "id_cities");
@@ -287,6 +343,7 @@ main (int argc, char *argv[])
        field->type = GDAEX_QE_FIELD_TYPE_DOUBLE;
        field->for_show = TRUE;
        field->for_where = TRUE;
+       field->for_order = TRUE;
        field->available_where_type = GDAEX_QE_WHERE_TYPE_NUMBER;
        gdaex_query_editor_table_add_field (qe, "orders", *field);
        g_free (field);