~drizzle-trunk/drizzle/development

1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
6
 *  Copyright (C) 2010 Sun Microsystems, Inc.
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
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
1273.13.49 by Brian Aker
Does not work (compile issue in plugin).
26
#include <drizzled/definitions.h>
27
#include "drizzled/plugin.h"
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
28
#include "drizzled/plugin/plugin.h"
1660.1.1 by Brian Aker
Merge in move identifier work.
29
#include "drizzled/identifier.h"
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
30
#include "drizzled/message/table.pb.h"
31
#include "drizzled/charset.h"
32
#include "drizzled/field.h"
33
34
#include <string>
35
#include <set>
1273.23.4 by Monty Taylor
Added include so that transform works on Sun Studio.
36
#include <algorithm>
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
37
1273.14.5 by Monty Taylor
Merged trunk.
38
namespace drizzled
39
{
40
1273.13.38 by Brian Aker
Add in new show work.
41
extern int wild_case_compare(const CHARSET_INFO * const cs, 
42
                             const char *str,const char *wildstr);
43
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
44
namespace plugin
45
{
46
1812.5.5 by Brian Aker
Added in possibility of having a blob type returned by a TableFunction.
47
#define TABLE_FUNCTION_BLOB_SIZE 2049
48
1340.1.5 by Brian Aker
Update, we now have all of the ANSI INFORMATION_SCHEMA listed.
49
// Not thread safe, but plugins are just loaded in a single thread right
50
// now.
51
static const char *local_string_append(const char *arg1, const char *arg2)
52
{
53
  static char buffer[1024];
54
  char *buffer_ptr= buffer;
55
  strcpy(buffer_ptr, arg1);
56
  buffer_ptr+= strlen(arg1);
57
  buffer_ptr[0]= '-';
58
  buffer_ptr++;
59
  strcpy(buffer_ptr, arg2);
60
61
  return buffer;
62
}
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
63
64
class TableFunction : public Plugin
65
{
66
  TableFunction();
67
  TableFunction(const TableFunction &);
68
  TableFunction& operator=(const TableFunction &);
69
1273.14.5 by Monty Taylor
Merged trunk.
70
  message::Table proto;
71
  TableIdentifier identifier;
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
72
  std::string local_path;
1340.1.5 by Brian Aker
Update, we now have all of the ANSI INFORMATION_SCHEMA listed.
73
  std::string original_table_label;
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
74
75
  void setName(); // init name
76
77
  void init();
78
1874.2.4 by Brian Aker
Have show functions be invisible.
79
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
80
public:
81
  TableFunction(const char *schema_arg, const char *table_arg) :
1340.1.5 by Brian Aker
Update, we now have all of the ANSI INFORMATION_SCHEMA listed.
82
    Plugin(local_string_append(schema_arg, table_arg) , "TableFunction"),
83
    identifier(schema_arg, table_arg),
84
    original_table_label(table_arg)
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
85
  {
86
    init();
87
  }
88
89
  virtual ~TableFunction() {}
90
91
  static bool addPlugin(TableFunction *function);
92
  static void removePlugin(TableFunction *) 
93
  { }
94
  static TableFunction *getFunction(const std::string &arg);
95
  static void getNames(const std::string &arg,
96
                       std::set<std::string> &set_of_names);
97
98
  enum ColumnType {
99
    BOOLEAN,
100
    NUMBER,
1337.1.2 by Stewart Smith
make DATA_DICTIONARY.COLUMNS.COLUMN_DEFAULT be a VARBINARY column that can be null. Add a test for binary default values as well as non-binary default values.
101
    STRING,
2008.2.4 by Brian Aker
Merge in additional fixes for sign, plus alter table, plus TIME on
102
    VARBINARY,
103
    SIZE
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
104
  };
105
106
  class Generator 
107
  {
108
    Field **columns;
109
    Field **columns_iterator;
1436 by Brian Aker
Move toward not having to call current_session (first pass).
110
    Session *session;
111
112
  protected:
113
114
    drizzled::Session &getSession()
115
    {
116
      return *session;
117
    }
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
118
119
  public:
120
    const CHARSET_INFO *scs;
121
122
    Generator(Field **arg);
123
    virtual ~Generator()
124
    { }
125
126
    /*
127
      Return type is bool meaning "are there more rows".
128
    */
1273.13.44 by Brian Aker
Updates/bug fix for columns. Assert now for checking that we filled in all
129
    bool sub_populate(uint32_t field_size);
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
130
131
    virtual bool populate()
132
    {
133
      return false;
134
    }
135
1300.1.3 by Monty Taylor
Fixed osx build without templates.
136
    void push(uint64_t arg);
137
    void push(int64_t arg);
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
138
    void push(const char *arg, uint32_t length= 0);
1302.2.1 by Monty Taylor
Fixed the OSX build issues.
139
    void push(const std::string& arg);
1300.1.3 by Monty Taylor
Fixed osx build without templates.
140
    void push(bool arg);
1273.13.45 by Brian Aker
Update for test split.
141
    void push();
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
142
1273.13.38 by Brian Aker
Add in new show work.
143
    bool isWild(const std::string &predicate);
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
144
  };
145
1273.14.5 by Monty Taylor
Merged trunk.
146
  void define(message::Table &arg)
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
147
  { 
148
    arg.CopyFrom(proto);
149
  }
150
1340.1.5 by Brian Aker
Update, we now have all of the ANSI INFORMATION_SCHEMA listed.
151
  const std::string &getTableLabel()
152
  { 
153
    return original_table_label;
154
  }
155
156
  const std::string &getIdentifierTableName()
157
  { 
1669.3.3 by Brian Aker
Remove the need for tolower in retrieval of table functions.
158
    return identifier.getTableName();
1340.1.5 by Brian Aker
Update, we now have all of the ANSI INFORMATION_SCHEMA listed.
159
  }
160
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
161
  const std::string &getSchemaHome()
162
  { 
1669.3.3 by Brian Aker
Remove the need for tolower in retrieval of table functions.
163
    return identifier.getSchemaName();
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
164
  }
165
166
  const std::string &getPath()
167
  { 
1669.3.3 by Brian Aker
Remove the need for tolower in retrieval of table functions.
168
    return identifier.getPath();
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
169
  }
170
171
  virtual Generator *generator(Field **arg);
172
173
  void add_field(const char *label,
1273.14.5 by Monty Taylor
Merged trunk.
174
                 message::Table::Field::FieldType type,
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
175
                 uint32_t length= 0);
176
177
  void add_field(const char *label,
1567.1.1 by Brian Aker
This fixes bug 586009, increases the size of the log files so that the UNION
178
                 uint32_t field_length= MAXIMUM_IDENTIFIER_LENGTH);
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
179
180
  void add_field(const char *label,
181
                 TableFunction::ColumnType type,
1273.13.45 by Brian Aker
Update for test split.
182
                 bool is_default_null= true);
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
183
184
  void add_field(const char *label,
185
                 TableFunction::ColumnType type,
186
                 uint32_t field_length,
187
                 bool is_default_null= false);
1874.2.4 by Brian Aker
Have show functions be invisible.
188
189
  virtual bool visable() { return true; }
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
190
};
191
192
} /* namespace plugin */
193
} /* namespace drizzled */
194
195
#endif /* DRIZZLED_PLUGIN_TABLE_FUNCTION_H */