~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.cc

  • Committer: lbieber
  • Date: 2010-10-02 19:48:35 UTC
  • mfrom: (1730.6.19 drizzle-make-lcov)
  • Revision ID: lbieber@orisndriz08-20101002194835-q5zd9qc4lvx1xnfo
Merge Hartmut - clean up lex, now require flex to build, also "make lcov" improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
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/global_charset_info.h"
 
26
#include "drizzled/session.h"
 
27
#include "drizzled/current_session.h"
29
28
 
30
29
#include <vector>
31
30
 
 
31
using namespace std;
 
32
 
32
33
namespace drizzled
33
34
{
34
35
 
36
37
 
37
38
void plugin::TableFunction::init()
38
39
{
39
 
  drizzled::message::table::init(proto, getTableLabel(), identifier.getSchemaName(), "FunctionEngine");
 
40
  drizzled::message::Engine *engine;
 
41
  drizzled::message::Table::TableOptions *table_options;
 
42
 
 
43
  proto.set_name(getTableLabel());
 
44
  proto.set_schema(identifier.getSchemaName());
40
45
  proto.set_type(drizzled::message::Table::FUNCTION);
41
46
  proto.set_creation_timestamp(0);
42
47
  proto.set_update_timestamp(0);
 
48
 
 
49
  table_options= proto.mutable_options();
 
50
  table_options->set_collation_id(default_charset_info->number);
 
51
  table_options->set_collation(default_charset_info->name);
 
52
 
 
53
  engine= proto.mutable_engine();
 
54
  engine->set_name("FunctionEngine");
43
55
}
44
56
 
45
57
bool plugin::TableFunction::addPlugin(plugin::TableFunction *tool)
49
61
  return false;
50
62
}
51
63
 
52
 
plugin::TableFunction *plugin::TableFunction::getFunction(const std::string &arg)
 
64
plugin::TableFunction *plugin::TableFunction::getFunction(const string &arg)
53
65
{
54
66
  return table_functions.getFunction(arg);
55
67
}
56
68
 
57
 
void plugin::TableFunction::getNames(const std::string &arg,
58
 
                                     std::set<std::string> &set_of_names)
 
69
void plugin::TableFunction::getNames(const string &arg,
 
70
                                     set<std::string> &set_of_names)
59
71
{
60
72
  table_functions.getNames(arg, set_of_names);
61
73
}
93
105
  field_options= field->mutable_options();
94
106
  field_constraints= field->mutable_constraints();
95
107
  field_options->set_default_null(is_default_null);
96
 
  field_constraints->set_is_notnull(not is_default_null);
 
108
  field_constraints->set_is_nullable(is_default_null);
97
109
 
98
110
  switch (type) 
99
111
  {
 
112
  default:
 
113
  case TableFunction::BOOLEAN: // Currently BOOLEAN always has a value
 
114
    field_length= 5;
 
115
    field_options->set_default_null(false);
 
116
    field_constraints->set_is_nullable(false);
100
117
  case TableFunction::STRING:
101
 
    {
102
 
      drizzled::message::Table::Field::StringFieldOptions *string_field_options;
103
 
      if (field_length >= TABLE_FUNCTION_BLOB_SIZE)
104
 
      {
105
 
        field->set_type(drizzled::message::Table::Field::BLOB);
106
 
        string_field_options= field->mutable_string_options();
107
 
        string_field_options->set_collation_id(default_charset_info->number);
108
 
        string_field_options->set_collation(default_charset_info->name);
109
 
      }
110
 
      else
111
 
      {
112
 
        field->set_type(drizzled::message::Table::Field::VARCHAR);
113
 
        string_field_options= field->mutable_string_options();
114
 
        string_field_options->set_length(field_length);
115
 
      }
116
 
    }
 
118
  {
 
119
    drizzled::message::Table::Field::StringFieldOptions *string_field_options;
 
120
    field->set_type(drizzled::message::Table::Field::VARCHAR);
 
121
 
 
122
    string_field_options= field->mutable_string_options();
 
123
    string_field_options->set_length(field_length);
 
124
  }
117
125
    break;
118
126
  case TableFunction::VARBINARY:
119
 
    {
120
 
      drizzled::message::Table::Field::StringFieldOptions *string_field_options;
121
 
      field->set_type(drizzled::message::Table::Field::VARCHAR);
 
127
  {
 
128
    drizzled::message::Table::Field::StringFieldOptions *string_field_options;
 
129
    field->set_type(drizzled::message::Table::Field::VARCHAR);
122
130
 
123
 
      string_field_options= field->mutable_string_options();
124
 
      string_field_options->set_length(field_length);
125
 
      string_field_options->set_collation(my_charset_bin.csname);
126
 
      string_field_options->set_collation_id(my_charset_bin.number);
127
 
    }
128
 
    break;
129
 
  case TableFunction::NUMBER:
130
 
    field->set_type(drizzled::message::Table::Field::BIGINT);
131
 
    break;
132
 
  case TableFunction::SIZE:
133
 
    field->set_type(drizzled::message::Table::Field::BIGINT);
134
 
    field_constraints->set_is_unsigned(true);
135
 
    break;
136
 
  case TableFunction::BOOLEAN: // Currently BOOLEAN always has a value
137
 
    field->set_type(drizzled::message::Table::Field::BOOLEAN);
138
 
    field_constraints->set_is_unsigned(true);
 
131
    string_field_options= field->mutable_string_options();
 
132
    string_field_options->set_length(field_length);
 
133
    string_field_options->set_collation(my_charset_bin.csname);
 
134
    string_field_options->set_collation_id(my_charset_bin.number);
 
135
  }
 
136
    break;
 
137
  case TableFunction::NUMBER: // Currently NUMBER always has a value
 
138
    field->set_type(drizzled::message::Table::Field::BIGINT);
139
139
    break;
140
140
  }
141
141
}
185
185
  assert(arg);
186
186
  length= length ? length : strlen(arg);
187
187
 
188
 
  if ((*columns_iterator)->char_length() < length)
189
 
    length= (*columns_iterator)->char_length();
190
 
 
191
188
  (*columns_iterator)->store(arg, length, scs);
192
189
  (*columns_iterator)->set_notnull();
193
190
  columns_iterator++;
195
192
 
196
193
void plugin::TableFunction::Generator::push()
197
194
{
198
 
  /* Only accept NULLs */
199
 
  assert((*columns_iterator)->maybe_null());
 
195
#if 0 // @note this needs to be rewritten such that a drizzled::Field object can determine if it should ever be null
 
196
  assert((*columns_iterator)->getTable()->getShare()->getTableProto()->field((*columns_iterator)->getTable()->getFields() - columns_iterator).constraints().is_nullable());
 
197
#endif
200
198
  (*columns_iterator)->set_null();
201
199
  columns_iterator++;
202
200
}