Changeset 26266


Ignore:
Timestamp:
06/01/10 23:10:23 (7 years ago)
Author:
piotras
Message:

Rewrite query generation for QB count method. This should satisfy MySQL 5.0, 5.1 and those versions between.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ragnaroek/midgard/core/midgard/src/query_builder.c

    r26258 r26266  
    464464        if(select_type == MQB_SELECT_GUID){
    465465               
    466                 g_string_append_printf(select, "COUNT(%s.guid) ", table);
    467                 if (midgard_object_class_is_multilang (klass) && !builder->priv->unset_lang) {
    468                         g_string_append_printf(select, ", IFNULL(%s_i.sid, 0) AS sid ", table);
    469                 }
     466                if (midgard_object_class_is_multilang (klass) && !builder->priv->unset_lang)
     467                        g_string_append_printf(select, " %s_i.sid AS sid ", table);
     468                else
     469                        g_string_append_printf(select, "COUNT(%s.guid) ", table);
     470
    470471                return g_string_free(select, FALSE);
    471472        }
     
    564565                        builder, select_type,
    565566                        midgard_query_builder_get_object_select(builder, select_type));
    566        
    567         g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "query=%s", sql);
    568567
    569568        if(!sql) {
     
    572571        }               
    573572
     573        /* Multilang fallback, wrap default fallback query */
     574        if (select_type == MQB_SELECT_GUID && midgard_object_class_is_multilang (klass)) {     
     575                GString *ml = g_string_new ("SELECT COUNT(tmp.sid) FROM ( ");
     576                g_string_append_printf (ml, "%s ) AS tmp", sql);
     577                g_free(sql);
     578                sql = g_string_free (ml, FALSE);
     579        }
     580
     581        g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "query=%s", sql);
    574582        gint sq = mysql_query(builder->priv->mgd->msql->mysql, sql);
    575583
Note: See TracChangeset for help on using the changeset viewer.