~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.h

  • Committer: Jay Pipes
  • Date: 2009-01-30 04:01:12 UTC
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090130040112-svbn774guj98pwi4
To remain in compatibility with MySQL, added ability to interpret
decimal arguments as datetime strings for temporal functions.

Fixed YEAR(), MONTH(), DAYOFMONTH(), DAYOFYEAR(), HOUR(), MINUTE(), SECOND(), and MICROSECOND()
to accept decimal parameters and interpret them the same way as MySQL.

Fixed an issue with the TemporalFormat::matches() method which was 
incorrectly assuming all microsecond arguments were specified as 6 digits.
Added power of 10 multiplier to usecond calculation. This fixes issues with
failures in type_date and func_sapdb test cases.

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/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
 
#include <algorithm>
37
 
 
38
 
namespace drizzled
39
 
{
40
 
 
41
 
extern int wild_case_compare(const CHARSET_INFO * const cs, 
42
 
                             const char *str,const char *wildstr);
43
 
 
44
 
namespace plugin
45
 
{
46
 
 
47
 
#define TABLE_FUNCTION_BLOB_SIZE 2049
48
 
 
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
 
}
63
 
 
64
 
class TableFunction : public Plugin
65
 
{
66
 
  TableFunction();
67
 
  TableFunction(const TableFunction &);
68
 
  TableFunction& operator=(const TableFunction &);
69
 
 
70
 
  message::Table proto;
71
 
  TableIdentifier identifier;
72
 
  std::string local_path;
73
 
  std::string original_table_label;
74
 
 
75
 
  void setName(); // init name
76
 
 
77
 
  void init();
78
 
 
79
 
 
80
 
public:
81
 
  TableFunction(const char *schema_arg, const char *table_arg) :
82
 
    Plugin(local_string_append(schema_arg, table_arg) , "TableFunction"),
83
 
    identifier(schema_arg, table_arg),
84
 
    original_table_label(table_arg)
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,
101
 
    STRING,
102
 
    VARBINARY
103
 
  };
104
 
 
105
 
  class Generator 
106
 
  {
107
 
    Field **columns;
108
 
    Field **columns_iterator;
109
 
    Session *session;
110
 
 
111
 
  protected:
112
 
 
113
 
    drizzled::Session &getSession()
114
 
    {
115
 
      return *session;
116
 
    }
117
 
 
118
 
  public:
119
 
    const CHARSET_INFO *scs;
120
 
 
121
 
    Generator(Field **arg);
122
 
    virtual ~Generator()
123
 
    { }
124
 
 
125
 
    /*
126
 
      Return type is bool meaning "are there more rows".
127
 
    */
128
 
    bool sub_populate(uint32_t field_size);
129
 
 
130
 
    virtual bool populate()
131
 
    {
132
 
      return false;
133
 
    }
134
 
 
135
 
    void push(uint64_t arg);
136
 
    void push(int64_t arg);
137
 
    void push(const char *arg, uint32_t length= 0);
138
 
    void push(const std::string& arg);
139
 
    void push(bool arg);
140
 
    void push();
141
 
 
142
 
    bool isWild(const std::string &predicate);
143
 
  };
144
 
 
145
 
  void define(message::Table &arg)
146
 
  { 
147
 
    arg.CopyFrom(proto);
148
 
  }
149
 
 
150
 
  const std::string &getTableLabel()
151
 
  { 
152
 
    return original_table_label;
153
 
  }
154
 
 
155
 
  const std::string &getIdentifierTableName()
156
 
  { 
157
 
    return identifier.getTableName();
158
 
  }
159
 
 
160
 
  const std::string &getSchemaHome()
161
 
  { 
162
 
    return identifier.getSchemaName();
163
 
  }
164
 
 
165
 
  const std::string &getPath()
166
 
  { 
167
 
    return identifier.getPath();
168
 
  }
169
 
 
170
 
  virtual Generator *generator(Field **arg);
171
 
 
172
 
  void add_field(const char *label,
173
 
                 message::Table::Field::FieldType type,
174
 
                 uint32_t length= 0);
175
 
 
176
 
  void add_field(const char *label,
177
 
                 uint32_t field_length= MAXIMUM_IDENTIFIER_LENGTH);
178
 
 
179
 
  void add_field(const char *label,
180
 
                 TableFunction::ColumnType type,
181
 
                 bool is_default_null= true);
182
 
 
183
 
  void add_field(const char *label,
184
 
                 TableFunction::ColumnType type,
185
 
                 uint32_t field_length,
186
 
                 bool is_default_null= false);
187
 
 
188
 
  virtual bool visable() { return true; }
189
 
};
190
 
 
191
 
} /* namespace plugin */
192
 
} /* namespace drizzled */
193
 
 
194
 
#endif /* DRIZZLED_PLUGIN_TABLE_FUNCTION_H */