drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
cached.h
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 <iosfwd>
28
29namespace drizzled {
30namespace plugin {
31namespace client {
32
33class Cached : public Concurrent
34{
35 uint32_t column;
36 uint32_t max_column;
37 sql::ResultSet *_result_set;
38
39public:
40 Cached(sql::ResultSet &rs) :
41 column(0),
42 max_column(0),
43 _result_set(&rs)
44 {
45 }
46
47 virtual void sendFields(List<Item>& list)
48 {
49 List<Item>::iterator it(list.begin());
50 column= 0;
51 max_column= 0;
52
53 while (Item* item= it++)
54 {
55 // max_column starts from 0, ColumnCount from 1
56 _result_set->setColumnCount(max_column+1);
57 // Get pointer to next column metadata class
58 SendField field = _result_set->getColumnInfo(max_column);
59 item->make_field(&field);
60 // Is this necessary or does it just set the same pointer back?
61 _result_set->setColumnInfo(max_column, field);
62 max_column++;
63 }
64 // Moved to checkRowBegin()
65 //_result_set->createRow();
66 }
67
68 virtual void sendError(drizzled::error_t error_code, const char *error_message)
69 {
70 _result_set->pushException(sql::Exception(error_message, error_code));
71 }
72
73 virtual void checkRowBegin()
74 {
75 if (currentColumn() == 0)
76 {
77 _result_set->createRow();
78 }
79 }
80
81 virtual void checkRowEnd()
82 {
83 column++;
84 }
85
86 using Client::store;
87
88 virtual void store(Field *from)
89 {
90 if (from->is_null())
91 return store();
92
93 char buff[MAX_FIELD_WIDTH];
94 String str(buff, sizeof(buff), &my_charset_bin);
95 from->val_str_internal(&str);
96
97 return store(str.ptr(), str.length());
98 }
99
100 virtual void store()
101 {
102 checkRowBegin();
103 _result_set->setColumnNull(currentColumn());
104 checkRowEnd();
105 }
106
107 virtual void store(int32_t from)
108 {
109 checkRowBegin();
110 _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
111 checkRowEnd();
112 }
113
114 virtual void store(uint32_t from)
115 {
116 checkRowBegin();
117 _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
118 checkRowEnd();
119 }
120
121 virtual void store(int64_t from)
122 {
123 checkRowBegin();
124 _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
125 checkRowEnd();
126 }
127
128 virtual void store(uint64_t from)
129 {
130 checkRowBegin();
131 _result_set->setColumn(currentColumn(), boost::lexical_cast<std::string>(from));
132 checkRowEnd();
133 }
134
135 virtual void store(double from, uint32_t decimals, String *buffer)
136 {
137 checkRowBegin();
138 buffer->set_real(from, decimals, &my_charset_bin);
139 return store(buffer->ptr(), buffer->length());
140 }
141
142 virtual void store(const char *from, size_t length)
143 {
144 checkRowBegin();
145 _result_set->setColumn(currentColumn(), std::string(from, length));
146 checkRowEnd();
147 }
148
149 inline uint32_t currentColumn() const
150 {
151 return column % max_column;
152 }
153};
154
155} /* namespace client */
156} /* namespace plugin */
157} /* namespace drizzled */
158
virtual void sendFields(List< Item > &list)
Definition cached.h:47
TODO: Rename this file - func.h is stupid.