~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/info_schema_table.cc

Merged in latest plugin-slot-reorg.

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 "drizzled/server_includes.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 <vector>
 
28
 
 
29
using namespace std;
 
30
 
 
31
namespace drizzled
 
32
{
 
33
 
 
34
vector<plugin::InfoSchemaTable *> all_schema_tables;
 
35
 
 
36
 
 
37
void plugin::InfoSchemaTable::add(plugin::InfoSchemaTable *schema_table)
 
38
{
 
39
  if (schema_table->getFirstColumnIndex() == 0)
 
40
    schema_table->setFirstColumnIndex(-1);
 
41
  if (schema_table->getSecondColumnIndex() == 0)
 
42
   schema_table->setSecondColumnIndex(-1);
 
43
 
 
44
  all_schema_tables.push_back(schema_table);
 
45
}
 
46
 
 
47
void plugin::InfoSchemaTable::remove(plugin::InfoSchemaTable *table)
 
48
{
 
49
  all_schema_tables.erase(remove_if(all_schema_tables.begin(),
 
50
                                    all_schema_tables.end(),
 
51
                                    bind2nd(equal_to<plugin::InfoSchemaTable *>(),
 
52
                                            table)),
 
53
                          all_schema_tables.end());
 
54
}
 
55
 
 
56
 
 
57
class AddSchemaTable : public unary_function<plugin::InfoSchemaTable *, bool>
 
58
{
 
59
  Session *session;
 
60
  const char *wild;
 
61
  vector<LEX_STRING*> &files;
 
62
 
 
63
public:
 
64
  AddSchemaTable(Session *session_arg, vector<LEX_STRING*> &files_arg, const char *wild_arg)
 
65
    : session(session_arg), wild(wild_arg), files(files_arg)
 
66
  {}
 
67
 
 
68
  result_type operator() (argument_type schema_table)
 
69
  {
 
70
    if (schema_table->isHidden())
 
71
    {
 
72
      return false;
 
73
    }
 
74
 
 
75
    const string &schema_table_name= schema_table->getTableName();
 
76
 
 
77
    if (wild && wild_case_compare(files_charset_info, schema_table_name.c_str(), wild))
 
78
    {
 
79
      return false;
 
80
    }
 
81
 
 
82
    LEX_STRING *file_name= 0;
 
83
    file_name= session->make_lex_string(file_name, schema_table_name.c_str(),
 
84
                                        schema_table_name.length(), true);
 
85
    if (file_name == NULL)
 
86
    {
 
87
      return true;
 
88
    }
 
89
 
 
90
    files.push_back(file_name);
 
91
    return false;
 
92
  }
 
93
};
 
94
 
 
95
class FindSchemaTableByName : public unary_function<plugin::InfoSchemaTable *, bool>
 
96
{
 
97
  const char *table_name;
 
98
public:
 
99
  FindSchemaTableByName(const char *table_name_arg)
 
100
    : table_name(table_name_arg) {}
 
101
  result_type operator() (argument_type schema_table)
 
102
  {
 
103
    return ! my_strcasecmp(system_charset_info,
 
104
                           schema_table->getTableName().c_str(),
 
105
                           table_name);
 
106
  }
 
107
};
 
108
 
 
109
plugin::InfoSchemaTable *plugin::InfoSchemaTable::getTable(const char *table_name)
 
110
{
 
111
  vector<plugin::InfoSchemaTable *>::iterator iter=
 
112
    find_if(all_schema_tables.begin(),
 
113
            all_schema_tables.end(),
 
114
            FindSchemaTableByName(table_name));
 
115
 
 
116
  if (iter != all_schema_tables.end())
 
117
  {
 
118
    return *iter;
 
119
  }
 
120
 
 
121
  return NULL;
 
122
 
 
123
}
 
124
 
 
125
 
 
126
int plugin::InfoSchemaTable::addTableToList(Session *session,
 
127
                                     vector<LEX_STRING*> &files,
 
128
                                     const char *wild)
 
129
{
 
130
 
 
131
  vector<plugin::InfoSchemaTable *>::iterator iter=
 
132
    find_if(all_schema_tables.begin(),
 
133
            all_schema_tables.end(),
 
134
            AddSchemaTable(session, files, wild));
 
135
 
 
136
  if (iter != all_schema_tables.end())
 
137
  {
 
138
    return 1;
 
139
  }
 
140
 
 
141
  return 0;
 
142
}
 
143
 
 
144
} /* namespace drizzled */