1215.2.18
by Padraig O'Sullivan
Moved the table names I_S table into its own header and implementation |
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 |
* table names I_S table methods.
|
|
24 |
*/
|
|
25 |
||
26 |
#include "drizzled/server_includes.h" |
|
27 |
#include "drizzled/session.h" |
|
28 |
#include "drizzled/show.h" |
|
29 |
#include "drizzled/tztime.h" |
|
30 |
||
1215.2.22
by Padraig O'Sullivan
Removed the info_schema_methods files and created a helper_methods header |
31 |
#include "helper_methods.h" |
1215.2.18
by Padraig O'Sullivan
Moved the table names I_S table into its own header and implementation |
32 |
#include "table_names.h" |
33 |
||
34 |
#include <vector> |
|
35 |
||
36 |
using namespace drizzled; |
|
37 |
using namespace std; |
|
38 |
||
39 |
/*
|
|
40 |
* Vectors of columns for the table names I_S table.
|
|
41 |
*/
|
|
42 |
static vector<const plugin::ColumnInfo *> *columns= NULL; |
|
43 |
||
44 |
/*
|
|
45 |
* Methods for the table names I_S table.
|
|
46 |
*/
|
|
47 |
static plugin::InfoSchemaMethods *methods= NULL; |
|
48 |
||
49 |
/*
|
|
50 |
* table names I_S table.
|
|
51 |
*/
|
|
52 |
static plugin::InfoSchemaTable *tn_table= NULL; |
|
53 |
||
54 |
/**
|
|
55 |
* Populate the vectors of columns for the I_S table.
|
|
56 |
*
|
|
57 |
* @return a pointer to a std::vector of Columns.
|
|
58 |
*/
|
|
59 |
vector<const plugin::ColumnInfo *> *TableNamesIS::createColumns() |
|
60 |
{
|
|
61 |
if (columns == NULL) |
|
62 |
{
|
|
63 |
columns= new vector<const plugin::ColumnInfo *>; |
|
64 |
}
|
|
65 |
else
|
|
66 |
{
|
|
1215.2.25
by Padraig O'Sullivan
Resolved valgrind warnings in the I_S plugin. |
67 |
clearColumns(*columns); |
1215.2.18
by Padraig O'Sullivan
Moved the table names I_S table into its own header and implementation |
68 |
}
|
69 |
||
70 |
columns->push_back(new plugin::ColumnInfo("TABLE_CATALOG", |
|
71 |
FN_REFLEN, |
|
72 |
DRIZZLE_TYPE_VARCHAR, |
|
73 |
0, |
|
74 |
1, |
|
75 |
"", |
|
76 |
SKIP_OPEN_TABLE)); |
|
77 |
||
78 |
columns->push_back(new plugin::ColumnInfo("TABLE_SCHEMA", |
|
79 |
NAME_CHAR_LEN, |
|
80 |
DRIZZLE_TYPE_VARCHAR, |
|
81 |
0, |
|
82 |
0, |
|
83 |
"", |
|
84 |
SKIP_OPEN_TABLE)); |
|
85 |
||
86 |
columns->push_back(new plugin::ColumnInfo("TABLE_NAME", |
|
87 |
NAME_CHAR_LEN, |
|
88 |
DRIZZLE_TYPE_VARCHAR, |
|
89 |
0, |
|
90 |
0, |
|
91 |
"Tables_in_", |
|
92 |
SKIP_OPEN_TABLE)); |
|
93 |
||
94 |
columns->push_back(new plugin::ColumnInfo("TABLE_TYPE", |
|
95 |
NAME_CHAR_LEN, |
|
96 |
DRIZZLE_TYPE_VARCHAR, |
|
97 |
0, |
|
98 |
0, |
|
99 |
"Table_type", |
|
100 |
OPEN_FRM_ONLY)); |
|
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 *TableNamesIS::getTable() |
|
110 |
{
|
|
111 |
columns= createColumns(); |
|
112 |
||
113 |
if (methods == NULL) |
|
114 |
{
|
|
115 |
methods= new TabNamesISMethods(); |
|
116 |
}
|
|
117 |
||
118 |
if (tn_table == NULL) |
|
119 |
{
|
|
120 |
tn_table= new plugin::InfoSchemaTable("TABLE_NAMES", |
|
121 |
*columns, |
|
122 |
1, 2, true, true, 0, |
|
123 |
methods); |
|
124 |
}
|
|
125 |
||
126 |
return tn_table; |
|
127 |
}
|
|
128 |
||
129 |
/**
|
|
130 |
* Delete memory allocated for the table, columns and methods.
|
|
131 |
*/
|
|
132 |
void TableNamesIS::cleanup() |
|
133 |
{
|
|
134 |
clearColumns(*columns); |
|
135 |
delete tn_table; |
|
136 |
delete methods; |
|
137 |
delete columns; |
|
138 |
}
|
|
139 |
||
140 |
int TabNamesISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table) |
|
141 |
const
|
|
142 |
{
|
|
143 |
char tmp[128]; |
|
144 |
String buffer(tmp,sizeof(tmp), session->charset()); |
|
145 |
LEX *lex= session->lex; |
|
146 |
Name_resolution_context *context= &lex->select_lex.context; |
|
147 |
const drizzled::plugin::InfoSchemaTable::Columns tab_columns= schema_table->getColumns(); |
|
148 |
||
149 |
const drizzled::plugin::ColumnInfo *column= tab_columns[2]; |
|
150 |
buffer.length(0); |
|
151 |
buffer.append(column->getOldName().c_str()); |
|
152 |
buffer.append(lex->select_lex.db); |
|
153 |
if (lex->wild && lex->wild->ptr()) |
|
154 |
{
|
|
155 |
buffer.append(STRING_WITH_LEN(" (")); |
|
156 |
buffer.append(lex->wild->ptr()); |
|
157 |
buffer.append(')'); |
|
158 |
}
|
|
159 |
Item_field *field= new Item_field(context, |
|
160 |
NULL, NULL, column->getName().c_str()); |
|
161 |
if (session->add_item_to_list(field)) |
|
162 |
{
|
|
163 |
return 1; |
|
164 |
}
|
|
165 |
field->set_name(buffer.ptr(), buffer.length(), system_charset_info); |
|
166 |
if (session->lex->verbose) |
|
167 |
{
|
|
168 |
field->set_name(buffer.ptr(), buffer.length(), system_charset_info); |
|
169 |
column= tab_columns[3]; |
|
170 |
field= new Item_field(context, NULL, NULL, column->getName().c_str()); |
|
171 |
if (session->add_item_to_list(field)) |
|
172 |
{
|
|
173 |
return 1; |
|
174 |
}
|
|
175 |
field->set_name(column->getOldName().c_str(), |
|
176 |
column->getOldName().length(), |
|
177 |
system_charset_info); |
|
178 |
}
|
|
179 |
return 0; |
|
180 |
}
|
|
181 |