~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/columns.cc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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("ORDINAL_POSITION", plugin::TableFunction::NUMBER);
36
 
  add_field("COLUMN_DEFAULT");
37
 
  add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN);
38
 
  add_field("DATA_TYPE");
39
 
 
40
 
  add_field("CHARACTER_MAXIMUM_LENGTH", plugin::TableFunction::NUMBER);
41
 
  add_field("CHARACTER_OCTET_LENGTH", plugin::TableFunction::NUMBER);
42
 
  add_field("NUMERIC_PRECISION", plugin::TableFunction::NUMBER);
43
 
  add_field("NUMERIC_SCALE", plugin::TableFunction::NUMBER);
44
 
 
45
 
  add_field("COLLATION_NAME");
46
 
 
47
 
  add_field("COLUMN_KEY", plugin::TableFunction::BOOLEAN);
48
 
  add_field("EXTRA", 20);
49
 
  add_field("COLUMN_COMMENT", 1024);
50
 
}
51
 
 
52
 
 
53
 
ColumnsTool::Generator::Generator(Field **arg) :
54
 
  TablesTool::Generator(arg),
55
 
  column_iterator(0),
56
 
  is_columns_primed(false)
57
 
{
58
 
}
59
 
 
60
 
 
61
 
bool ColumnsTool::Generator::nextColumnCore()
62
 
{
63
 
  if (is_columns_primed)
64
 
  {
65
 
    column_iterator++;
66
 
  }
67
 
  else
68
 
  {
69
 
    if (not isTablesPrimed())
70
 
      return false;
71
 
 
72
 
    column_iterator= 0;
73
 
    is_columns_primed= true;
74
 
  }
75
 
 
76
 
  if (column_iterator >= getTableProto().field_size())
77
 
    return false;
78
 
 
79
 
  column= getTableProto().field(column_iterator);
80
 
 
81
 
  return true;
82
 
}
83
 
 
84
 
 
85
 
bool ColumnsTool::Generator::nextColumn()
86
 
{
87
 
  while (not nextColumnCore())
88
 
  {
89
 
    if (not nextTable())
90
 
      return false;
91
 
    is_columns_primed= false;
92
 
  }
93
 
 
94
 
  return true;
95
 
}
96
 
 
97
 
bool ColumnsTool::Generator::populate()
98
 
{
99
 
  if (not nextColumn())
100
 
    return false;
101
 
 
102
 
  fill();
103
 
 
104
 
  return true;
105
 
}
106
 
 
107
 
void ColumnsTool::Generator::fill()
108
 
{
109
 
  /* TABLE_SCHEMA */
110
 
  push(schema_name());
111
 
 
112
 
  /* TABLE_NAME */
113
 
  push(table_name());
114
 
 
115
 
  /* COLUMN_NAME */
116
 
  push(column.name());
117
 
 
118
 
  /* ORDINAL_POSITION */
119
 
  push(static_cast<int64_t>(column_iterator));
120
 
 
121
 
  /* COLUMN_DEFAULT */
122
 
  push(column.options().default_value());
123
 
 
124
 
  /* IS_NULLABLE */
125
 
  push(column.constraints().is_nullable());
126
 
 
127
 
  /* DATATYPE */
128
 
  pushType(column.type());
129
 
 
130
 
 /* "CHARACTER_MAXIMUM_LENGTH" */
131
 
  push(static_cast<int64_t>(column.string_options().length()));
132
 
 
133
 
 /* "CHARACTER_OCTET_LENGTH" */
134
 
  push(static_cast<int64_t>(column.string_options().length()) * 4);
135
 
 
136
 
 /* "NUMERIC_PRECISION" */
137
 
  push(static_cast<int64_t>(column.numeric_options().precision()));
138
 
 
139
 
 /* "NUMERIC_SCALE" */
140
 
  push(static_cast<int64_t>(column.numeric_options().scale()));
141
 
 
142
 
 /* "COLLATION_NAME" */
143
 
  push(column.string_options().collation());
144
 
 
145
 
 /* "COLUMN_KEY" */
146
 
  push(false);
147
 
 
148
 
 /* "EXTRA" */
149
 
  push();
150
 
 
151
 
 /* "COLUMN_COMMENT" */
152
 
  push(column.comment());
153
 
}