~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/sum.cc

  • Committer: Monty Taylor
  • Date: 2011-02-12 21:49:59 UTC
  • mto: (2165.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110212214959-bve8sh4hu761y48m
Updated the windows build to be able to build from the command line and not to show warnings on strncpy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  @brief
21
21
  Sum functions (COUNT, MIN...)
22
22
*/
23
 
#include <config.h>
 
23
#include "config.h"
24
24
#include <cstdio>
25
25
#include <math.h>
26
26
#include <drizzled/sql_select.h>
29
29
#include <drizzled/hybrid_type_traits_integer.h>
30
30
#include <drizzled/hybrid_type_traits_decimal.h>
31
31
#include <drizzled/sql_base.h>
32
 
#include <drizzled/session.h>
33
32
 
34
33
#include <drizzled/item/sum.h>
35
34
#include <drizzled/field/decimal.h>
37
36
#include <drizzled/field/int64.h>
38
37
#include <drizzled/field/date.h>
39
38
#include <drizzled/field/datetime.h>
40
 
#include <drizzled/unique.h>
41
39
 
42
40
#include <drizzled/type/decimal.h>
43
41
 
44
 
#include <drizzled/internal/m_string.h>
 
42
#include "drizzled/internal/m_string.h"
45
43
 
46
44
#include <algorithm>
47
45
 
76
74
 
77
75
bool Item_sum::init_sum_func_check(Session *session)
78
76
{
79
 
  if (!session->getLex()->allow_sum_func)
 
77
  if (!session->lex->allow_sum_func)
80
78
  {
81
79
    my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE),
82
80
               MYF(0));
83
81
    return true;
84
82
  }
85
83
  /* Set a reference to the nesting set function if there is  any */
86
 
  in_sum_func= session->getLex()->in_sum_func;
 
84
  in_sum_func= session->lex->in_sum_func;
87
85
  /* Save a pointer to object to be used in items for nested set functions */
88
 
  session->getLex()->in_sum_func= this;
89
 
  nest_level= session->getLex()->current_select->nest_level;
 
86
  session->lex->in_sum_func= this;
 
87
  nest_level= session->lex->current_select->nest_level;
90
88
  ref_by= 0;
91
89
  aggr_level= -1;
92
90
  aggr_sel= NULL;
93
91
  max_arg_level= -1;
94
92
  max_sum_func_level= -1;
95
 
  outer_fields.clear();
 
93
  outer_fields.empty();
96
94
  return false;
97
95
}
98
96
 
148
146
bool Item_sum::check_sum_func(Session *session, Item **ref)
149
147
{
150
148
  bool invalid= false;
151
 
  nesting_map allow_sum_func= session->getLex()->allow_sum_func;
 
149
  nesting_map allow_sum_func= session->lex->allow_sum_func;
152
150
  /*
153
151
    The value of max_arg_level is updated if an argument of the set function
154
152
    contains a column reference resolved  against a subquery whose level is
181
179
  if (!invalid && aggr_level < 0)
182
180
  {
183
181
    aggr_level= nest_level;
184
 
    aggr_sel= session->getLex()->current_select;
 
182
    aggr_sel= session->lex->current_select;
185
183
  }
186
184
  /*
187
185
    By this moment we either found a subquery where the set function is
256
254
        select the field belongs to. If there are some then an error is
257
255
        raised.
258
256
    */
259
 
    List<Item_field>::iterator of(outer_fields.begin());
 
257
    List_iterator<Item_field> of(outer_fields);
260
258
    while ((field= of++))
261
259
    {
262
260
      Select_Lex *sel= field->cached_table->select_lex;
287
285
  }
288
286
  aggr_sel->full_group_by_flag.set(SUM_FUNC_USED);
289
287
  update_used_tables();
290
 
  session->getLex()->in_sum_func= in_sum_func;
 
288
  session->lex->in_sum_func= in_sum_func;
291
289
  return false;
292
290
}
293
291
 
319
317
bool Item_sum::register_sum_func(Session *session, Item **ref)
320
318
{
321
319
  Select_Lex *sl;
322
 
  nesting_map allow_sum_func= session->getLex()->allow_sum_func;
323
 
  for (sl= session->getLex()->current_select->master_unit()->outer_select() ;
 
320
  nesting_map allow_sum_func= session->lex->allow_sum_func;
 
321
  for (sl= session->lex->current_select->master_unit()->outer_select() ;
324
322
       sl && sl->nest_level > max_arg_level;
325
323
       sl= sl->master_unit()->outer_select() )
326
324
  {
371
369
      with_sum_func being set for an Select_Lex means that this Select_Lex
372
370
      has aggregate functions directly referenced (i.e. not through a sub-select).
373
371
    */
374
 
    for (sl= session->getLex()->current_select;
 
372
    for (sl= session->lex->current_select;
375
373
         sl && sl != aggr_sel && sl->master_unit()->item;
376
374
         sl= sl->master_unit()->outer_select() )
377
375
      sl->master_unit()->item->with_sum_func= 1;
378
376
  }
379
 
  session->getLex()->current_select->mark_as_dependent(aggr_sel);
 
377
  session->lex->current_select->mark_as_dependent(aggr_sel);
380
378
  return false;
381
379
}
382
380
 
387
385
  if ((args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count)))
388
386
  {
389
387
    uint32_t i=0;
390
 
    List<Item>::iterator li(list.begin());
 
388
    List_iterator_fast<Item> li(list);
391
389
    Item *item;
392
390
 
393
391
    while ((item=li++))
396
394
    }
397
395
  }
398
396
  mark_as_sum_func();
399
 
  list.clear();                                 // Fields are used
 
397
  list.empty();                                 // Fields are used
400
398
}
401
399
 
402
400
 
738
736
  */
739
737
  switch (args[0]->field_type()) {
740
738
  case DRIZZLE_TYPE_DATE:
741
 
    field= new Field_date(maybe_null, name);
 
739
    field= new Field_date(maybe_null, name, collation.collation);
742
740
    break;
743
741
  case DRIZZLE_TYPE_TIMESTAMP:
744
742
  case DRIZZLE_TYPE_DATETIME:
745
 
    field= new Field_datetime(maybe_null, name);
 
743
    field= new Field_datetime(maybe_null, name, collation.collation);
746
744
    break;
747
745
  default:
748
746
    return Item_sum::create_tmp_field(group, table, convert_blob_length);
2584
2582
bool Item_sum_count_distinct::setup(Session *session)
2585
2583
{
2586
2584
  List<Item> list;
2587
 
  Select_Lex *select_lex= session->getLex()->current_select;
 
2585
  Select_Lex *select_lex= session->lex->current_select;
2588
2586
 
2589
2587
  /*
2590
2588
    Setup can be called twice for ROLLUP items. This is a bug.
2998
2996
  order= (Order**)(args + arg_count);
2999
2997
 
3000
2998
  /* fill args items of show and sort */
3001
 
  List<Item>::iterator li(select_list->begin());
 
2999
  List_iterator_fast<Item> li(*select_list);
3002
3000
 
3003
3001
  for (arg_ptr=args ; (item_select= li++) ; arg_ptr++)
3004
3002
    *arg_ptr= item_select;
3208
3206
bool Item_func_group_concat::setup(Session *session)
3209
3207
{
3210
3208
  List<Item> list;
3211
 
  Select_Lex *select_lex= session->getLex()->current_select;
 
3209
  Select_Lex *select_lex= session->lex->current_select;
3212
3210
 
3213
3211
  /*
3214
3212
    Currently setup() can be called twice. Please add