Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implicitly set from's join if there's target with the same qualifier

added already
  • Loading branch information...
commit d6994dc1c89fa4db66b73f85f7a14c2b2662c2db 1 parent 7dee9b8
piotras authored

Showing 1 changed file with 29 additions and 13 deletions. Show diff stats Hide diff stats

  1. +29 13 src/sql/midgard_sql_query_select_data.c
42 src/sql/midgard_sql_query_select_data.c
@@ -379,7 +379,7 @@ gboolean __query_select_data_add_joins (MidgardSqlQuerySelectData *self, GdaSqlO
379 379 GdaSqlStatementSelect *select = (GdaSqlStatementSelect *) sql_stm->contents;
380 380 GdaSqlSelectFrom *from = select->from;
381 381 GdaSqlSelectJoin *join;
382   -
  382 +
383 383 for (l = MIDGARD_QUERY_EXECUTOR (self)->priv->joins; l != NULL; l = l->next) {
384 384
385 385 qsj *_sj = (qsj*) l->data;
@@ -417,7 +417,8 @@ gboolean __query_select_data_add_joins (MidgardSqlQuerySelectData *self, GdaSqlO
417 417 midgard_query_holder_get_value (MIDGARD_QUERY_HOLDER (_sj->right_property), &rval);
418 418
419 419 /* Set qualifier as default table and alias */
420   - const gchar *qualifier = midgard_query_column_get_qualifier (MIDGARD_QUERY_COLUMN (_sj->right_property), NULL);
  420 + const gchar *qualifier= NULL;
  421 + qualifier = midgard_query_column_get_qualifier (MIDGARD_QUERY_COLUMN (_sj->right_property), NULL);
421 422 MidgardQueryProperty *qproperty = midgard_query_column_get_query_property (MIDGARD_QUERY_COLUMN (_sj->right_property), NULL);
422 423 gchar *table_name = (gchar *) qualifier;
423 424
@@ -440,22 +441,37 @@ gboolean __query_select_data_add_joins (MidgardSqlQuerySelectData *self, GdaSqlO
440 441 g_value_unset (&rval);
441 442
442 443 join->expr = expr;
443   - join->position = ++executor->priv->joinid;
444 444
445 445 /* Add right qualifier to targets */
446 446 gda_sql_select_from_take_new_join (from , join);
447 447 GdaSqlSelectTarget *s_target = gda_sql_select_target_new (GDA_SQL_ANY_PART (from));
448 448 s_target->table_name = g_strdup (table_name);
449   - s_target->as = g_strdup (qualifier);
450   - //gda_sql_select_from_take_new_target (from, s_target);
451   -
452   - /* Set target expression */
453   - GdaSqlExpr *texpr = gda_sql_expr_new (GDA_SQL_ANY_PART (s_target));
454   - GValue *tval = g_new0 (GValue, 1);
455   - g_value_init (tval, G_TYPE_STRING);
456   - g_value_set_string (tval, table_name);
457   - texpr->value = tval;
458   - s_target->expr = texpr;
  449 + s_target->as = g_strdup (qualifier);
  450 +
  451 + GSList *l = NULL;
  452 + guint i = 0;
  453 + gboolean duplicate = FALSE;
  454 + for (l = from->targets; l != NULL; l = l->next, i++) {
  455 + if (g_str_equal(((GdaSqlSelectTarget*)(l->data))->as, qualifier)) {
  456 + duplicate = TRUE;
  457 + break;
  458 + }
  459 + }
  460 +
  461 + if (duplicate) {
  462 + join->position = i;
  463 + } else {
  464 + gda_sql_select_from_take_new_target (from, s_target);
  465 + join->position = g_slist_length(from->targets)-1;
  466 +
  467 + /* Set target expression, cause we set new target */
  468 + GdaSqlExpr *texpr = gda_sql_expr_new (GDA_SQL_ANY_PART (s_target));
  469 + GValue *tval = g_new0 (GValue, 1);
  470 + g_value_init (tval, G_TYPE_STRING);
  471 + g_value_set_string (tval, table_name);
  472 + texpr->value = tval;
  473 + s_target->expr = texpr;
  474 + }
459 475 }
460 476
461 477 return TRUE;

0 comments on commit d6994dc

Please sign in to comment.
Something went wrong with that request. Please try again.