~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:30:27 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103033027-lskb6gxwwforfz71
fix docs warning: underline/overline too short for replace.rst

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/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);
43
48
 
44
 
  proto.mutable_options()->set_dont_replicate(true);
 
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");
45
55
}
46
56
 
47
57
bool plugin::TableFunction::addPlugin(plugin::TableFunction *tool)
51
61
  return false;
52
62
}
53
63
 
54
 
plugin::TableFunction *plugin::TableFunction::getFunction(const std::string &arg)
 
64
plugin::TableFunction *plugin::TableFunction::getFunction(const string &arg)
55
65
{
56
66
  return table_functions.getFunction(arg);
57
67
}
58
68
 
59
 
void plugin::TableFunction::getNames(const std::string &arg,
60
 
                                     std::set<std::string> &set_of_names)
 
69
void plugin::TableFunction::getNames(const string &arg,
 
70
                                     set<std::string> &set_of_names)
61
71
{
62
72
  table_functions.getNames(arg, set_of_names);
63
73
}
95
105
  field_options= field->mutable_options();
96
106
  field_constraints= field->mutable_constraints();
97
107
  field_options->set_default_null(is_default_null);
98
 
  field_constraints->set_is_notnull(not is_default_null);
 
108
  field_constraints->set_is_nullable(is_default_null);
99
109
 
100
110
  switch (type) 
101
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);
102
117
  case TableFunction::STRING:
103
118
    {
104
119
      drizzled::message::Table::Field::StringFieldOptions *string_field_options;
128
143
      string_field_options->set_collation_id(my_charset_bin.number);
129
144
    }
130
145
    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);
 
146
  case TableFunction::NUMBER: // Currently NUMBER always has a value
 
147
    field->set_type(drizzled::message::Table::Field::BIGINT);
141
148
    break;
142
149
  }
143
150
}
187
194
  assert(arg);
188
195
  length= length ? length : strlen(arg);
189
196
 
190
 
  if ((*columns_iterator)->char_length() < length)
191
 
    length= (*columns_iterator)->char_length();
192
 
 
193
197
  (*columns_iterator)->store(arg, length, scs);
194
198
  (*columns_iterator)->set_notnull();
195
199
  columns_iterator++;
197
201
 
198
202
void plugin::TableFunction::Generator::push()
199
203
{
200
 
  /* Only accept NULLs */
201
 
  assert((*columns_iterator)->maybe_null());
 
204
#if 0 // @note this needs to be rewritten such that a drizzled::Field object can determine if it should ever be null
 
205
  assert((*columns_iterator)->getTable()->getShare()->getTableProto()->field((*columns_iterator)->getTable()->getFields() - columns_iterator).constraints().is_nullable());
 
206
#endif
202
207
  (*columns_iterator)->set_null();
203
208
  columns_iterator++;
204
209
}
224
229
 
225
230
bool plugin::TableFunction::Generator::isWild(const std::string &predicate)
226
231
{
227
 
  if (not getSession().getLex()->wild)
 
232
  if (not getSession().lex->wild)
228
233
    return false;
229
234
 
230
235
  bool match= wild_case_compare(system_charset_info,
231
236
                                predicate.c_str(),
232
 
                                getSession().getLex()->wild->ptr());
 
237
                                getSession().lex->wild->ptr());
233
238
 
234
239
  return match;
235
240
}