1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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.
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.
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
23
* schemata I_S table methods.
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
#include "drizzled/join_table.h"
30
#include "drizzled/sql_table.h"
31
#include "drizzled/db.h"
32
#include "helper_methods.h"
35
#ifdef HAVE_SYS_STAT_H
36
# include <sys/stat.h>
41
using namespace drizzled;
45
* Vectors of columns for the schemata I_S table.
47
static vector<const plugin::ColumnInfo *> *columns= NULL;
50
* Methods for the schemata I_S table.
52
static plugin::InfoSchemaMethods *methods= NULL;
57
static plugin::InfoSchemaTable *sch_table= NULL;
60
* Populate the vectors of columns for the I_S table.
62
* @return a pointer to a std::vector of Columns.
64
vector<const plugin::ColumnInfo *> *SchemataIS::createColumns()
68
columns= new vector<const plugin::ColumnInfo *>;
72
clearColumns(*columns);
75
columns->push_back(new plugin::ColumnInfo("CATALOG_NAME",
82
columns->push_back(new plugin::ColumnInfo("SCHEMA_NAME",
89
columns->push_back(new plugin::ColumnInfo("DEFAULT_CHARACTER_SET_NAME",
96
columns->push_back(new plugin::ColumnInfo("DEFAULT_COLLATION_NAME",
103
columns->push_back(new plugin::ColumnInfo("SQL_PATH",
105
DRIZZLE_TYPE_VARCHAR,
114
* Initialize the I_S table.
116
* @return a pointer to an I_S table
118
plugin::InfoSchemaTable *SchemataIS::getTable()
120
columns= createColumns();
124
methods= new SchemataISMethods();
127
if (sch_table == NULL)
129
sch_table= new plugin::InfoSchemaTable("SCHEMATA",
131
1, -1, false, false, 0,
139
* Delete memory allocated for the table, columns and methods.
141
void SchemataIS::cleanup()
143
clearColumns(*columns);
149
static bool store_schema_schemata(Session *,
152
const CHARSET_INFO * const cs,
153
plugin::InfoSchemaTable *schema_table)
155
table->restoreRecordAsDefault();
156
table->setWriteSet(1);
157
table->setWriteSet(2);
158
table->setWriteSet(3);
159
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
160
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
161
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
162
schema_table->addRow(table->record[0], table->s->reclength);
166
int SchemataISMethods::fillTable(Session *session,
168
plugin::InfoSchemaTable *schema_table)
171
TODO: fill_schema_shemata() is called when new client is connected.
172
Returning error status in this case leads to client hangup.
175
LOOKUP_FIELD_VALUES lookup_field_vals;
176
vector<LEX_STRING*> db_names;
178
/* the WHERE condition */
179
COND *cond= table->reginfo.join_tab->select_cond;
181
if (get_lookup_field_values(session,
183
table->pos_in_table_list,
190
if (make_db_list(session,
199
If we have lookup db value we should check that the database exists
201
if (lookup_field_vals.db_value.str &&
202
! lookup_field_vals.wild_db_value &&
205
char path[FN_REFLEN+16];
207
struct stat stat_info;
208
if (! lookup_field_vals.db_value.str[0])
213
path_len= build_table_filename(path,
215
lookup_field_vals.db_value.str,
219
if (stat(path,&stat_info))
225
vector<LEX_STRING*>::iterator db_name= db_names.begin();
226
while (db_name != db_names.end())
228
if (with_i_schema) // information schema name is always first in list
230
if (store_schema_schemata(session, table, *db_name, system_charset_info, schema_table))
238
const CHARSET_INFO *cs= get_default_db_collation((*db_name)->str);
240
if (store_schema_schemata(session, table, *db_name, cs, schema_table))
250
int SchemataISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
254
LEX *lex= session->lex;
255
Select_Lex *sel= lex->current_select;
256
Name_resolution_context *context= &sel->context;
257
const drizzled::plugin::InfoSchemaTable::Columns sch_columns= schema_table->getColumns();
259
if (! sel->item_list.elements)
261
const drizzled::plugin::ColumnInfo *column= sch_columns[1];
262
String buffer(tmp,sizeof(tmp), system_charset_info);
263
Item_field *field= new Item_field(context,
266
column->getName().c_str());
267
if (! field || session->add_item_to_list(field))
272
buffer.append(column->getOldName().c_str());
273
if (lex->wild && lex->wild->ptr())
275
buffer.append(STRING_WITH_LEN(" ("));
276
buffer.append(lex->wild->ptr());
279
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);