~drizzle-trunk/drizzle/development

851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
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
#ifndef DRIZZLED_SELECT_DUMPVAR_H
21
#define DRIZZLED_SELECT_DUMPVAR_H
22
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
23
#include "drizzled/error.h"
1271.5.3 by Tim Penhey
change the include files
24
#include "drizzled/error.h"
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
25
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
26
#include <vector>
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
27
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
28
namespace drizzled
29
{
30
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
31
class select_dumpvar :public select_result_interceptor {
32
  ha_rows row_count;
33
public:
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
34
  std::vector<my_var *> var_list;
35
  select_dumpvar()  { var_list.clear(); row_count= 0;}
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
36
  ~select_dumpvar() {}
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
37
38
  int prepare(List<Item> &list, Select_Lex_Unit *u)
39
  {
40
    unit= u;
41
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
42
    if (var_list.size() != list.elements)
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
43
    {
44
      my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
45
                 ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0));
46
      return 1;
47
    }
48
    return 0;
49
  }
50
51
  void cleanup()
52
  {
53
    row_count= 0;
54
  }
55
56
57
  bool send_data(List<Item> &items)
58
  {
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
59
    
60
    std::vector<my_var *>::const_iterator iter= var_list.begin();
61
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
62
    List_iterator<Item> it(items);
63
    Item *item;
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
64
    my_var *current_var;
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
65
66
    if (unit->offset_limit_cnt)
67
    {						// using limit offset,count
68
      unit->offset_limit_cnt--;
69
      return(0);
70
    }
71
    if (row_count++)
72
    {
73
      my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
74
      return(1);
75
    }
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
76
    while ((iter != var_list.end()) && (item= it++))
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
77
    {
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
78
      current_var= *iter;
79
      if (current_var->local == 0)
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
80
      {
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
81
        Item_func_set_user_var *suv= new Item_func_set_user_var(current_var->s, item);
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
82
        suv->fix_fields(session, 0);
83
        suv->check(0);
84
        suv->update();
85
      }
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
86
      ++iter;
882 by Brian Aker
Minor refactoring (we will need to disconnect the code from the include
87
    }
88
    return(session->is_error());
89
  }
90
91
  bool send_eof()
92
  {
93
    if (! row_count)
94
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
95
                   ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA));
96
    /*
97
      In order to remember the value of affected rows for ROW_COUNT()
98
      function, SELECT INTO has to have an own SQLCOM.
99
TODO: split from SQLCOM_SELECT
100
  */
101
    session->my_ok(row_count);
102
    return 0;
103
  }
104
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
105
};
106
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
107
} /* namespace drizzled */
108
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
109
#endif /* DRIZZLED_SELECT_DUMPVAR_H */