~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/select_dumpvar.h

pandora-build v0.100 - Fixes several bugs found by cb1kenobi. Add several thoughts from folks at LCA.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
 
 
21
#ifndef DRIZZLED_SELECT_DUMPVAR_H
 
22
#define DRIZZLED_SELECT_DUMPVAR_H
 
23
 
 
24
#include "drizzled/error.h"
 
25
#include "drizzled/my_error.h"
 
26
 
 
27
#include <vector>
 
28
 
 
29
class select_dumpvar :public select_result_interceptor {
 
30
  ha_rows row_count;
 
31
public:
 
32
  std::vector<my_var *> var_list;
 
33
  select_dumpvar()  { var_list.clear(); row_count= 0;}
 
34
  ~select_dumpvar() {}
 
35
 
 
36
  int prepare(List<Item> &list, Select_Lex_Unit *u)
 
37
  {
 
38
    unit= u;
 
39
 
 
40
    if (var_list.size() != list.elements)
 
41
    {
 
42
      my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
 
43
                 ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0));
 
44
      return 1;
 
45
    }
 
46
    return 0;
 
47
  }
 
48
 
 
49
  void cleanup()
 
50
  {
 
51
    row_count= 0;
 
52
  }
 
53
 
 
54
 
 
55
  bool send_data(List<Item> &items)
 
56
  {
 
57
    
 
58
    std::vector<my_var *>::const_iterator iter= var_list.begin();
 
59
 
 
60
    List_iterator<Item> it(items);
 
61
    Item *item;
 
62
    my_var *current_var;
 
63
 
 
64
    if (unit->offset_limit_cnt)
 
65
    {                                           // using limit offset,count
 
66
      unit->offset_limit_cnt--;
 
67
      return(0);
 
68
    }
 
69
    if (row_count++)
 
70
    {
 
71
      my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
 
72
      return(1);
 
73
    }
 
74
    while ((iter != var_list.end()) && (item= it++))
 
75
    {
 
76
      current_var= *iter;
 
77
      if (current_var->local == 0)
 
78
      {
 
79
        Item_func_set_user_var *suv= new Item_func_set_user_var(current_var->s, item);
 
80
        suv->fix_fields(session, 0);
 
81
        suv->check(0);
 
82
        suv->update();
 
83
      }
 
84
      ++iter;
 
85
    }
 
86
    return(session->is_error());
 
87
  }
 
88
 
 
89
  bool send_eof()
 
90
  {
 
91
    if (! row_count)
 
92
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
93
                   ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA));
 
94
    /*
 
95
      In order to remember the value of affected rows for ROW_COUNT()
 
96
      function, SELECT INTO has to have an own SQLCOM.
 
97
TODO: split from SQLCOM_SELECT
 
98
  */
 
99
    session->my_ok(row_count);
 
100
    return 0;
 
101
  }
 
102
 
 
103
};
 
104
 
 
105
#endif /* DRIZZLED_SELECT_DUMPVAR_H */