~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/info_schema_table.cc

pandora-build v0.71. Added check for avahi.

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
bool plugin::InfoSchemaTable::addPlugin(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
  return false;
 
46
}
 
47
 
 
48
void plugin::InfoSchemaTable::removePlugin(plugin::InfoSchemaTable *table)
 
49
{
 
50
  all_schema_tables.erase(remove_if(all_schema_tables.begin(),
 
51
                                    all_schema_tables.end(),
 
52
                                    bind2nd(equal_to<plugin::InfoSchemaTable *>(),
 
53
                                            table)),
 
54
                          all_schema_tables.end());
 
55
}
 
56
 
 
57
 
 
58
class AddSchemaTable : public unary_function<plugin::InfoSchemaTable *, bool>
 
59
{
 
60
  Session *session;
 
61
  const char *wild;
 
62
  vector<LEX_STRING*> &files;
 
63
 
 
64
public:
 
65
  AddSchemaTable(Session *session_arg, vector<LEX_STRING*> &files_arg, const char *wild_arg)
 
66
    : session(session_arg), wild(wild_arg), files(files_arg)
 
67
  {}
 
68
 
 
69
  result_type operator() (argument_type schema_table)
 
70
  {
 
71
    if (schema_table->isHidden())
 
72
    {
 
73
      return false;
 
74
    }
 
75
 
 
76
    const string &schema_table_name= schema_table->getTableName();
 
77
 
 
78
    if (wild && wild_case_compare(files_charset_info, schema_table_name.c_str(), wild))
 
79
    {
 
80
      return false;
 
81
    }
 
82
 
 
83
    LEX_STRING *file_name= 0;
 
84
    file_name= session->make_lex_string(file_name, schema_table_name.c_str(),
 
85
                                        schema_table_name.length(), true);
 
86
    if (file_name == NULL)
 
87
    {
 
88
      return true;
 
89
    }
 
90
 
 
91
    files.push_back(file_name);
 
92
    return false;
 
93
  }
 
94
};
 
95
 
 
96
class FindSchemaTableByName : public unary_function<plugin::InfoSchemaTable *, bool>
 
97
{
 
98
  const char *table_name;
 
99
public:
 
100
  FindSchemaTableByName(const char *table_name_arg)
 
101
    : table_name(table_name_arg) {}
 
102
  result_type operator() (argument_type schema_table)
 
103
  {
 
104
    return ! my_strcasecmp(system_charset_info,
 
105
                           schema_table->getTableName().c_str(),
 
106
                           table_name);
 
107
  }
 
108
};
 
109
 
 
110
plugin::InfoSchemaTable *plugin::InfoSchemaTable::getTable(const char *table_name)
 
111
{
 
112
  vector<plugin::InfoSchemaTable *>::iterator iter=
 
113
    find_if(all_schema_tables.begin(),
 
114
            all_schema_tables.end(),
 
115
            FindSchemaTableByName(table_name));
 
116
 
 
117
  if (iter != all_schema_tables.end())
 
118
  {
 
119
    return *iter;
 
120
  }
 
121
 
 
122
  return NULL;
 
123
 
 
124
}
 
125
 
 
126
void plugin::InfoSchemaTable::getTableNames(set<string>& tables_names)
 
127
{
 
128
  for (vector<plugin::InfoSchemaTable *>::iterator iter= all_schema_tables.begin();
 
129
       iter != all_schema_tables.end();
 
130
       iter++)
 
131
  {
 
132
    if ((*iter)->isHidden() == false)
 
133
      tables_names.insert((*iter)->getTableName().c_str());
 
134
  }
 
135
}
 
136
 
 
137
int plugin::InfoSchemaTable::addTableToList(Session *session,
 
138
                                     vector<LEX_STRING*> &files,
 
139
                                     const char *wild)
 
140
{
 
141
 
 
142
  vector<plugin::InfoSchemaTable *>::iterator iter=
 
143
    find_if(all_schema_tables.begin(),
 
144
            all_schema_tables.end(),
 
145
            AddSchemaTable(session, files, wild));
 
146
 
 
147
  if (iter != all_schema_tables.end())
 
148
  {
 
149
    return 1;
 
150
  }
 
151
 
 
152
  return 0;
 
153
}
 
154
 
 
155
} /* namespace drizzled */