~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/columns.cc

Lowercase plugin name prefix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
 
28
28
ColumnsTool::ColumnsTool() :
29
 
  DataDictionary("COLUMNS")
 
29
  TablesTool("COLUMNS")
30
30
{
31
31
  add_field("TABLE_SCHEMA");
32
32
  add_field("TABLE_NAME");
37
37
  add_field("COLUMN_DEFAULT", plugin::TableFunction::VARBINARY, 65535, true);
38
38
  add_field("COLUMN_DEFAULT_IS_NULL", plugin::TableFunction::BOOLEAN, 0, false);
39
39
  add_field("COLUMN_DEFAULT_UPDATE");
40
 
  add_field("IS_AUTO_INCREMENT", plugin::TableFunction::BOOLEAN, 0, false);
41
40
  add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN, 0, false);
42
41
  add_field("IS_INDEXED", plugin::TableFunction::BOOLEAN, 0, false);
43
42
  add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN, 0, false);
52
51
  add_field("NUMERIC_PRECISION", plugin::TableFunction::NUMBER);
53
52
  add_field("NUMERIC_SCALE", plugin::TableFunction::NUMBER);
54
53
 
55
 
  add_field("ENUM_VALUES", plugin::TableFunction::STRING, 1024, true);
56
 
 
57
54
  add_field("COLLATION_NAME");
58
55
 
59
56
  add_field("COLUMN_COMMENT", plugin::TableFunction::STRING, 1024, true);
61
58
 
62
59
 
63
60
ColumnsTool::Generator::Generator(Field **arg) :
64
 
  DataDictionary::Generator(arg),
65
 
  field_generator(getSession())
66
 
{
 
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;
67
102
}
68
103
 
