~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/open_tables.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 23:28:30 UTC
  • mfrom: (1215.2.25 is-split)
  • Revision ID: brian@gaz-20091118232830-v28y7o26squz3c9c
Merge of Padraig

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) 2009 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
/**
 
22
 * @file 
 
23
 *   Open tables I_S table methods.
 
24
 */
 
25
 
 
26
#include "drizzled/server_includes.h"
 
27
#include "drizzled/session.h"
 
28
#include "drizzled/show.h"
 
29
 
 
30
#include "helper_methods.h"
 
31
#include "open_tables.h"
 
32
 
 
33
#include <vector>
 
34
 
 
35
using namespace drizzled;
 
36
using namespace std;
 
37
 
 
38
/*
 
39
 * Vectors of columns for the open tables I_S table.
 
40
 */
 
41
static vector<const plugin::ColumnInfo *> *columns= NULL;
 
42
 
 
43
/*
 
44
 * Methods for the open tables I_S table.
 
45
 */
 
46
static plugin::InfoSchemaMethods *methods= NULL;
 
47
 
 
48
/*
 
49
 * open tables I_S table.
 
50
 */
 
51
static plugin::InfoSchemaTable *open_tabs_table= NULL;
 
52
 
 
53
/**
 
54
 * Populate the vectors of columns for the I_S table.
 
55
 *
 
56
 * @return a pointer to a std::vector of Columns.
 
57
 */
 
58
vector<const plugin::ColumnInfo *> *OpenTablesIS::createColumns()
 
59
{
 
60
  if (columns == NULL)
 
61
  {
 
62
    columns= new vector<const plugin::ColumnInfo *>;
 
63
  }
 
64
  else
 
65
  {
 
66
    clearColumns(*columns);
 
67
  }
 
68
 
 
69
  columns->push_back(new plugin::ColumnInfo("Database",
 
70
                                            NAME_CHAR_LEN,
 
71
                                            DRIZZLE_TYPE_VARCHAR,
 
72
                                            0,
 
73
                                            0,
 
74
                                            "Database",
 
75
                                            SKIP_OPEN_TABLE));
 
76
 
 
77
  columns->push_back(new plugin::ColumnInfo("Table",
 
78
                                            NAME_CHAR_LEN,
 
79
                                            DRIZZLE_TYPE_VARCHAR,
 
80
                                            0,
 
81
                                            0,
 
82
                                            "Table",
 
83
                                            SKIP_OPEN_TABLE));
 
84
 
 
85
  columns->push_back(new plugin::ColumnInfo("In_use",
 
86
                                            1,
 
87
                                            DRIZZLE_TYPE_LONGLONG,
 
88
                                            0,
 
89
                                            0,
 
90
                                            "In_use",
 
91
                                            SKIP_OPEN_TABLE));
 
92
 
 
93
  columns->push_back(new plugin::ColumnInfo("Name_locked",
 
94
                                            4,
 
95
                                            DRIZZLE_TYPE_LONGLONG,
 
96
                                            0,
 
97
                                            0,
 
98
                                            "Name_locked",
 
99
                                            SKIP_OPEN_TABLE));
 
100
 
 
101
  return columns;
 
102
}
 
103
 
 
104
/**
 
105
 * Initialize the I_S table.
 
106
 *
 
107
 * @return a pointer to an I_S table
 
108
 */
 
109
plugin::InfoSchemaTable *OpenTablesIS::getTable()
 
110
{
 
111
  columns= createColumns();
 
112
 
 
113
  if (methods == NULL)
 
114
  {
 
115
    methods= new OpenTablesISMethods();
 
116
  }
 
117
 
 
118
  if (open_tabs_table == NULL)
 
119
  {
 
120
    open_tabs_table= new plugin::InfoSchemaTable("OPEN_TABLES",
 
121
                                                 *columns,
 
122
                                                 -1, -1, true, false, 0,
 
123
                                                 methods);
 
124
  }
 
125
 
 
126
  return open_tabs_table;
 
127
}
 
128
 
 
129
/**
 
130
 * Delete memory allocated for the table, columns and methods.
 
131
 */
 
132
void OpenTablesIS::cleanup()
 
133
{
 
134
  clearColumns(*columns);
 
135
  delete open_tabs_table;
 
136
  delete methods;
 
137
  delete columns;
 
138
}
 
139
 
 
140
inline bool open_list_store(Table *table, open_table_list_st& open_list);
 
141
inline bool open_list_store(Table *table, open_table_list_st& open_list)
 
142
{
 
143
  table->restoreRecordAsDefault();
 
144
  table->field[0]->store(open_list.db.c_str(), open_list.db.length(), system_charset_info);
 
145
  table->field[1]->store(open_list.table.c_str(), open_list.table.length(), system_charset_info);
 
146
  table->field[2]->store((int64_t) open_list.in_use, true);
 
147
  table->field[3]->store((int64_t) open_list.locked, true);
 
148
  if (schema_table_store_record(table->in_use, table))
 
149
    return true;
 
150
 
 
151
  return false;
 
152
}
 
153
 
 
154
int OpenTablesISMethods::fillTable(Session *session, TableList *tables)
 
155
{
 
156
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
 
157
 
 
158
  if ((list_open_tables(session->lex->select_lex.db, wild, open_list_store, tables->table) == true) && session->is_fatal_error)
 
159
    return 1;
 
160
 
 
161
  return 0;
 
162
}
 
163