~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/columns.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-17 00:08:20 UTC
  • mto: (1126.9.3 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090917000820-urd6p46qngi1okjp
Updated calls to some dtrace probes to cast the parameter to const char *
appropriately. Also, removed the additional variable in places that I was
using.

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 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
 
#include "config.h"
22
 
#include "plugin/schema_dictionary/dictionary.h"
23
 
 
24
 
using namespace std;
25
 
using namespace drizzled;
26
 
 
27
 
 
28
 
ColumnsTool::ColumnsTool() :
29
 
  TablesTool("COLUMNS")
30
 
{
31
 
  add_field("TABLE_SCHEMA");
32
 
  add_field("TABLE_NAME");
33
 
 
34
 
  add_field("COLUMN_NAME");
35
 
  add_field("COLUMN_TYPE");
36
 
  add_field("ORDINAL_POSITION", plugin::TableFunction::NUMBER);
37
 
  add_field("COLUMN_DEFAULT", plugin::TableFunction::VARBINARY, 65535, true);
38
 
  add_field("COLUMN_DEFAULT_IS_NULL", plugin::TableFunction::BOOLEAN);
39
 
  add_field("COLUMN_DEFAULT_UPDATE");
40
 
  add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN);
41
 
  add_field("IS_INDEXED", plugin::TableFunction::BOOLEAN);
42
 
  add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN);
43
 
  add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN);
44
 
  add_field("IS_MULTI", plugin::TableFunction::BOOLEAN);
45
 
  add_field("IS_FIRST_IN_MULTI", plugin::TableFunction::BOOLEAN);
46
 
  add_field("INDEXES_FOUND_IN", plugin::TableFunction::NUMBER);
47
 
  add_field("DATA_TYPE");
48
 
 
49
 
  add_field("CHARACTER_MAXIMUM_LENGTH", plugin::TableFunction::NUMBER);
50
 
  add_field("CHARACTER_OCTET_LENGTH", plugin::TableFunction::NUMBER);
51
 
  add_field("NUMERIC_PRECISION", plugin::TableFunction::NUMBER);
52
 
  add_field("NUMERIC_SCALE", plugin::TableFunction::NUMBER);
53
 
 
54
 
  add_field("COLLATION_NAME");
55
 
 
56
 
  add_field("COLUMN_COMMENT", 1024);
57
 
}
58
 
 
59
 
 
60
 
ColumnsTool::Generator::Generator(Field **arg) :
61
 
  TablesTool::Generator(arg),
62
 
  column_iterator(0),
63
 
  is_columns_primed(false)
64
 
{
65
 
}
66
 
 
67
 
 
68
 
bool ColumnsTool::Generator::nextColumnCore()
69
 
{
70
 
  if (is_columns_primed)
71
 
  {
72
 
    column_iterator++;
73
 
  }
74
 
  else
75
 
  {
76
 
    if (not isTablesPrimed())
77
 
      return false;
78
 
 
79
 
    column_iterator= 0;
80
 
    is_columns_primed= true;
81
 
  }
82
 
 
83
 
  if (column_iterator >= getTableProto().field_size())
84
 
    return false;
85
 
 
86
 
  column= getTableProto().field(column_iterator);
87
 
 
88
 
  return true;
89
 
}
90
 
 
91
 
 
92
 
bool ColumnsTool::Generator::nextColumn()
93
 
{
94
 
  while (not nextColumnCore())
95
 
  {
96
 
    if (not nextTable())
97
 
      return false;
98
 
    is_columns_primed= false;
99
 
  }
100
 
 
101
 
  return true;
102
 
}
103
 
 
104
 
bool ColumnsTool::Generator::populate()
105
 
{
106
 
 
107
 
  if (not nextColumn())
108
 
    return false;
109
 
 
110
 
  fill();
111
 
 
112
 
  return true;
113
 
}
114
 
 
115
 
void ColumnsTool::Generator::fill()
116
 
{
117
 
  /* TABLE_SCHEMA */
118
 
  push(getTableProto().schema());
119
 
 
120
 
  /* TABLE_NAME */
121
 
  push(getTableProto().name());
122
 
 
123
 
  /* COLUMN_NAME */
124
 
  push(column.name());
125
 
 
126
 
  /* COLUMN_TYPE */
127
 
  pushType(column.type());
128
 
 
129
 
  /* ORDINAL_POSITION */
130
 
  push(static_cast<int64_t>(column_iterator));
131
 
 
132
 
  /* COLUMN_DEFAULT */
133
 
  if (column.options().has_default_value())
134
 
    push(column.options().default_value());
135
 
  else if (column.options().has_default_bin_value())
136
 
    push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
137
 
  else
138
 
    push();
139
 
 
140
 
  /* COLUMN_DEFAULT_IS_NULL */
141
 
  push(column.options().default_null());
142
 
 
143
 
  /* COLUMN_DEFAULT_UPDATE */
144
 
  push(column.options().update_value());
145
 
 
146
 
  /* IS_NULLABLE */
147
 
  push(column.constraints().is_nullable());
148
 
 
149
 
  /* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
150
 
  bool is_indexed= false;
151
 
  bool is_primary= false;
152
 
  bool is_unique= false;
153
 
  bool is_multi= false;
154
 
  bool is_multi_first= false;
155
 
  int64_t indexes_found_in= 0;
156
 
  for (int32_t x= 0; x < getTableProto().indexes_size() ; x++)
157
 
  {
158
 
    drizzled::message::Table::Index index=
159
 
      getTableProto().indexes(x);
160
 
 
161
 
    for (int32_t y= 0; y < index.index_part_size() ; y++)
162
 
    {
163
 
      drizzled::message::Table::Index::IndexPart index_part=
164
 
        index.index_part(y);
165
 
 
166
 
      if (static_cast<int32_t>(index_part.fieldnr()) == column_iterator)
167
 
      {
168
 
        indexes_found_in++;
169
 
        is_indexed= true;
170
 
 
171
 
        if (index.is_primary())
172
 
          is_primary= true;
173
 
 
174
 
        if (index.is_unique())
175
 
          is_unique= true;
176
 
 
177
 
        if (index.index_part_size() > 1)
178
 
        {
179
 
          is_multi= true;
180
 
 
181
 
          if (y == 0)
182
 
            is_multi_first= true;
183
 
        }
184
 
      }
185
 
    }
186
 
  }
187
 
  /* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
188
 
  push(is_indexed);
189
 
  push(is_primary);
190
 
  push(is_unique);
191
 
  push(is_multi);
192
 
  push(is_multi_first);
193
 
  push(indexes_found_in);
194
 
 
195
 
  /* DATATYPE */
196
 
  pushType(column.type());
197
 
 
198
 
 /* "CHARACTER_MAXIMUM_LENGTH" */
199
 
  push(static_cast<int64_t>(column.string_options().length()));
200
 
 
201
 
 /* "CHARACTER_OCTET_LENGTH" */
202
 
  push(static_cast<int64_t>(column.string_options().length()) * 4);
203
 
 
204
 
 /* "NUMERIC_PRECISION" */
205
 
  push(static_cast<int64_t>(column.numeric_options().precision()));
206
 
 
207
 
 /* "NUMERIC_SCALE" */
208
 
  push(static_cast<int64_t>(column.numeric_options().scale()));
209
 
 
210
 
 /* "COLLATION_NAME" */
211
 
  push(column.string_options().collation());
212
 
 
213
 
 /* "COLUMN_COMMENT" */
214
 
  push(column.comment());
215
 
}