diff options
| author | Tristan Van Berkom <tristanvb@openismus.com> | 2013-11-30 15:40:11 +0900 |
|---|---|---|
| committer | Tristan Van Berkom <tristanvb@openismus.com> | 2013-11-30 15:57:05 +0900 |
| commit | 0eb19ea56840c18d7441e8c117a5d5e3036cad10 (patch) | |
| tree | 473186379fe5caf306efd0eac3ac7de72d5cb193 /addressbook | |
| parent | 9a3181beb66a8955a8985ecd38319cd9dfa2aecb (diff) | |
| download | evolution-data-server-0eb19ea56840c18d7441e8c117a5d5e3036cad10.tar.gz | |
EBookSqlite: Experimental query formation change
Diffstat (limited to 'addressbook')
| -rw-r--r-- | addressbook/libedata-book/e-book-sqlite.c | 75 |
1 files changed, 17 insertions, 58 deletions
diff --git a/addressbook/libedata-book/e-book-sqlite.c b/addressbook/libedata-book/e-book-sqlite.c index 923da63c5..2da05e4e8 100644 --- a/addressbook/libedata-book/e-book-sqlite.c +++ b/addressbook/libedata-book/e-book-sqlite.c @@ -4882,7 +4882,7 @@ query_preflight (PreflightContext *context, query_preflight_substitute_full_name (context, ebsql); /* Optimize queries which touch auxiliary columns */ - query_preflight_optimize (context, ebsql); + /* query_preflight_optimize (context, ebsql); */ } else { /* We might use this context to perform a fallback query, @@ -5354,6 +5354,15 @@ ebsql_generate_constraints (EBookSqlite *ebsql, sub_query_context_free (ctx); } + +/* SELECT DISTINCT summary.uid, summary.vcard FROM folder_id AS summary */ +/* JOIN folder_id_phone_list AS phone_list */ +/* ON phone_list.uid = summary.uid */ +/* JOIN folder_id_email_list AS email_list */ +/* ON email_list.uid = summary.uid */ +/* WHERE phone_list.value LIKE '%0505' AND email_list.value LIKE 'eddie%'; */ + + /* Generates the SELECT portion of the query, this will possibly add some * of the constraints into nested selects. Constraints that could not be * nested will have their symbolic table names in context. @@ -5370,7 +5379,6 @@ ebsql_generate_select (EBookSqlite *ebsql, { GSList *l; EbSqlRowFunc callback = NULL; - gchar *previous_field = NULL; g_string_append (string, "SELECT "); if (context->aux_fields) @@ -5400,69 +5408,20 @@ ebsql_generate_select (EBookSqlite *ebsql, break; } - g_string_append (string, "FROM "); + ebsql_string_append_printf (string, "FROM %Q AS summary", ebsql->priv->folderid); for (l = context->aux_fields; l; l = l->next) { PreflightAuxData *aux_data = (PreflightAuxData *)l->data; SummaryField *field = summary_field_get (ebsql, aux_data->field_id); - /* For every other query, start with the JOIN */ - if (previous_field) - g_string_append (string, "LEFT OUTER JOIN "); - - if (aux_data->constraints) { - /* Each nested select must be outer left joined on to - * the previous one, in this way the collection of joined - * tables is equal to a logical AND. - * - * See query_preflight_optimize() for more details. - */ - ebsql_string_append_printf (string, - "( SELECT DISTINCT %s.uid FROM %Q AS %s WHERE ", - field->aux_table_symbolic, - field->aux_table, - field->aux_table_symbolic); - ebsql_generate_constraints (ebsql, string, - aux_data->constraints, - NULL); - ebsql_string_append_printf (string, " ) AS %s_results ", - field->aux_table_symbolic); - - if (previous_field) - ebsql_string_append_printf (string, "ON %s_results.uid = %s ", - field->aux_table_symbolic, - previous_field); - - g_free (previous_field); - previous_field = g_strconcat (field->aux_table_symbolic, - "_results.uid", NULL); - } else { - /* Join the table in the normal way and leave the constraints for later */ - ebsql_string_append_printf (string, "%Q AS %s ", - field->aux_table, - field->aux_table_symbolic); - - if (previous_field) - ebsql_string_append_printf (string, "ON %s.uid = %s ", - field->aux_table_symbolic, - previous_field); - - g_free (previous_field); - previous_field = g_strconcat (field->aux_table_symbolic, - ".uid", NULL); - } + /* Join the table in the normal way and leave the constraints for later */ + ebsql_string_append_printf (string, " JOIN %Q AS %s ON %s.uid = summary.uid", + field->aux_table, + field->aux_table_symbolic, + field->aux_table_symbolic); } - if (previous_field) - g_string_append (string, "LEFT OUTER JOIN "); - - ebsql_string_append_printf (string, "%Q AS summary ", ebsql->priv->folderid); - if (previous_field) - ebsql_string_append_printf (string, "ON summary.uid = %s ", previous_field); - - g_free (previous_field); - return callback; } @@ -5495,7 +5454,7 @@ ebsql_do_search_query (EBookSqlite *ebsql, /* * Now generate the search expression on the main contacts table */ - g_string_append (string, "WHERE "); + g_string_append (string, " WHERE "); ebsql_generate_constraints (ebsql, string, context->constraints, |
