~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.cc

  • Committer: Djellel E. Difallah
  • Date: 2010-03-27 10:10:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1429.
  • Revision ID: ded@ubuntu-20100327101049-oo3arvatjoyku124
merge my_decimal and decimal

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
 
#include <drizzled/current_session.h>
23
 
#include <drizzled/gettext.h>
24
 
#include <drizzled/global_charset_info.h>
25
22
#include <drizzled/plugin/table_function.h>
26
 
#include <drizzled/session.h>
27
 
#include <drizzled/show.h>
28
23
#include <drizzled/table_function_container.h>
 
24
#include <drizzled/gettext.h>
 
25
#include "drizzled/plugin/registry.h"
 
26
#include "drizzled/global_charset_info.h"
 
27
#include "drizzled/session.h"
 
28
#include "drizzled/current_session.h"
29
29
 
30
30
#include <vector>
31
31
 
 
32
using namespace std;
 
33
 
32
34
namespace drizzled
33
35
{
34
36
 
36
38
 
37
39
void plugin::TableFunction::init()
38
40
{
39
 
  drizzled::message::table::init(proto, getTableLabel(), identifier.getSchemaName(), "FunctionEngine");
 
41
  drizzled::message::Table::StorageEngine *engine;
 
42
  drizzled::message::Table::TableOptions *table_options;
 
43
 
 
44
  proto.set_name(getTableLabel());
 
45
  proto.set_schema(identifier.getSchemaName());
40
46
  proto.set_type(drizzled::message::Table::FUNCTION);
41
47
  proto.set_creation_timestamp(0);
42
48
  proto.set_update_timestamp(0);
43
49
 
44
 
  proto.mutable_options()->set_dont_replicate(true);
 
50
  table_options= proto.mutable_options();
 
51
  table_options->set_collation_id(default_charset_info->number);
 
52
  table_options->set_collation(default_charset_info->name);
 
53
 
 
54
  engine= proto.mutable_engine();
 
55
  engine->set_name("FunctionEngine");
45
56
}
46
57
 
47
58
bool plugin::TableFunction::addPlugin(plugin::TableFunction *tool)
51
62
  return false;
52
63
}
53
64
 
54
 
plugin::TableFunction *plugin::TableFunction::getFunction(const std::string &arg)
 
65
plugin::TableFunction *plugin::TableFunction::getFunction(const string &arg)
55
66
{
56
67
  return table_functions.getFunction(arg);
57
68
}
58
69
 
59
 
void plugin::TableFunction::getNames(const std::string &arg,
60
 
                                     std::set<std::string> &set_of_names)
 
70
void plugin::TableFunction::getNames(const string &arg,
 
71
                                     set<std::string> &set_of_names)
61
72
{
62
73
  table_functions.getNames(arg, set_of_names);
63
74
}
81
92
}
82
93
 
83
94
void plugin::TableFunction::add_field(const char *label,
84
 
                                      TableFunction::ColumnType type,
85
 
                                      uint32_t field_length,
86
 
                                      bool is_default_null)
 
95
                              TableFunction::ColumnType type,
 
96
                              uint32_t field_length,
 
97
                              bool is_default_null)