69
104
bool ColumnsTool::Generator::populate()
70
105
{
71
 
  drizzled::generator::FieldPair field_pair;
72
 
 
73
 
  while (!!(field_pair= field_generator))
74
 
  {
75
 
    const drizzled::message::Table *table_message= field_pair.first;
76
 
    int32_t field_iterator= field_pair.second;
77
 
    const message::Table::Field &column(table_message->field(field_pair.second));
78
 
 
79
 
    /* TABLE_SCHEMA */
80
 
    push(table_message->schema());
81
 
 
82
 
    /* TABLE_NAME */
83
 
    push(table_message->name());
84
 
 
85
 
    /* COLUMN_NAME */
86
 
    push(column.name());
87
 
 
88
 
    /* COLUMN_TYPE */
89
 
    push(drizzled::message::type(column.type()));
90
 
 
91
 
    /* ORDINAL_POSITION */
92
 
    push(static_cast<int64_t>(field_iterator));
93
 
 
94
 
    /* COLUMN_DEFAULT */
95
 
    if (column.options().has_default_value())
96
 
    {
97
 
      push(column.options().default_value());
98
 
    }
99
 
    else if (column.options().has_default_bin_value())
100
 
    {
101
 
      push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
102
 
    }
103
 
    else if (column.options().has_default_expression())
104
 
    {
105
 
      push(column.options().default_expression());
106
 
    }
107
 
    else
108
 
    {
109
 
      push();
110
 
    }
111
 
 
112
 
    /* COLUMN_DEFAULT_IS_NULL */
113
 
    push(column.options().default_null());
114
 
 
115
 
    /* COLUMN_DEFAULT_UPDATE */
116
 
    push(column.options().update_expression());
117
 
 
118
 
    /* IS_AUTO_INCREMENT */
119
 
    push(column.numeric_options().is_autoincrement());
120
 
 
121
 
    /* IS_NULLABLE */
122
 
    push(column.constraints().is_nullable());
123
 
 
124
 
    /* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
125
 
    bool is_indexed= false;
126
 
    bool is_primary= false;
127
 
    bool is_unique= false;
128
 
    bool is_multi= false;
129
 
    bool is_multi_first= false;
130
 
    int64_t indexes_found_in= 0;
131
 
    for (int32_t x= 0; x < table_message->indexes_size() ; x++)
132
 
    {
133
 
      const drizzled::message::Table::Index &index(table_message->indexes(x));
134
 
 
135
 
      for (int32_t y= 0; y < index.index_part_size() ; y++)
 
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
  assert(getTableProto().schema().length());
 
119
  assert(getTableProto().schema().c_str());
 
120
  push(getTableProto().schema());
 
121
 
 
122
  /* TABLE_NAME */
 
123
  push(getTableProto().name());
 
124
 
 
125
  /* COLUMN_NAME */
 
126
  push(column.name());
 
127
 
 
128
  /* COLUMN_TYPE */
 
129
  pushType(column.type());
 
130
 
 
131
  /* ORDINAL_POSITION */
 
132
  push(static_cast<int64_t>(column_iterator));
 
133
 
 
134
  /* COLUMN_DEFAULT */
 
135
  if (column.options().has_default_value())
 
136
  {
 
137
    push(column.options().default_value());
 
138
  }
 
139
  else if (column.options().has_default_bin_value())
 
140
  {
 
141
    push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
 
142
  }
 
143
  else
 
144
  {
 
145
    push();
 
146
  }
 
147
 
 
148
  /* COLUMN_DEFAULT_IS_NULL */
 
149
  push(column.options().default_null());
 
150
 
 
151
  /* COLUMN_DEFAULT_UPDATE */
 
152
  push(column.options().update_value());
 
153
 
 
154
  /* IS_NULLABLE */
 
155
  push(column.constraints().is_nullable());
 
156
 
 
157
  /* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
 
158
  bool is_indexed= false;
 
159
  bool is_primary= false;
 
160
  bool is_unique= false;
 
161
  bool is_multi= false;
 
162
  bool is_multi_first= false;
 
163
  int64_t indexes_found_in= 0;
 
164
  for (int32_t x= 0; x < getTableProto().indexes_size() ; x++)
 
165
  {
 
166
    drizzled::message::Table::Index index=
 
167
      getTableProto().indexes(x);
 
168
 
 
169
    for (int32_t y= 0; y < index.index_part_size() ; y++)
 
170
    {
 
171
      drizzled::message::Table::Index::IndexPart index_part=
 
172
        index.index_part(y);
 
173
 
 
174
      if (static_cast<int32_t>(index_part.fieldnr()) == column_iterator)
136
175
      {
137
 
        const drizzled::message::Table::Index::IndexPart &index_part(index.index_part(y));
138
 
 
139
 
        if (static_cast<int32_t>(index_part.fieldnr()) == field_iterator)
 
176
        indexes_found_in++;
 
177
        is_indexed= true;
 
178
 
 
179
        if (index.is_primary())
 
180
          is_primary= true;
 
181
 
 
182
        if (index.is_unique())
 
183
          is_unique= true;
 
184
 
 
185
        if (index.index_part_size() > 1)
140
186
        {
141
 
          indexes_found_in++;
142
 
          is_indexed= true;
143
 
 
144
 
          if (index.is_primary())
145
 
            is_primary= true;
146
 
 
147
 
          if (index.is_unique())
148
 
            is_unique= true;
149
 
 
150
 
          if (index.index_part_size() > 1)
151
 
          {
152
 
            is_multi= true;
153
 
 
154
 
            if (y == 0)
155
 
              is_multi_first= true;
156
 
          }
 
187
          is_multi= true;
 
188
 
 
189
          if (y == 0)
 
190
            is_multi_first= true;
157
191
        }
158
192
      }
159
193
    }
160
 
    /* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
161
 
    push(is_indexed);
162
 
    push(is_primary);
163
 
    push(is_unique);
164
 
    push(is_multi);
165
 
    push(is_multi_first);
166
 
    push(indexes_found_in);
167
 
 
168
 
    /* DATATYPE */
169
 
    push(drizzled::message::type(column.type()));
170
 
 
171
 
    /* "CHARACTER_MAXIMUM_LENGTH" */
172
 
    push(static_cast<int64_t>(column.string_options().length()));
173
 
 
174
 
    /* "CHARACTER_OCTET_LENGTH" */
175
 
    push(static_cast<int64_t>(column.string_options().length()) * 4);
176
 
 
177
 
    /* "NUMERIC_PRECISION" */
178
 
    push(static_cast<int64_t>(column.numeric_options().precision()));
179
 
 
180
 
    /* "NUMERIC_SCALE" */
181
 
    push(static_cast<int64_t>(column.numeric_options().scale()));
182
 
 
183
 
    /* "ENUM_VALUES" */
184
 
    if (column.type() == drizzled::message::Table::Field::ENUM)
185
 
    {
186
 
      string destination;
187
 
      size_t num_field_values= column.enumeration_values().field_value_size();
188
 
      for (size_t x= 0; x < num_field_values; ++x)
189
 
      {
190
 
        const string &type= column.enumeration_values().field_value(x);
191
 
 
192
 
        if (x != 0)
193
 
          destination.push_back(',');
194
 
 
195
 
        destination.push_back('\'');
196
 
        destination.append(type);
197
 
        destination.push_back('\'');
198
 
      }
199
 
      push(destination);
200
 
    }
201
 
    else
202
 
    {
203
 
      push();
204
 
    }
205
 
 
206
 
    /* "COLLATION_NAME" */
207
 
    push(column.string_options().collation());
208
 
 
209
 
    /* "COLUMN_COMMENT" */
210
 
    if (column.has_comment())
211
 
    {
212
 
      push(column.comment());
213
 
    }
214
 
    else
215
 
    {
216
 
      push();
217
 
    }
218
 
 
219
 
    return true;
220
 
  }
221
 
 
222
 
  return false;
 
194
  }
 
195
  /* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
 
196
  push(is_indexed);
 
197
  push(is_primary);
 
198
  push(is_unique);
 
199
  push(is_multi);
 
200
  push(is_multi_first);
 
201
  push(indexes_found_in);
 
202
 
 
203
  /* DATATYPE */
 
204
  pushType(column.type());
 
205
 
 
206
 /* "CHARACTER_MAXIMUM_LENGTH" */
 
207
  push(static_cast<int64_t>(column.string_options().length()));
 
208
 
 
209
 /* "CHARACTER_OCTET_LENGTH" */
 
210
  push(static_cast<int64_t>(column.string_options().length()) * 4);
 
211
 
 
212
 /* "NUMERIC_PRECISION" */
 
213
  push(static_cast<int64_t>(column.numeric_options().precision()));
 
214
 
 
215
 /* "NUMERIC_SCALE" */
 
216
  push(static_cast<int64_t>(column.numeric_options().scale()));
 
217
 
 
218
 /* "COLLATION_NAME" */
 
219
  push(column.string_options().collation());
 
220
 
 
221
 /* "COLUMN_COMMENT" */
 
222
  if (column.has_comment())
 
223
  {
 
224
    push(column.comment());
 
225
  }
 
226
  else
 
227
  {
 
228
    push();
 
229
  }
223
230
}