~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2010.12.06-0ubuntu4/drizzled/plugin/table_function.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2011-01-04 09:31:58 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110104093158-smhgvkfdi2y9au3i
Tags: 2011.01.07-0ubuntu1
New upstream release.

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) 2010 Monty Taylor
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; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
 
22
 
#include <drizzled/plugin/table_function.h>
23
 
#include <drizzled/table_function_container.h>
24
 
#include <drizzled/gettext.h>
25
 
#include "drizzled/global_charset_info.h"
26
 
#include "drizzled/session.h"
27
 
#include "drizzled/current_session.h"
28
 
 
29
 
#include <vector>
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
static TableFunctionContainer table_functions;
35
 
 
36
 
void plugin::TableFunction::init()
37
 
{
38
 
  drizzled::message::Engine *engine;
39
 
  drizzled::message::Table::TableOptions *table_options;
40
 
 
41
 
  proto.set_name(getTableLabel());
42
 
  proto.set_schema(identifier.getSchemaName());
43
 
  proto.set_type(drizzled::message::Table::FUNCTION);
44
 
  proto.set_creation_timestamp(0);
45
 
  proto.set_update_timestamp(0);
46
 
 
47
 
  table_options= proto.mutable_options();
48
 
  table_options->set_collation_id(default_charset_info->number);
49
 
  table_options->set_collation(default_charset_info->name);
50
 
 
51
 
  engine= proto.mutable_engine();
52
 
  engine->set_name("FunctionEngine");
53
 
}
54
 
 
55
 
bool plugin::TableFunction::addPlugin(plugin::TableFunction *tool)
56
 
{
57
 
  assert(tool != NULL);
58
 
  table_functions.addFunction(tool); 
59
 
  return false;
60
 
}
61
 
 
62
 
plugin::TableFunction *plugin::TableFunction::getFunction(const std::string &arg)
63
 
{
64
 
  return table_functions.getFunction(arg);
65
 
}
66
 
 
67
 
void plugin::TableFunction::getNames(const std::string &arg,
68
 
                                     std::set<std::string> &set_of_names)
69
 
{
70
 
  table_functions.getNames(arg, set_of_names);
71
 
}
72
 
 
73
 
plugin::TableFunction::Generator *plugin::TableFunction::generator(Field **arg)
74
 
{
75
 
  return new Generator(arg);
76
 
}
77
 
 
78
 
void plugin::TableFunction::add_field(const char *label,
79
 
                                      uint32_t field_length)
80
 
{
81
 
  add_field(label, TableFunction::STRING, field_length);
82
 
}
83
 
 
84
 
void plugin::TableFunction::add_field(const char *label,
85
 
                              TableFunction::ColumnType type,
86
 
                              bool is_default_null)
87
 
{
88
 
  add_field(label, type, 5, is_default_null);
89
 
}
90
 
 
91
 
void plugin::TableFunction::add_field(const char *label,
92
 
                                      TableFunction::ColumnType type,
93
 
                                      uint32_t field_length,
94
 
                                      bool is_default_null)
95
 
{
96
 
  drizzled::message::Table::Field *field;
97
 
  drizzled::message::Table::Field::FieldOptions *field_options;
98
 
  drizzled::message::Table::Field::FieldConstraints *field_constraints;
99
 
 
100
 
  field= proto.add_field();
101
 
  field->set_name(label);
102
 
 
103
 
  field_options= field->mutable_options();
104
 
  field_constraints= field->mutable_constraints();
105
 
  field_options->set_default_null(is_default_null);
106
 
  field_constraints->set_is_nullable(is_default_null);
107
 
 
108
 
  switch (type) 
109
 
  {
110
 
  default:
111
 
  case TableFunction::BOOLEAN: // Currently BOOLEAN always has a value
112
 
    field_length= 5;
113
 
    field_options->set_default_null(false);
114
 
    field_constraints->set_is_nullable(false);
115
 
  case TableFunction::STRING:
116
 
    {
117
 
      drizzled::message::Table::Field::StringFieldOptions *string_field_options;
118
 
      if (field_length >= TABLE_FUNCTION_BLOB_SIZE)
119
 
      {
120
 
        field->set_type(drizzled::message::Table::Field::BLOB);
121
 
        string_field_options= field->mutable_string_options();
122
 
        string_field_options->set_collation_id(default_charset_info->number);
123
 
        string_field_options->set_collation(default_charset_info->name);
124
 
      }
125
 
      else
126
 
      {
127
 
        field->set_type(drizzled::message::Table::Field::VARCHAR);
128
 
        string_field_options= field->mutable_string_options();
129
 
        string_field_options->set_length(field_length);
130
 
      }
131
 
    }
132
 
    break;
133
 
  case TableFunction::VARBINARY:
134
 
    {
135
 
      drizzled::message::Table::Field::StringFieldOptions *string_field_options;
136
 
      field->set_type(drizzled::message::Table::Field::VARCHAR);
137
 
 
138
 
      string_field_options= field->mutable_string_options();
139
 
      string_field_options->set_length(field_length);
140
 
      string_field_options->set_collation(my_charset_bin.csname);
141
 
      string_field_options->set_collation_id(my_charset_bin.number);
142
 
    }
143
 
    break;
144
 
  case TableFunction::NUMBER:
145
 
    field->set_type(drizzled::message::Table::Field::BIGINT);
146
 
    break;
147
 
  case TableFunction::SIZE:
148
 
    field->set_type(drizzled::message::Table::Field::BIGINT);
149
 
    field_constraints->set_is_unsigned(true);
150
 
    break;
151
 
  }
152
 
}
153
 
 
154
 