87
98
{
88
99
  drizzled::message::Table::Field *field;
89
100
  drizzled::message::Table::Field::FieldOptions *field_options;
95
106
  field_options= field->mutable_options();
96
107
  field_constraints= field->mutable_constraints();
97
108
  field_options->set_default_null(is_default_null);
98
 
  field_constraints->set_is_notnull(not is_default_null);
 
109
  field_constraints->set_is_nullable(is_default_null);
99
110
 
100
111
  switch (type) 
101
112
  {
 
113
  default:
 
114
  case TableFunction::BOOLEAN: // Currently BOOLEAN always has a value
 
115
    field_length= 5;
 
116
    field_options->set_default_null(false);
 
117
    field_constraints->set_is_nullable(false);
102
118
  case TableFunction::STRING:
103
 
    {
104
 
      drizzled::message::Table::Field::StringFieldOptions *string_field_options;
105
 
      if (field_length >= TABLE_FUNCTION_BLOB_SIZE)
106
 
      {
107
 
        field->set_type(drizzled::message::Table::Field::BLOB);
108
 
        string_field_options= field->mutable_string_options();
109
 
        string_field_options->set_collation_id(default_charset_info->number);
110
 
        string_field_options->set_collation(default_charset_info->name);
111
 
      }
112
 
      else
113
 
      {
114
 
        field->set_type(drizzled::message::Table::Field::VARCHAR);
115
 
        string_field_options= field->mutable_string_options();
116
 
        string_field_options->set_length(field_length);
117
 
      }
118
 
    }
 
119
  {
 
120
    drizzled::message::Table::Field::StringFieldOptions *string_field_options;
 
121
    field->set_type(drizzled::message::Table::Field::VARCHAR);
 
122
 
 
123
    string_field_options= field->mutable_string_options();
 
124
    string_field_options->set_length(field_length);
 
125
  }
119
126
    break;
120
127
  case TableFunction::VARBINARY:
121
 
    {
122
 
      drizzled::message::Table::Field::StringFieldOptions *string_field_options;
123
 
      field->set_type(drizzled::message::Table::Field::VARCHAR);
 
128
  {
 
129
    drizzled::message::Table::Field::StringFieldOptions *string_field_options;
 
130
    field->set_type(drizzled::message::Table::Field::VARCHAR);
124
131
 
125
 
      string_field_options= field->mutable_string_options();
126
 
      string_field_options->set_length(field_length);
127
 
      string_field_options->set_collation(my_charset_bin.csname);
128
 
      string_field_options->set_collation_id(my_charset_bin.number);
129
 
    }
130
 
    break;
131
 
  case TableFunction::NUMBER:
132
 
    field->set_type(drizzled::message::Table::Field::BIGINT);
133
 
    break;
134
 
  case TableFunction::SIZE:
135
 
    field->set_type(drizzled::message::Table::Field::BIGINT);
136
 
    field_constraints->set_is_unsigned(true);
137
 
    break;
138
 
  case TableFunction::BOOLEAN: // Currently BOOLEAN always has a value
139
 
    field->set_type(drizzled::message::Table::Field::BOOLEAN);
140
 
    field_constraints->set_is_unsigned(true);
 
132
    string_field_options= field->mutable_string_options();
 
133
    string_field_options->set_length(field_length);
 
134
    string_field_options->set_collation(my_charset_bin.csname);
 
135
    string_field_options->set_collation_id(my_charset_bin.number);
 
136
  }
 
137
    break;
 
138
  case TableFunction::NUMBER: // Currently NUMBER always has a value
 
139
    field->set_type(drizzled::message::Table::Field::BIGINT);
 
140
    field_options->set_default_null(false);
 
141
    field_constraints->set_is_nullable(false);
141
142
    break;
142
143
  }
143
144
}
144
145
 
145
146
plugin::TableFunction::Generator::Generator(Field **arg) :
146
 
  columns(arg),
147
 
  session(current_session)
 
147
  columns(arg)
148
148
{
149
149
  scs= system_charset_info;
150
150
}
187
187
  assert(arg);
188
188
  length= length ? length : strlen(arg);
189
189
 
190
 
  if ((*columns_iterator)->char_length() < length)
191
 
    length= (*columns_iterator)->char_length();
192
 
 
193
190
  (*columns_iterator)->store(arg, length, scs);
194
191
  (*columns_iterator)->set_notnull();
195
192
  columns_iterator++;
197
194
 
198
195
void plugin::TableFunction::Generator::push()
199
196
{
200
 
  /* Only accept NULLs */
201
 
  assert((*columns_iterator)->maybe_null());
 
197
  assert((*columns_iterator)->type()  == DRIZZLE_TYPE_VARCHAR);
202
198
  (*columns_iterator)->set_null();
203
199
  columns_iterator++;
204
200
}
212
208
{
213
209
  if (arg)
214
210
  {
215
 
    (*columns_iterator)->store("YES", 3, scs);
 
211
    (*columns_iterator)->store("TRUE", 4, scs);
216
212
  }
217
213
  else
218
214
  {
219
 
    (*columns_iterator)->store("NO", 2, scs);
 
215
    (*columns_iterator)->store("FALSE", 5, scs);
220
216
  }
221
217
 
222
218
  columns_iterator++;
224
220
 
225
221
bool plugin::TableFunction::Generator::isWild(const std::string &predicate)
226
222
{
227
 
  if (not getSession().getLex()->wild)
 
223
  Session *session= current_session;
 
224
 
 
225
  if (not session->lex->wild)
228
226
    return false;
229
227
 
230
228
  bool match= wild_case_compare(system_charset_info,
231
229
                                predicate.c_str(),
232
 
                                getSession().getLex()->wild->ptr());
 
230
                                session->lex->wild->ptr());
233
231
 
234
232
  return match;
235
233
}