~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.h

  • Committer: Brian Aker
  • Date: 2010-02-14 02:02:48 UTC
  • mfrom: (1273.13.64 fix_is)
  • Revision ID: brian@gaz-20100214020248-bhovaejhz9fmer3q
Merge in data_dictionary.

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
 *  Definitions required for TableFunction plugin
 
5
 *
 
6
 *  Copyright (C) 2010 Sun Microsystems
 
7
 *  Copyright (C) 2010 Monty Taylor
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; version 2 of the License.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program; if not, write to the Free Software
 
20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 */
 
22
 
 
23
#ifndef DRIZZLED_PLUGIN_TABLE_FUNCTION_H
 
24
#define DRIZZLED_PLUGIN_TABLE_FUNCTION_H
 
25
 
 
26
#include <drizzled/definitions.h>
 
27
#include "drizzled/plugin.h"
 
28
#include "drizzled/plugin/plugin.h"
 
29
#include "drizzled/table_identifier.h"
 
30
#include "drizzled/message/table.pb.h"
 
31
#include "drizzled/charset.h"
 
32
#include "drizzled/field.h"
 
33
 
 
34
#include <string>
 
35
#include <set>
 
36
 
 
37
namespace drizzled
 
38
{
 
39
 
 
40
extern int wild_case_compare(const CHARSET_INFO * const cs, 
 
41
                             const char *str,const char *wildstr);
 
42
 
 
43
namespace plugin
 
44
{
 
45
 
 
46
 
 
47
class TableFunction : public Plugin
 
48
{
 
49
  TableFunction();
 
50
  TableFunction(const TableFunction &);
 
51
  TableFunction& operator=(const TableFunction &);
 
52
 
 
53
  message::Table proto;
 
54
  TableIdentifier identifier;
 
55
  std::string local_path;
 
56
  std::string local_schema;
 
57
 
 
58
  void setName(); // init name
 
59
 
 
60
  void init();
 
61
 
 
62
public:
 
63
  TableFunction(const char *schema_arg, const char *table_arg) :
 
64
    Plugin(table_arg, "TableFunction"),
 
65
    identifier(schema_arg, table_arg)
 
66
  {
 
67
    init();
 
68
  }
 
69
 
 
70
  virtual ~TableFunction() {}
 
71
 
 
72
  static bool addPlugin(TableFunction *function);
 
73
  static void removePlugin(TableFunction *) 
 
74
  { }
 
75
  static TableFunction *getFunction(const std::string &arg);
 
76
  static void getNames(const std::string &arg,
 
77
                       std::set<std::string> &set_of_names);
 
78
 
 
79
  enum ColumnType {
 
80
    BOOLEAN,
 
81
    NUMBER,
 
82
    STRING
 
83
  };
 
84
 
 
85
  class Generator 
 
86
  {
 
87
    Field **columns;
 
88
    Field **columns_iterator;
 
89
 
 
90
  public:
 
91
    const CHARSET_INFO *scs;
 
92
 
 
93
    Generator(Field **arg);
 
94
    virtual ~Generator()
 
95
    { }
 
96
 
 
97
    /*
 
98
      Return type is bool meaning "are there more rows".
 
99
    */
 
100
    bool sub_populate(uint32_t field_size);
 
101
 
 
102
    virtual bool populate()
 
103
    {
 
104
      return false;
 
105
    }
 
106
 
 
107
    void push(uint64_t arg);
 
108
    void push(uint32_t arg);
 
109
    void push(int64_t arg);
 
110
    void push(int32_t arg);
 
111
    void push(const char *arg, uint32_t length= 0);
 
112
    void push(const std::string& arg);
 
113
    void push(bool arg);
 
114
    void push();
 
115
 
 
116
    bool isWild(const std::string &predicate);
 
117
  };
 
118
 
 
119
  void define(message::Table &arg)
 
120
  { 
 
121
    arg.CopyFrom(proto);
 
122
  }
 
123
 
 
124
  const std::string &getSchemaHome()
 
125
  { 
 
126
    if (local_schema.length() == 0)
 
127
    {
 
128
      local_schema= identifier.getSchemaName();
 
129
      transform(local_schema.begin(), local_schema.end(),
 
130
                local_schema.begin(), ::tolower);
 
131
    }
 
132
 
 
133
    return local_schema;
 
134
  }
 
135
 
 
136
  const std::string &getPath()
 
137
  { 
 
138
    if (local_path.length() == 0)
 
139
    {
 
140
      local_path= identifier.getPath();
 
141
      transform(local_path.begin(), local_path.end(),
 
142
                local_path.begin(), ::tolower);
 
143
    }
 
144
 
 
145
    return local_path;
 
146
  }
 
147
 
 
148
  virtual Generator *generator(Field **arg);
 
149
 
 
150
  void add_field(const char *label,
 
151
                 message::Table::Field::FieldType type,
 
152
                 uint32_t length= 0);
 
153
 
 
154
  void add_field(const char *label,
 
155
                 uint32_t field_length= 64);
 
156
 
 
157
  void add_field(const char *label,
 
158
                 TableFunction::ColumnType type,
 
159
                 bool is_default_null= true);
 
160
 
 
161
  void add_field(const char *label,
 
162
                 TableFunction::ColumnType type,
 
163
                 uint32_t field_length,
 
164
                 bool is_default_null= false);
 
165
};
 
166
 
 
167
} /* namespace plugin */
 
168
} /* namespace drizzled */
 
169
 
 
170
#endif /* DRIZZLED_PLUGIN_TABLE_FUNCTION_H */