1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
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 |
* schemata 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/join_table.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.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
32 |
#include "schemata.h" |
33 |
||
34 |
#include <vector> |
|
35 |
||
36 |
using namespace drizzled; |
|
37 |
using namespace std; |
|
38 |
||
39 |
/*
|
|
40 |
* Vectors of columns for the schemata I_S table.
|
|
41 |
*/
|
|
42 |
static vector<const plugin::ColumnInfo *> *columns= NULL; |
|
43 |
||
44 |
/*
|
|
45 |
* Methods for the schemata I_S table.
|
|
46 |
*/
|
|
47 |
static plugin::InfoSchemaMethods *methods= NULL; |
|
48 |
||
49 |
/*
|
|
50 |
* schemata I_S table.
|
|
51 |
*/
|
|
52 |
static plugin::InfoSchemaTable *sch_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 *> *SchemataIS::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.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
68 |
}
|
69 |
||
70 |
columns->push_back(new plugin::ColumnInfo("CATALOG_NAME", |
|
71 |
FN_REFLEN, |
|
72 |
DRIZZLE_TYPE_VARCHAR, |
|
73 |
0, |
|
74 |
1, |
|
1225.1.14
by Padraig O'Sullivan
Removed the redundant open table method parameter to columns associated with an I_S table. |
75 |
"")); |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
76 |
|
77 |
columns->push_back(new plugin::ColumnInfo("SCHEMA_NAME", |
|
78 |
NAME_CHAR_LEN, |
|
79 |
DRIZZLE_TYPE_VARCHAR, |
|
80 |
0, |
|
81 |
0, |
|
1225.1.14
by Padraig O'Sullivan
Removed the redundant open table method parameter to columns associated with an I_S table. |
82 |
"Database")); |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
83 |
|
84 |
columns->push_back(new plugin::ColumnInfo("DEFAULT_CHARACTER_SET_NAME", |
|
85 |
64, |
|
86 |
DRIZZLE_TYPE_VARCHAR, |
|
87 |
0, |
|
88 |
0, |
|
1225.1.14
by Padraig O'Sullivan
Removed the redundant open table method parameter to columns associated with an I_S table. |
89 |
"")); |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
90 |
|
91 |
columns->push_back(new plugin::ColumnInfo("DEFAULT_COLLATION_NAME", |
|
92 |
64, |
|
93 |
DRIZZLE_TYPE_VARCHAR, |
|
94 |
0, |
|
95 |
0, |
|
1225.1.14
by Padraig O'Sullivan
Removed the redundant open table method parameter to columns associated with an I_S table. |
96 |
"")); |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
97 |
|
98 |
columns->push_back(new plugin::ColumnInfo("SQL_PATH", |
|
99 |
FN_REFLEN, |
|
100 |
DRIZZLE_TYPE_VARCHAR, |
|
101 |
0, |
|
102 |
1, |
|
1225.1.14
by Padraig O'Sullivan
Removed the redundant open table method parameter to columns associated with an I_S table. |
103 |
"")); |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
104 |
|
105 |
return columns; |
|
106 |
}
|
|
107 |
||
108 |
/**
|
|
109 |
* Initialize the I_S table.
|
|
110 |
*
|
|
111 |
* @return a pointer to an I_S table
|
|
112 |
*/
|
|
113 |
plugin::InfoSchemaTable *SchemataIS::getTable() |
|
114 |
{
|
|
115 |
columns= createColumns(); |
|
116 |
||
117 |
if (methods == NULL) |
|
118 |
{
|
|
119 |
methods= new SchemataISMethods(); |
|
120 |
}
|
|
121 |
||
122 |
if (sch_table == NULL) |
|
123 |
{
|
|
124 |
sch_table= new plugin::InfoSchemaTable("SCHEMATA", |
|
125 |
*columns, |
|
126 |
1, -1, false, false, 0, |
|
127 |
methods); |
|
128 |
}
|
|
129 |
||
130 |
return sch_table; |
|
131 |
}
|
|
132 |
||
133 |
/**
|
|
134 |
* Delete memory allocated for the table, columns and methods.
|
|
135 |
*/
|
|
136 |
void SchemataIS::cleanup() |
|
137 |
{
|
|
138 |
clearColumns(*columns); |
|
139 |
delete sch_table; |
|
140 |
delete methods; |
|
141 |
delete columns; |
|
142 |
}
|
|
143 |
||
1225.1.1
by Padraig O'Sullivan
Removed special case I_S code paths. All queries are now going against the I_S engine. |
144 |
static bool store_schema_schemata(Session *, |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
145 |
Table *table, |
146 |
LEX_STRING *db_name, |
|
1225.1.19
by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table |
147 |
const CHARSET_INFO * const cs, |
148 |
plugin::InfoSchemaTable *schema_table) |
|
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
149 |
{
|
150 |
table->restoreRecordAsDefault(); |
|
1225.1.6
by Padraig O'Sullivan
Now we are correctly setting the bitmaps in the I_S methods before adding a row to an I_S table. |
151 |
table->setWriteSet(1); |
152 |
table->setWriteSet(2); |
|
153 |
table->setWriteSet(3); |
|
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
154 |
table->field[1]->store(db_name->str, db_name->length, system_charset_info); |
155 |
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info); |
|
156 |
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info); |
|
1225.1.19
by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table |
157 |
schema_table->addRow(table->record[0], table->s->reclength); |
1225.1.1
by Padraig O'Sullivan
Removed special case I_S code paths. All queries are now going against the I_S engine. |
158 |
return false; |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
159 |
}
|
160 |
||
1225.1.19
by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table |
161 |
int SchemataISMethods::fillTable(Session *session, |
162 |
Table *table, |
|
163 |
plugin::InfoSchemaTable *schema_table) |
|
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
164 |
{
|
165 |
/*
|
|
166 |
TODO: fill_schema_shemata() is called when new client is connected.
|
|
167 |
Returning error status in this case leads to client hangup.
|
|
168 |
*/
|
|
169 |
||
170 |
LOOKUP_FIELD_VALUES lookup_field_vals; |
|
171 |
vector<LEX_STRING*> db_names; |
|
172 |
bool with_i_schema; |
|
173 |
/* the WHERE condition */
|
|
174 |
COND *cond= table->reginfo.join_tab->select_cond; |
|
175 |
||
1225.1.20
by Padraig O'Sullivan
Removed all remnants of schema_table from the TableList class. This cleans up a bunch of code. |
176 |
if (get_lookup_field_values(session, |
177 |
cond, |
|
178 |
table->pos_in_table_list, |
|
179 |
&lookup_field_vals, |
|
180 |
schema_table)) |
|
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
181 |
{
|
182 |
return 0; |
|
183 |
}
|
|
184 |
||
185 |
if (make_db_list(session, |
|
186 |
db_names, |
|
187 |
&lookup_field_vals, |
|
188 |
&with_i_schema)) |
|
189 |
{
|
|
190 |
return 1; |
|
191 |
}
|
|
192 |
||
193 |
/*
|
|
194 |
If we have lookup db value we should check that the database exists
|
|
195 |
*/
|
|
196 |
if (lookup_field_vals.db_value.str && |
|
197 |
! lookup_field_vals.wild_db_value && |
|
198 |
! with_i_schema) |
|
199 |
{
|
|
200 |
char path[FN_REFLEN+16]; |
|
201 |
uint32_t path_len; |
|
202 |
struct stat stat_info; |
|
203 |
if (! lookup_field_vals.db_value.str[0]) |
|
204 |
{
|
|
205 |
return 0; |
|
206 |
}
|
|
207 |
||
208 |
path_len= build_table_filename(path, |
|
209 |
sizeof(path), |
|
210 |
lookup_field_vals.db_value.str, |
|
211 |
"", |
|
212 |
false); |
|
213 |
path[path_len-1]= 0; |
|
214 |
if (stat(path,&stat_info)) |
|
215 |
{
|
|
216 |
return 0; |
|
217 |
}
|
|
218 |
}
|
|
219 |
||
220 |
vector<LEX_STRING*>::iterator db_name= db_names.begin(); |
|
221 |
while (db_name != db_names.end()) |
|
222 |
{
|
|
223 |
if (with_i_schema) // information schema name is always first in list |
|
224 |
{
|
|
1225.1.19
by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table |
225 |
if (store_schema_schemata(session, table, *db_name, system_charset_info, schema_table)) |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
226 |
{
|
227 |
return 1; |
|
228 |
}
|
|
229 |
with_i_schema= 0; |
|
230 |
}
|
|
231 |
else
|
|
232 |
{
|
|
233 |
const CHARSET_INFO *cs= get_default_db_collation((*db_name)->str); |
|
234 |
||
1225.1.19
by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table |
235 |
if (store_schema_schemata(session, table, *db_name, cs, schema_table)) |
1215.2.14
by Padraig O'Sullivan
Split schemata out into its own header and implementation files. |
236 |
{
|
237 |
return 1; |
|
238 |
}
|
|
239 |
}
|
|
240 |
++db_name; |
|
241 |
}
|
|
242 |
return 0; |
|
243 |
}
|
|
244 |
||
245 |
int SchemataISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table) |
|
246 |
const
|
|
247 |
{
|
|
248 |
char tmp[128]; |
|
249 |
LEX *lex= session->lex; |
|
250 |
Select_Lex *sel= lex->current_select; |
|
251 |
Name_resolution_context *context= &sel->context; |
|
252 |
const drizzled::plugin::InfoSchemaTable::Columns sch_columns= schema_table->getColumns(); |
|
253 |
||
254 |
if (! sel->item_list.elements) |
|
255 |
{
|
|
256 |
const drizzled::plugin::ColumnInfo *column= sch_columns[1]; |
|
257 |
String buffer(tmp,sizeof(tmp), system_charset_info); |
|
258 |
Item_field *field= new Item_field(context, |
|
259 |
NULL, |
|
260 |
NULL, |
|
261 |
column->getName().c_str()); |
|
262 |
if (! field || session->add_item_to_list(field)) |
|
263 |
{
|
|
264 |
return 1; |
|
265 |
}
|
|
266 |
buffer.length(0); |
|
267 |
buffer.append(column->getOldName().c_str()); |
|
268 |
if (lex->wild && lex->wild->ptr()) |
|
269 |
{
|
|
270 |
buffer.append(STRING_WITH_LEN(" (")); |
|
271 |
buffer.append(lex->wild->ptr()); |
|
272 |
buffer.append(')'); |
|
273 |
}
|
|
274 |
field->set_name(buffer.ptr(), buffer.length(), system_charset_info); |
|
275 |
}
|
|
276 |
return 0; |
|
277 |
}
|
|
278 |