~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/table_names.cc

  • Committer: Brian Aker
  • Date: 2010-02-14 02:02:48 UTC
  • mfrom: (1273.13.64 fix_is)
  • Revision ID: brian@gaz-20100214020248-bhovaejhz9fmer3q
MergeĀ inĀ data_dictionary.

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
 
 *   table names I_S table methods.
24
 
 */
25
 
 
26
 
#include "config.h"
27
 
#include "drizzled/session.h"
28
 
#include "drizzled/show.h"
29
 
#include "drizzled/tztime.h"
30
 
 
31
 
#include "helper_methods.h"
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
 
  {
67
 
    clearColumns(*columns);
68
 
  }
69
 
 
70
 
  columns->push_back(new plugin::ColumnInfo("TABLE_CATALOG",
71
 
                                            FN_REFLEN,
72
 
                                            DRIZZLE_TYPE_VARCHAR,
73
 
                                            0,
74
 
                                            1,
75
 
                                            ""));
76
 
 
77
 
  columns->push_back(new plugin::ColumnInfo("TABLE_SCHEMA",
78
 
                                            NAME_CHAR_LEN,
79
 
                                            DRIZZLE_TYPE_VARCHAR,
80
 
                                            0,
81
 
                                            0,
82
 
                                            ""));
83
 
 
84
 
  columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
85
 
                                            NAME_CHAR_LEN,
86
 
                                            DRIZZLE_TYPE_VARCHAR,
87
 
                                            0,
88
 
                                            0,
89
 
                                            "Tables_in_"));
90
 
 
91
 
  columns->push_back(new plugin::ColumnInfo("TABLE_TYPE",
92
 
                                            NAME_CHAR_LEN,
93
 
                                            DRIZZLE_TYPE_VARCHAR,
94
 
                                            0,
95
 
                                            0,
96
 
                                            "Table_type"));
97
 
  return columns;
98
 
}
99
 
 
100
 
/**
101
 
 * Initialize the I_S table.
102
 
 *
103
 
 * @return a pointer to an I_S table
104
 
 */
105
 
plugin::InfoSchemaTable *TableNamesIS::getTable()
106
 
{
107
 
  columns= createColumns();
108
 
 
109
 
  if (methods == NULL)
110
 
  {
111
 
    methods= new TabNamesISMethods();
112
 
  }
113
 
 
114
 
  if (tn_table == NULL)
115
 
  {
116
 
    tn_table= new plugin::InfoSchemaTable("TABLE_NAMES",
117
 
                                          *columns,
118
 
                                          1, 2, true, true, 0,
119
 
                                          methods);
120
 
  }
121
 
 
122
 
  return tn_table;
123
 
}
124
 
 
125
 
/**
126
 
 * Delete memory allocated for the table, columns and methods.
127
 
 */
128
 
void TableNamesIS::cleanup()
129
 
{
130
 
  clearColumns(*columns);
131
 
  delete tn_table;
132
 
  delete methods;
133
 
  delete columns;
134
 
}
135
 
 
136
 
int TabNamesISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
137
 
  const
138
 
{
139
 
  char tmp[128];
140
 
  String buffer(tmp,sizeof(tmp), session->charset());
141
 
  LEX *lex= session->lex;
142
 
  Name_resolution_context *context= &lex->select_lex.context;
143
 
  const drizzled::plugin::InfoSchemaTable::Columns tab_columns= schema_table->getColumns();
144
 
 
145
 
  const drizzled::plugin::ColumnInfo *column= tab_columns[2];
146
 
  buffer.length(0);
147
 
  buffer.append(column->getOldName().c_str());
148
 
  buffer.append(lex->select_lex.db);
149
 
  if (lex->wild && lex->wild->ptr())
150
 
  {
151
 
    buffer.append(STRING_WITH_LEN(" ("));
152
 
    buffer.append(lex->wild->ptr());
153
 
    buffer.append(')');
154
 
  }
155
 
  Item_field *field= new Item_field(context,
156
 
                                    NULL, NULL, column->getName().c_str());
157
 
  if (session->add_item_to_list(field))
158
 
  {
159
 
    return 1;
160
 
  }
161
 
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
162
 
 
163
 
  return 0;
164
 
}
165