~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/client/cached.h

Merge Monty - Added inter-plugin dependencies for controlling plugin load order

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) 2011 Brian Aker
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; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#pragma once
22
 
 
23
 
#include <boost/lexical_cast.hpp>
24
 
#include <drizzled/field.h>
25
 
#include <drizzled/plugin/client/concurrent.h>
26
 
#include <drizzled/sql/result_set.h>
27
 
#include <iostream>
28
 
 
29
 
namespace drizzled {
30
 
namespace plugin {
31
 
namespace client {
32
 
 
33
 
class Cached : public Concurrent
34
 
{
35
 
  uint32_t column;
36
 
  uint32_t max_column;
37
 
  sql::ResultSet *_result_set;
38
 
 
39
 
public:
40
 
  Cached(sql::ResultSet &rs) :
41
 
    column(0),
42
 
    max_column(0),
43
 
    _result_set(&rs)
44
 
  {
45
 
  }
46
 
 
47
 
  virtual bool sendFields(List<Item> *list)
48
 
  {
49
 
    List<Item>::iterator it(list->begin());
50
 
 
51
 
    column= 0;
52
 
    max_column= 0;
53
 
 
54
 
    while (Item* item= it++)
55
 
    {
56
 
      SendField field;
57
 
      item->make_field(&field);
58
 
      max_column++;
59
 
    }
60
 
    _result_set->setColumnCount(max_column);
61
 
    _result_set->createRow();
62
 
 
63
 
    return false;
64
 
  }
65
 
 
66
 
  virtual void sendError(drizzled::error_t error_code, const char *error_message)
67
 
  {
68
 
    _result_set->pushException(sql::Exception(error_message, error_code));
69
 
  }
70
 
 
71
 
  virtual void checkRowEnd()
72
 
  {
73
 
    if (++column % max_column == 0)
74
 
    {
75
 
      _result_set->createRow();
76
 
    }
77
 
  }
78
 
 
79
 
  using Client::store;
80
 
 
81
 
  virtual bool store(Field *from)
82
 
  {
83
 
    if (from->is_null())
84
 
      return store();
85
 
 
86
 
    char buff[MAX_FIELD_WIDTH];
87
 
    String str(buff, sizeof(buff), &my_charset_bin);
88
 
    from->val_str_internal(&str);
89
 
 
90
 
    return store(str.ptr(), str.length());
91
 
  }
92
 
 
93
 
  virtual bool store()
94
 
  {
95
 
    _result_set->setColumnNull(currentColumn());
96
 
 
97
 
    checkRowEnd();
98
 
 
99
 
    return false;
100
 
  }
101
 
 
102
 
  virtual bool store(int32_t from)
103
 
  {
104
 
    _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
105
 
    checkRowEnd();
106
 
 
107
 
    return false;
108
 
  }
109
 
 
110
 
  virtual bool store(uint32_t from)
111
 
  {
112
 
    _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
113
 
    checkRowEnd();
114
 
 
115
 
    return false;
116
 
  }
117
 
 
118
 
  virtual bool store(int64_t from)
119
 
  {
120
 
    _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
121
 
    checkRowEnd();
122
 
 
123
 
    return false;
124
 
  }
125
 
 
126
 
  virtual bool store(uint64_t from)
127
 
  {
128
 
    _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
129
 
    checkRowEnd();
130
 
 
131
 
    return false;
132
 
  }
133
 
 
134
 
  virtual bool store(double from, uint32_t decimals, String *buffer)
135
 
  {
136
 
    buffer->set_real(from, decimals, &my_charset_bin);
137
 
    return store(buffer->ptr(), buffer->length());
138
 
  }
139
 
 
140
 
  virtual bool store(const char *from, size_t length)
141
 
  {
142
 
    _result_set->setColumn(currentColumn(), std::string(from, length));
143
 
    checkRowEnd();
144
 
 
145
 
    return false;
146
 
  }
147
 
  
148
 
  inline uint32_t currentColumn() const
149
 
  {
150
 
    return column % max_column;
151
 
  }
152
 
};
153
 
 
154
 
} /* namespace client */
155
 
} /* namespace plugin */
156
 
} /* namespace drizzled */
157