~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.h

  • Committer: Monty Taylor
  • Date: 2010-03-06 02:08:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1381.
  • Revision ID: mordred@inaugust.com-20100306020813-c37d0b39004nl1zf
Remove plugin deinit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 *  Definitions required for TableFunction plugin
5
5
 *
6
 
 *  Copyright (C) 2010 Sun Microsystems, Inc.
 
6
 *  Copyright (C) 2010 Sun Microsystems
7
7
 *  Copyright (C) 2010 Monty Taylor
8
8
 *
9
9
 *  This program is free software; you can redistribute it and/or modify
24
24
#define DRIZZLED_PLUGIN_TABLE_FUNCTION_H
25
25
 
26
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>
 
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
33
 
34
34
#include <string>
35
35
#include <set>
36
36
#include <algorithm>
37
37
 
38
 
#include <drizzled/visibility.h>
39
 
 
40
38
namespace drizzled
41
39
{
42
40
 
 
41
extern int wild_case_compare(const CHARSET_INFO * const cs, 
 
42
                             const char *str,const char *wildstr);
 
43
 
43
44
namespace plugin
44
45
{
45
46
 
46
 
#define TABLE_FUNCTION_BLOB_SIZE 2049
47
 
 
48
 
// Not thread safe, but plugins are just loaded in a single thread right
49
 
// now.
50
 
static const char *local_string_append(const char *arg1, const char *arg2)
51
 
{
52
 
  static char buffer[1024];
53
 
  char *buffer_ptr= buffer;
54
 
  strcpy(buffer_ptr, arg1);
55
 
  buffer_ptr+= strlen(arg1);
56
 
  buffer_ptr[0]= '-';
57
 
  buffer_ptr++;
58
 
  strcpy(buffer_ptr, arg2);
59
 
 
60
 
  return buffer;
61
 
}
62
 
 
63
 
class DRIZZLED_API TableFunction : public Plugin
 
47
 
 
48
class TableFunction : public Plugin
64
49
{
65
50
  TableFunction();
66
51
  TableFunction(const TableFunction &);
67
52
  TableFunction& operator=(const TableFunction &);
68
53
 
69
54
  message::Table proto;
70
 
  identifier::Table identifier;
 
55
  TableIdentifier identifier;
71
56
  std::string local_path;
72
 
  std::string original_table_label;
 
57
  std::string local_schema;
73
58
 
74
59
  void setName(); // init name
75
60
 
76
61
  void init();
77
62
 
78
 
 
79
63
public:
80
64
  TableFunction(const char *schema_arg, const char *table_arg) :
81
 
    Plugin(local_string_append(schema_arg, table_arg) , "TableFunction"),
82
 
    identifier(schema_arg, table_arg),
83
 
    original_table_label(table_arg)
 
65
    Plugin(table_arg, "TableFunction"),
 
66
    identifier(schema_arg, table_arg)
84
67
  {
85
68
    init();
86
69
  }
97
80
  enum ColumnType {
98
81
    BOOLEAN,
99
82
    NUMBER,
100
 
    STRING,
101
 
    VARBINARY,
102
 
    SIZE
 
83
    STRING
103
84
  };
104
85
 
105
86
  class Generator 
106
87
  {
107
88
    Field **columns;
108
89
    Field **columns_iterator;
109
 
    Session *session;
110
 
 
111
 
  protected:
112
 
 
113
 
    drizzled::Session &getSession()
114
 
    {
115
 
      return *session;
116
 
    }
117
90
 
118
91
  public:
119
92
    const CHARSET_INFO *scs;
147
120
    arg.CopyFrom(proto);
148
121
  }
149
122
 
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
123
  const std::string &getSchemaHome()
161
124
  { 
162
 
    return identifier.getSchemaName();
 
125
    if (local_schema.length() == 0)
 
126
    {
 
127
      local_schema= identifier.getSchemaName();
 
128
      std::transform(local_schema.begin(), local_schema.end(),
 
129
                     local_schema.begin(), ::tolower);
 
130
    }
 
131
 
 
132
    return local_schema;
163
133
  }
164
134
 
165
135
  const std::string &getPath()
166
136
  { 
167
 
    return identifier.getPath();
 
137
    if (local_path.length() == 0)
 
138
    {
 
139
      local_path= identifier.getPath();
 
140
      std::transform(local_path.begin(), local_path.end(),
 
141
                     local_path.begin(), ::tolower);
 
142
    }
 
143
 
 
144
    return local_path;
168
145
  }
169
146
 
170
147
  virtual Generator *generator(Field **arg);
174
151
                 uint32_t length= 0);
175
152
 
176
153
  void add_field(const char *label,
177
 
                 uint32_t field_length= MAXIMUM_IDENTIFIER_LENGTH);
 
154
                 uint32_t field_length= 64);
178
155
 
179
156
  void add_field(const char *label,
180
157
                 TableFunction::ColumnType type,
184
161
                 TableFunction::ColumnType type,
185
162
                 uint32_t field_length,
186
163
                 bool is_default_null= false);
187
 
 
188
 
  virtual bool visable() { return true; }
189
164
};
190
165
 
191
166
} /* namespace plugin */