~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/show_dictionary/show_columns.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 00:53:34 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913005334-6wio2sbjugskfbm3
Added calls to the connection start/end dtrace probes.

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) 2010 Brian Aker
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
 
#include "config.h"
22
 
#include "plugin/show_dictionary/dictionary.h"
23
 
#include "drizzled/table_identifier.h"
24
 
 
25
 
 
26
 
using namespace std;
27
 
using namespace drizzled;
28
 
 
29
 
static const string VARCHAR("VARCHAR");
30
 
static const string DOUBLE("DOUBLE");
31
 
static const string BLOB("BLOB");
32
 
static const string ENUM("ENUM");
33
 
static const string INTEGER("INTEGER");
34
 
static const string BIGINT("BIGINT");
35
 
static const string DECIMAL("DECIMAL");
36
 
static const string DATE("DATE");
37
 
static const string TIMESTAMP("TIMESTAMP");
38
 
static const string DATETIME("DATETIME");
39
 
 
40
 
ShowColumns::ShowColumns() :
41
 
  plugin::TableFunction("DATA_DICTIONARY", "SHOW_COLUMNS")
42
 
{
43
 
  add_field("Field");
44
 
  add_field("Type");
45
 
  add_field("Null", plugin::TableFunction::BOOLEAN);
46
 
  add_field("Default");
47
 
  add_field("Default_is_NULL", plugin::TableFunction::BOOLEAN);
48
 
  add_field("On_Update");
49
 
}
50
 
 
51
 
ShowColumns::Generator::Generator(Field **arg) :
52
 
  plugin::TableFunction::Generator(arg),
53
 
  is_tables_primed(false),
54
 
  is_columns_primed(false),
55
 
  column_iterator(0)
56
 
{
57
 
  statement::Select *select= static_cast<statement::Select *>(getSession().lex->statement);
58
 
 
59
 
  table_name.append(select->getShowTable().c_str());
60
 
  TableIdentifier identifier(select->getShowSchema().c_str(), select->getShowTable().c_str());
61
 
 
62
 
  is_tables_primed= plugin::StorageEngine::getTableDefinition(getSession(),
63
 
                                                              identifier,
64
 
                                                              table_proto);
65
 
}
66
 
 
67
 
bool ShowColumns::Generator::nextColumnCore()
68
 
{
69
 
  if (is_columns_primed)
70
 
  {
71
 
    column_iterator++;
72
 
  }
73
 
  else
74
 
  {
75
 
    if (not isTablesPrimed())
76
 
      return false;
77
 
 
78
 
    column_iterator= 0;
79
 
    is_columns_primed= true;
80
 
  }
81
 
 
82
 
  if (column_iterator >= getTableProto().field_size())
83
 
    return false;
84
 
 
85
 
  column= getTableProto().field(column_iterator);
86
 
 
87
 
  return true;
88
 
}
89
 
 
90
 
 
91
 
bool ShowColumns::Generator::nextColumn()
92
 
{
93
 
  while (not nextColumnCore())
94
 
  {
95
 
    return false;
96
 
  }
97
 
 
98
 
  return true;
99
 
}
100
 
 
101
 
bool ShowColumns::Generator::populate()
102
 
{
103
 
 
104
 
  if (not nextColumn())
105
 
    return false;
106
 
 
107
 
  fill();
108
 
 
109
 
  return true;
110
 
}
111
 
 
112
 
void ShowColumns::Generator::pushType(message::Table::Field::FieldType type)
113
 
{
114
 
  switch (type)
115
 
  {
116
 
  default:
117
 
  case message::Table::Field::VARCHAR:
118
 
    push(VARCHAR);
119
 
    break;
120
 
  case message::Table::Field::DOUBLE:
121
 
    push(DOUBLE);
122
 
    break;
123
 
  case message::Table::Field::BLOB:
124
 
    push(BLOB);
125
 
    break;
126
 
  case message::Table::Field::ENUM:
127
 
    push(ENUM);
128
 
    break;
129
 
  case message::Table::Field::INTEGER:
130
 
    push(INTEGER);
131
 
    break;
132
 
  case message::Table::Field::BIGINT:
133
 
    push(BIGINT);
134
 
    break;
135
 
  case message::Table::Field::DECIMAL:
136
 
    push(DECIMAL);
137
 
    break;
138
 
  case message::Table::Field::DATE:
139
 
    push(DATE);
140
 
    break;
141
 
  case message::Table::Field::TIMESTAMP:
142
 
    push(TIMESTAMP);
143
 
    break;
144
 
  case message::Table::Field::DATETIME:
145
 
    push(DATETIME);
146
 
    break;
147
 
  }
148
 
}
149
 
 
150
 
 
151
 
void ShowColumns::Generator::fill()
152
 
{
153
 
  /* Field */
154
 
  push(column.name());
155
 
 
156
 
  /* Type */
157
 
  pushType(column.type());
158
 
 
159
 
  /* Null */
160
 
  push(column.constraints().is_nullable());
161
 
 
162
 
  /* Default */
163
 
  push(column.options().default_value());
164
 
 
165
 
  /* Default_is_NULL */
166
 
  push(column.options().default_null());
167
 
 
168
 
  /* On_Update */
169
 
  push(column.options().update_value());
170
 
}