~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: patrick crews
  • Date: 2011-03-15 12:12:09 UTC
  • mfrom: (1099.4.216 drizzle)
  • Revision ID: gleebix@gmail.com-20110315121209-8g2tkf31w0rx9ter
Tags: 2011.03.12
Updated translations

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