plugin::TableFunction::Generator::Generator(Field **arg) :
155
 
  columns(arg),
156
 
  session(current_session)
157
 
{
158
 
  scs= system_charset_info;
159
 
}
160
 
 
161
 
bool plugin::TableFunction::Generator::sub_populate(uint32_t field_size)
162
 
{
163
 
  bool ret;
164
 
  uint64_t difference;
165
 
 
166
 
  columns_iterator= columns;
167
 
  ret= populate();
168
 
  difference= columns_iterator - columns;
169
 
 
170
 
  if (ret == true)
171
 
  {
172
 
    assert(difference == field_size);
173
 
  }
174
 
 
175
 
  return ret;
176
 
}
177
 
 
178
 
void plugin::TableFunction::Generator::push(uint64_t arg)
179
 
{
180
 
  (*columns_iterator)->store(static_cast<int64_t>(arg), true);
181
 
  (*columns_iterator)->set_notnull();
182
 
  columns_iterator++;
183
 
}
184
 
 
185
 
void plugin::TableFunction::Generator::push(int64_t arg)
186
 
{
187
 
  (*columns_iterator)->store(arg, false);
188
 
  (*columns_iterator)->set_notnull();
189
 
  columns_iterator++;
190
 
}
191
 
 
192
 
void plugin::TableFunction::Generator::push(const char *arg, uint32_t length)
193
 
{
194
 
  assert(columns_iterator);
195
 
  assert(*columns_iterator);
196
 
  assert(arg);
197
 
  length= length ? length : strlen(arg);
198
 
 
199
 
  if ((*columns_iterator)->char_length() < length)
200
 
    length= (*columns_iterator)->char_length();
201
 
 
202
 
  (*columns_iterator)->store(arg, length, scs);
203
 
  (*columns_iterator)->set_notnull();
204
 
  columns_iterator++;
205
 
}
206
 
 
207
 
void plugin::TableFunction::Generator::push()
208
 
{
209
 
  /* Only accept NULLs */
210
 
  assert((*columns_iterator)->maybe_null());
211
 
  (*columns_iterator)->set_null();
212
 
  columns_iterator++;
213
 
}
214
 
 
215
 
void plugin::TableFunction::Generator::push(const std::string& arg)
216
 
{
217
 
  push(arg.c_str(), arg.length());
218
 
}
219
 
 
220
 
void plugin::TableFunction::Generator::push(bool arg)
221
 
{
222
 
  if (arg)
223
 
  {
224
 
    (*columns_iterator)->store("YES", 3, scs);
225
 
  }
226
 
  else
227
 
  {
228
 
    (*columns_iterator)->store("NO", 2, scs);
229
 
  }
230
 
 
231
 
  columns_iterator++;
232
 
}
233
 
 
234
 
bool plugin::TableFunction::Generator::isWild(const std::string &predicate)
235
 
{
236
 
  if (not getSession().lex->wild)
237
 
    return false;
238
 
 
239
 
  bool match= wild_case_compare(system_charset_info,
240
 
                                predicate.c_str(),
241
 
                                getSession().lex->wild->ptr());
242
 
 
243
 
  return match;
244
 
}
245
 
 
246
 
} /* namespace drizzled */