~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/select_dumpvar.h

  • Committer: Brian Aker
  • Date: 2009-02-12 22:45:08 UTC
  • Revision ID: brian@tangent.org-20090212224508-mrd9jwgn1zjdpqdk
Minor refactoring (we will need to disconnect the code from the include
file).

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DRIZZLED_SELECT_DUMPVAR_H
22
22
#define DRIZZLED_SELECT_DUMPVAR_H
23
23
 
 
24
#include <drizzled/error.h>
24
25
 
25
26
 
26
27
class select_dumpvar :public select_result_interceptor {
29
30
  List<my_var> var_list;
30
31
  select_dumpvar()  { var_list.empty(); row_count= 0;}
31
32
  ~select_dumpvar() {}
32
 
  int prepare(List<Item> &list, Select_Lex_Unit *u);
33
 
  bool send_data(List<Item> &items);
34
 
  bool send_eof();
35
 
  void cleanup();
 
33
 
 
34
  int prepare(List<Item> &list, Select_Lex_Unit *u)
 
35
  {
 
36
    unit= u;
 
37
 
 
38
    if (var_list.elements != list.elements)
 
39
    {
 
40
      my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
 
41
                 ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0));
 
42
      return 1;
 
43
    }
 
44
    return 0;
 
45
  }
 
46
 
 
47
  void cleanup()
 
48
  {
 
49
    row_count= 0;
 
50
  }
 
51
 
 
52
 
 
53
  bool send_data(List<Item> &items)
 
54
  {
 
55
    List_iterator_fast<my_var> var_li(var_list);
 
56
    List_iterator<Item> it(items);
 
57
    Item *item;
 
58
    my_var *mv;
 
59
 
 
60
    if (unit->offset_limit_cnt)
 
61
    {                                           // using limit offset,count
 
62
      unit->offset_limit_cnt--;
 
63
      return(0);
 
64
    }
 
65
    if (row_count++)
 
66
    {
 
67
      my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
 
68
      return(1);
 
69
    }
 
70
    while ((mv= var_li++) && (item= it++))
 
71
    {
 
72
      if (mv->local == 0)
 
73
      {
 
74
        Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item);
 
75
        suv->fix_fields(session, 0);
 
76
        suv->check(0);
 
77
        suv->update();
 
78
      }
 
79
    }
 
80
    return(session->is_error());
 
81
  }
 
82
 
 
83
  bool send_eof()
 
84
  {
 
85
    if (! row_count)
 
86
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
87
                   ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA));
 
88
    /*
 
89
      In order to remember the value of affected rows for ROW_COUNT()
 
90
      function, SELECT INTO has to have an own SQLCOM.
 
91
TODO: split from SQLCOM_SELECT
 
92
  */
 
93
    session->my_ok(row_count);
 
94
    return 0;
 
95
  }
 
96
 
36
97
};
37
98
 
38
99
#endif /* DRIZZLED_SELECT_DUMPVAR_H */