~jaypipes/drizzle/split-xa-resource-manager

« back to all changes in this revision

Viewing changes to plugin/info_schema/open_tables.cc

  • Committer: Jay Pipes
  • Date: 2010-02-14 20:26:43 UTC
  • mfrom: (1273.1.27 staging)
  • Revision ID: jpipes@serialcoder-20100214202643-ahuqvc8rhn8u7y33
Merge trunk and resolve conflicts

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