~linuxjedi/drizzle/trunk-bug-729642

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2011-02-25 17:02:30 UTC
  • mfrom: (2116.1.55 slave)
  • Revision ID: brian@tangent.org-20110225170230-zj0h32xlmr42ly2z
Merge in David's slave work

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
 
 
22
#ifndef DRIZZLED_PLUGIN_CLIENT_CACHED_H
 
23
#define DRIZZLED_PLUGIN_CLIENT_CACHED_H
 
24
 
 
25
 
 
26
#include <drizzled/plugin/client/concurrent.h>
 
27
#include <drizzled/sql/result_set.h>
 
28
 
 
29
#include <boost/scoped_ptr.hpp>
 
30
 
 
31
#include <iostream>
 
32
 
 
33
namespace drizzled
 
34
{
 
35
namespace plugin
 
36
{
 
37
namespace client
 
38
{
 
39
 
 
40
class Cached : public Concurrent
 
41
{
 
42
  uint32_t column;
 
43
  uint32_t max_column;
 
44
  sql::ResultSet *_result_set;
 
45
 
 
46
public:
 
47
  Cached(sql::ResultSet &rs) :
 
48
    Concurrent(),
 
49
    column(0),
 
50
    max_column(0),
 
51
    _result_set(&rs)
 
52
  {
 
53
  }
 
54
 
 
55
  virtual bool sendFields(List<Item> *list)
 
56
  {
 
57
    List<Item>::iterator it(list->begin());
 
58
    Item *item;
 
59
 
 
60
    column= 0;
 
61
    max_column= 0;
 
62
 
 
63
    while ((item=it++))
 
64
    {
 
65
      SendField field;
 
66
      item->make_field(&field);
 
67
      max_column++;
 
68
    }
 
69
    _result_set->createRow();
 
70
 
 
71
    return false;
 
72
  }
 
73
 
 
74
  virtual void sendError(drizzled::error_t error_code, const char *error_message)
 
75
  {
 
76
    sql::Exception tmp(error_message, error_code);
 
77
    _result_set->pushException(tmp);
 
78
  }
 
79
 
 
80
  virtual void checkRowEnd(void)
 
81
  {
 
82
    if (++column % max_column == 0)
 
83
    {
 
84
      _result_set->createRow();
 
85
    }
 
86
  }
 
87
 
 
88
  using Client::store;
 
89
 
 
90
  virtual bool store(Field *from)
 
91
  {
 
92
    if (from->is_null())
 
93
      return store();
 
94
 
 
95
    char buff[MAX_FIELD_WIDTH];
 
96
    String str(buff, sizeof(buff), &my_charset_bin);
 
97
    from->val_str_internal(&str);
 
98
 
 
99
    return store(str.ptr(), str.length());
 
100
  }
 
101
 
 
102
  virtual bool store(void)
 
103
  {
 
104
    _result_set->setColumnNull(currentColumn());
 
105
 
 
106
    checkRowEnd();
 
107
 
 
108
    return false;
 
109
  }
 
110
 
 
111
  virtual bool store(int32_t from)
 
112
  {
 
113
    std::string tmp;
 
114
 
 
115
    tmp= boost::lexical_cast<std::string>(from);
 
116
    _result_set->setColumn(currentColumn(), tmp);
 
117
    checkRowEnd();
 
118
 
 
119
    return false;
 
120
  }
 
121
 
 
122
  virtual bool store(uint32_t from)
 
123
  {
 
124
    std::string tmp;
 
125
 
 
126
    tmp= boost::lexical_cast<std::string>(from);
 
127
    _result_set->setColumn(currentColumn(), tmp);
 
128
    checkRowEnd();
 
129
 
 
130
    return false;
 
131
  }
 
132
 
 
133
  virtual bool store(int64_t from)
 
134
  {
 
135
    std::string tmp;
 
136
 
 
137
    tmp= boost::lexical_cast<std::string>(from);
 
138
    _result_set->setColumn(currentColumn(), tmp);
 
139
    checkRowEnd();
 
140
 
 
141
    return false;
 
142
  }
 
143
 
 
144
  virtual bool store(uint64_t from)
 
145
  {
 
146
    std::string tmp;
 
147
 
 
148
    tmp= boost::lexical_cast<std::string>(from);
 
149
    _result_set->setColumn(currentColumn(), tmp);
 
150
    checkRowEnd();
 
151
 
 
152
    return false;
 
153
  }
 
154
 
 
155
  virtual bool store(double from, uint32_t decimals, String *buffer)
 
156
  {
 
157
    buffer->set_real(from, decimals, &my_charset_bin);
 
158
    return store(buffer->ptr(), buffer->length());
 
159
  }
 
160
 
 
161
  virtual bool store(const char *from, size_t length)
 
162
  {
 
163
    _result_set->setColumn(currentColumn(), std::string(from, length));
 
164
    checkRowEnd();
 
165
 
 
166
    return false;
 
167
  }
 
168
  
 
169
  inline uint32_t currentColumn() const
 
170
  {
 
171
    return column % max_column;
 
172
  }
 
173
};
 
174
 
 
175
} /* namespace client */
 
176
} /* namespace plugin */
 
177
} /* namespace drizzled */
 
178
 
 
179
#endif /* DRIZZLED_PLUGIN_CLIENT_CACHED_H */