~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/info_schema_table.cc

  • Committer: Brian Aker
  • Date: 2010-02-25 07:54:52 UTC
  • mfrom: (1273.13.101 build)
  • Revision ID: brian@gaz-20100225075452-19eozreshbrerypu
Merge of all patches in build.

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
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
#include "drizzled/plugin/info_schema_table.h"
23
 
#include "drizzled/gettext.h"
24
 
#include "drizzled/session.h"
25
 
#include "drizzled/lex_string.h"
26
 
 
27
 
#include <cstring>
28
 
#include <vector>
29
 
 
30
 
using namespace std;
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
const std::string INFORMATION_SCHEMA_NAME("information_schema");
36
 
 
37
 
vector<plugin::InfoSchemaTable *> all_schema_tables;
38
 
 
39
 
 
40
 
plugin::InfoSchemaRecord::InfoSchemaRecord()
41
 
  : record(NULL),
42
 
    rec_len(0),
43
 
    checksum(0)
44
 
{}
45
 
 
46
 
plugin::InfoSchemaRecord::InfoSchemaRecord(unsigned char *buf, size_t in_len)
47
 
  : record(new unsigned char[in_len]),
48
 
    rec_len(in_len),
49
 
    checksum(0)
50
 
{
51
 
  memcpy(record, buf, rec_len);
52
 
  checksum= algorithm::crc32((const char *) record, rec_len);
53
 
}
54
 
 
55
 
plugin::InfoSchemaRecord::InfoSchemaRecord(const plugin::InfoSchemaRecord &rhs)
56
 
  : record(new(std::nothrow) unsigned char[rhs.rec_len]),
57
 
    rec_len(rhs.rec_len)
58
 
{
59
 
  memcpy(record, rhs.record, rec_len);
60
 
  checksum= algorithm::crc32((const char *) record, rec_len);
61
 
}
62
 
 
63
 
bool plugin::InfoSchemaTable::addPlugin(plugin::InfoSchemaTable *schema_table)
64
 
{
65
 
  if (schema_table->getFirstColumnIndex() == 0)
66
 
    schema_table->setFirstColumnIndex(-1);
67
 
  if (schema_table->getSecondColumnIndex() == 0)
68
 
   schema_table->setSecondColumnIndex(-1);
69
 
 
70
 
  all_schema_tables.push_back(schema_table);
71
 
  return false;
72
 
}
73
 
 
74
 
void plugin::InfoSchemaTable::removePlugin(plugin::InfoSchemaTable *table)
75
 
{
76
 
  all_schema_tables.erase(remove_if(all_schema_tables.begin(),
77
 
                                    all_schema_tables.end(),
78
 
                                    bind2nd(equal_to<plugin::InfoSchemaTable *>(),
79
 
                                            table)),
80
 
                          all_schema_tables.end());
81
 
}
82
 
 
83
 
 
84
 
class AddSchemaTable : public unary_function<plugin::InfoSchemaTable *, bool>
85
 
{
86
 
  Session *session;
87
 
  const char *wild;
88
 
  vector<LEX_STRING*> &files;
89
 
 
90
 
public:
91
 
  AddSchemaTable(Session *session_arg, vector<LEX_STRING*> &files_arg, const char *wild_arg)
92
 
    : session(session_arg), wild(wild_arg), files(files_arg)
93
 
  {}
94
 
 
95
 
  result_type operator() (argument_type schema_table)
96
 
  {
97
 
    if (schema_table->isHidden())
98
 
    {
99
 
      return false;
100
 
    }
101
 
 
102
 
    const string &schema_table_name= schema_table->getTableName();
103
 
 
104
 
    if (wild && wild_case_compare(files_charset_info, schema_table_name.c_str(), wild))
105
 
    {
106
 
      return false;
107
 
    }
108
 
 
109
 
    LEX_STRING *file_name= 0;
110
 
    file_name= session->make_lex_string(file_name, schema_table_name.c_str(),
111
 
                                        schema_table_name.length(), true);
112
 
    if (file_name == NULL)
113
 
    {
114
 
      return true;
115
 
    }
116
 
 
117
 
    files.push_back(file_name);
118
 
    return false;
119
 
  }
120
 
};
121
 
 
122
 
class FindSchemaTableByName : public unary_function<plugin::InfoSchemaTable *, bool>
123
 
{
124
 
  const char *table_name;
125
 
public:
126
 
  FindSchemaTableByName(const char *table_name_arg)
127
 
    : table_name(table_name_arg) {}
128
 
  result_type operator() (argument_type schema_table)
129
 
  {
130
 
    return ! my_strcasecmp(system_charset_info,
131
 
                           schema_table->getTableName().c_str(),
132
 
                           table_name);
133
 
  }
134
 
};
135
 
 
136
 
plugin::InfoSchemaTable *plugin::InfoSchemaTable::getTable(const char *table_name)
137
 
{
138
 
  vector<plugin::InfoSchemaTable *>::iterator iter=
139
 
    find_if(all_schema_tables.begin(),
140
 
            all_schema_tables.end(),
141
 
            FindSchemaTableByName(table_name));
142
 
 
143
 
  if (iter != all_schema_tables.end())
144
 
  {
145
 
    return *iter;
146
 
  }
147
 
 
148
 
  return NULL;
149
 
 
150
 
}
151
 
 
152
 
void plugin::InfoSchemaTable::getTableNames(set<string>& tables_names)
153
 
{
154
 
  for (vector<plugin::InfoSchemaTable *>::iterator iter= all_schema_tables.begin();
155
 
       iter != all_schema_tables.end();
156
 
       iter++)
157
 
  {
158
 
    if ((*iter)->isHidden() == false)
159
 
      tables_names.insert((*iter)->getTableName().c_str());
160
 
  }
161
 
}
162
 
 
163
 
int plugin::InfoSchemaTable::addTableToList(Session *session,
164
 
                                     vector<LEX_STRING*> &files,
165
 
                                     const char *wild)
166
 
{
167
 
 
168
 
  vector<plugin::InfoSchemaTable *>::iterator iter=
169
 
    find_if(all_schema_tables.begin(),
170
 
            all_schema_tables.end(),
171
 
            AddSchemaTable(session, files, wild));
172
 
 
173
 
  if (iter != all_schema_tables.end())
174
 
  {
175
 
    return 1;
176
 
  }
177
 
 
178
 
  return 0;
179
 
}
180
 
 
181
 
} /* namespace drizzled */