1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
22
#include "drizzled/plugin/info_schema_table.h"
23
#include "drizzled/gettext.h"
24
#include "drizzled/session.h"
25
#include "drizzled/lex_string.h"
35
const std::string INFORMATION_SCHEMA_NAME("information_schema");
37
vector<plugin::InfoSchemaTable *> all_schema_tables;
40
plugin::InfoSchemaRecord::InfoSchemaRecord()
46
plugin::InfoSchemaRecord::InfoSchemaRecord(unsigned char *buf, size_t in_len)
47
: record(new unsigned char[in_len]),
51
memcpy(record, buf, rec_len);
52
checksum= algorithm::crc32((const char *) record, rec_len);
55
plugin::InfoSchemaRecord::InfoSchemaRecord(const plugin::InfoSchemaRecord &rhs)
56
: record(new(std::nothrow) unsigned char[rhs.rec_len]),
59
memcpy(record, rhs.record, rec_len);
60
checksum= algorithm::crc32((const char *) record, rec_len);
63
bool plugin::InfoSchemaTable::addPlugin(plugin::InfoSchemaTable *schema_table)
65
if (schema_table->getFirstColumnIndex() == 0)
66
schema_table->setFirstColumnIndex(-1);
67
if (schema_table->getSecondColumnIndex() == 0)
68
schema_table->setSecondColumnIndex(-1);
70
all_schema_tables.push_back(schema_table);
74
void plugin::InfoSchemaTable::removePlugin(plugin::InfoSchemaTable *table)
76
all_schema_tables.erase(remove_if(all_schema_tables.begin(),
77
all_schema_tables.end(),
78
bind2nd(equal_to<plugin::InfoSchemaTable *>(),
80
all_schema_tables.end());
84
class AddSchemaTable : public unary_function<plugin::InfoSchemaTable *, bool>
88
vector<LEX_STRING*> &files;
91
AddSchemaTable(Session *session_arg, vector<LEX_STRING*> &files_arg, const char *wild_arg)
92
: session(session_arg), wild(wild_arg), files(files_arg)
95
result_type operator() (argument_type schema_table)
97
if (schema_table->isHidden())
102
const string &schema_table_name= schema_table->getTableName();
104
if (wild && wild_case_compare(files_charset_info, schema_table_name.c_str(), wild))
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)
117
files.push_back(file_name);
122
class FindSchemaTableByName : public unary_function<plugin::InfoSchemaTable *, bool>
124
const char *table_name;
126
FindSchemaTableByName(const char *table_name_arg)
127
: table_name(table_name_arg) {}
128
result_type operator() (argument_type schema_table)
130
return ! my_strcasecmp(system_charset_info,
131
schema_table->getTableName().c_str(),
136
plugin::InfoSchemaTable *plugin::InfoSchemaTable::getTable(const char *table_name)
138
vector<plugin::InfoSchemaTable *>::iterator iter=
139
find_if(all_schema_tables.begin(),
140
all_schema_tables.end(),
141
FindSchemaTableByName(table_name));
143
if (iter != all_schema_tables.end())
152
void plugin::InfoSchemaTable::getTableNames(set<string>& tables_names)
154
for (vector<plugin::InfoSchemaTable *>::iterator iter= all_schema_tables.begin();
155
iter != all_schema_tables.end();
158
if ((*iter)->isHidden() == false)
159
tables_names.insert((*iter)->getTableName().c_str());
163
int plugin::InfoSchemaTable::addTableToList(Session *session,
164
vector<LEX_STRING*> &files,
168
vector<plugin::InfoSchemaTable *>::iterator iter=
169
find_if(all_schema_tables.begin(),
170
all_schema_tables.end(),
171
AddSchemaTable(session, files, wild));
173
if (iter != all_schema_tables.end())
181
} /* namespace drizzled */