~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.cc

  • Committer: Stewart Smith
  • Date: 2010-02-15 03:55:09 UTC
  • mto: (1273.13.96 build)
  • mto: This revision was merged to the branch mainline in revision 1308.
  • Revision ID: stewart@flamingspork.com-20100215035509-y6sry4q4yymph2by
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <drizzled/plugin/table_function.h>
23
23
#include <drizzled/table_function_container.h>
24
24
#include <drizzled/gettext.h>
 
25
#include "drizzled/plugin/registry.h"
25
26
#include "drizzled/global_charset_info.h"
26
27
#include "drizzled/session.h"
27
28
#include "drizzled/current_session.h"
28
29
 
29
30
#include <vector>
30
31
 
 
32
using namespace std;
 
33
 
31
34
namespace drizzled
32
35
{
33
36
 
35
38
 
36
39
void plugin::TableFunction::init()
37
40
{
38
 
  drizzled::message::Engine *engine;
 
41
  drizzled::message::Table::StorageEngine *engine;
39
42
  drizzled::message::Table::TableOptions *table_options;
40
43
 
41
 
  proto.set_name(getTableLabel());
42
 
  proto.set_schema(identifier.getSchemaName());
 
44
  proto.set_name(identifier.getTableName());
43
45
  proto.set_type(drizzled::message::Table::FUNCTION);
44
 
  proto.set_creation_timestamp(0);
45
 
  proto.set_update_timestamp(0);
46
46
 
47
47
  table_options= proto.mutable_options();
48
48
  table_options->set_collation_id(default_charset_info->number);
59
59
  return false;
60
60
}
61
61
 
62
 
plugin::TableFunction *plugin::TableFunction::getFunction(const std::string &arg)
 
62
plugin::TableFunction *plugin::TableFunction::getFunction(const string &arg)
63
63
{
64
64
  return table_functions.getFunction(arg);
65
65
}
66
66
 
67
 
void plugin::TableFunction::getNames(const std::string &arg,
68
 
                                     std::set<std::string> &set_of_names)
 
67
void plugin::TableFunction::getNames(const string &arg,
 
68
                                     set<std::string> &set_of_names)
69
69
{
70
70
  table_functions.getNames(arg, set_of_names);
71
71
}
89
89
}
90
90
 
91
91
void plugin::TableFunction::add_field(const char *label,
92
 
                                      TableFunction::ColumnType type,
93
 
                                      uint32_t field_length,
94
 
                                      bool is_default_null)
 
92
                              TableFunction::ColumnType type,
 
93
                              uint32_t field_length,
 
94
                              bool is_default_null)
95
95
{
96
96
  drizzled::message::Table::Field *field;
97
97
  drizzled::message::Table::Field::FieldOptions *field_options;
113
113
    field_options->set_default_null(false);
114
114
    field_constraints->set_is_nullable(false);
115
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
 
    }
 
116
    drizzled::message::Table::Field::StringFieldOptions *string_field_options;
 
117
    field->set_type(drizzled::message::Table::Field::VARCHAR);
 
118
 
 
119
    string_field_options= field->mutable_string_options();
 
120
    string_field_options->set_length(field_length);
 
121
 
143
122
    break;
144
123
  case TableFunction::NUMBER: // Currently NUMBER always has a value
145
124
    field->set_type(drizzled::message::Table::Field::BIGINT);
 
125
    field_options->set_default_null(false);
 
126
    field_constraints->set_is_nullable(false);
146
127
    break;
147
128
  }
148
129
}
149
130
 
150
131
plugin::TableFunction::Generator::Generator(Field **arg) :
151
 
  columns(arg),
152
 
  session(current_session)
 
132
  columns(arg)
153
133
{
154
134
  scs= system_charset_info;
155
135
}
173
153
 
174
154
void plugin::TableFunction::Generator::push(uint64_t arg)
175
155
{
176
 
  (*columns_iterator)->store(static_cast<int64_t>(arg), true);
177
 
  (*columns_iterator)->set_notnull();
 
156
  (*columns_iterator)->store(static_cast<int64_t>(arg), false);
 
157
  columns_iterator++;
 
158
}
 
159
 
 
160
void plugin::TableFunction::Generator::push(uint32_t arg)
 
161
{
 
162
  (*columns_iterator)->store(static_cast<int64_t>(arg), false);
178
163
  columns_iterator++;
179
164
}
180
165
 
181
166
void plugin::TableFunction::Generator::push(int64_t arg)
182
167
{
183
168
  (*columns_iterator)->store(arg, false);
184
 
  (*columns_iterator)->set_notnull();
 
169
  columns_iterator++;
 
170
}
 
171
 
 
172
void plugin::TableFunction::Generator::push(int32_t arg)
 
173
{
 
174
  (*columns_iterator)->store(arg, false);
185
175
  columns_iterator++;
186
176
}
187
177
 
192
182
  assert(arg);
193
183
  length= length ? length : strlen(arg);
194
184
 
195
 
  if ((*columns_iterator)->char_length() < length)
196
 
    length= (*columns_iterator)->char_length();
 
185
  if (not length)
 
186
    return push();
197
187
 
198
188
  (*columns_iterator)->store(arg, length, scs);
199
189
  (*columns_iterator)->set_notnull();
202
192
 
203
193
void plugin::TableFunction::Generator::push()
204
194
{
205
 
  /* Only accept NULLs */
206
 
  assert((*columns_iterator)->maybe_null());
 
195
  assert((*columns_iterator)->type()  == DRIZZLE_TYPE_VARCHAR);
207
196
  (*columns_iterator)->set_null();
208
197
  columns_iterator++;
209
198
}
217
206
{
218
207
  if (arg)
219
208
  {
220
 
    (*columns_iterator)->store("YES", 3, scs);
 
209
    (*columns_iterator)->store("TRUE", 4, scs);
221
210
  }
222
211
  else
223
212
  {
224
 
    (*columns_iterator)->store("NO", 2, scs);
 
213
    (*columns_iterator)->store("FALSE", 5, scs);
225
214
  }
226
215
 
227
216
  columns_iterator++;
229
218
 
230
219
bool plugin::TableFunction::Generator::isWild(const std::string &predicate)
231
220
{
232
 
  if (not getSession().lex->wild)
 
221
  Session *session= current_session;
 
222
 
 
223
  if (not session->lex->wild)
233
224
    return false;
234
225
 
235
226
  bool match= wild_case_compare(system_charset_info,
236
227
                                predicate.c_str(),
237
 
                                getSession().lex->wild->ptr());
 
228
                                session->lex->wild->ptr());
238
229
 
239
230
  return match;
240
231
}