~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/select_dumpvar.h

  • Committer: Eric Day
  • Date: 2009-11-10 22:59:28 UTC
  • mto: This revision was merged to the branch mainline in revision 1218.
  • Revision ID: eday@oddments.org-20091110225928-hht1klldtfflwixc
Fixed header file guards and fixed test cases.

Show diffs side-by-side

added added

removed removed

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