~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/data_engine/schemas.cc

Update code, first pass through cleaner method for recursing through
dictionary of table information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <plugin/data_engine/dictionary.h>
 
21
#include <plugin/data_engine/function.h>
22
22
#include <drizzled/charset.h>
23
23
 
24
24
using namespace std;
25
25
using namespace drizzled;
26
26
 
27
 
SchemataTool::SchemataTool() :
28
 
  Tool("SCHEMATA")
29
 
{
30
 
  add_field("CATALOG_NAME", message::Table::Field::VARCHAR, 512);
31
 
  add_field("SCHEMA_NAME", message::Table::Field::VARCHAR, 64);
32
 
  add_field("DEFAULT_CHARACTER_SET_NAME", message::Table::Field::VARCHAR, 64);
33
 
  add_field("DEFAULT_COLLATION_NAME", message::Table::Field::VARCHAR, 64);
34
 
  add_field("SQL_PATH", message::Table::Field::VARCHAR, 512);
35
 
}
36
 
 
37
 
SchemataTool::Generator::Generator()
38
 
{
39
 
  plugin::StorageEngine::getSchemaNames(set_of_names);
40
 
 
41
 
  it= set_of_names.begin();
42
 
}
43
 
 
44
 
bool SchemataTool::Generator::populate(Field ** fields)
45
 
{
46
 
  if (it == set_of_names.end())
 
27
SchemasTool::SchemasTool() :
 
28
  Tool("SCHEMAS")
 
29
{
 
30
  add_field("SCHEMA_NAME");
 
31
  add_field("DEFAULT_COLLATION_NAME");
 
32
}
 
33
 
 
34
SchemasTool::Generator::Generator(Field **arg) :
 
35
  Tool::Generator(arg),
 
36
  is_schema_primed(false),
 
37
  is_schema_parsed(false)
 
38
{
 
39
}
 
40
 
 
41
bool SchemasTool::Generator::nextSchema()
 
42
{
 
43
  if (is_schema_primed)
 
44
  {
 
45
    schema_iterator++;
 
46
  }
 
47
  else
 
48
  {
 
49
    plugin::StorageEngine::getSchemaNames(schema_names);
 
50
    schema_iterator= schema_names.begin();
 
51
    is_schema_primed= true;
 
52
  }
 
53
 
 
54
  if (schema_iterator == schema_names.end())
47
55
    return false;
48
56
 
49
 
  bool rc= fill(fields);
50
 
 
51
 
  it++;
52
 
 
53
 
  return rc;
54
 
}
55
 
 
56
 
bool SchemataTool::Generator::fill(Field ** fields)
57
 
{
58
 
  const CHARSET_INFO * const scs= system_charset_info;
59
 
  message::Schema schema;
60
 
  Field **field= fields;
61
 
  bool parsed;
62
 
 
63
 
  parsed= plugin::StorageEngine::getSchemaDefinition(schema_name(), schema);
64
 
 
65
 
  /* TABLE_CATALOG */
66
 
  (*field)->store("default", sizeof("default"), scs);
67
 
  field++;
68
 
 
69
 
  if (not parsed)
70
 
  {
71
 
    (*field)->store(schema_name().c_str(), schema_name().length(), scs);
72
 
    field++;
73
 
 
74
 
    for (; *field ; field++)
75
 
      (*field)->store("<error>", sizeof("<error>"), scs);
76
 
 
77
 
    return true;
78
 
  }
79
 
 
80
 
  /* SCHEMA_NAME */
81
 
  (*field)->store(schema.name().c_str(), schema.name().length(), scs);
82
 
  field++;
83
 
 
84
 
  /* DEFAULT_CHARACTER_SET_NAME */
85
 
  (*field)->store("utf8", sizeof("utf8"), scs);
86
 
  field++;
87
 
 
88
 
  /* DEFAULT_COLLATION_NAME */
89
 
  (*field)->store(schema.collation().c_str(), schema.collation().length(), scs);
90
 
  field++;
91
 
 
92
 
  for (; *field ; field++)
93
 
  {
94
 
    (*field)->store("<not implemented>", sizeof("<not implemented>"), scs);
95
 
  }
96
 
 
97
 
  return true;
98
 
}
99
 
 
100
 
SchemataNamesTool::SchemataNamesTool() :
101
 
  SchemataTool("SCHEMATA_NAMES")
102
 
{
103
 
  add_field("SCHEMA_NAME", message::Table::Field::VARCHAR, 64);
104
 
}
105
 
 
106
 
bool SchemataNamesTool::Generator::fill(Field ** fields)
107
 
{
108
 
  const CHARSET_INFO * const scs= system_charset_info;
109
 
  Field **field= fields;
110
 
 
111
 
  (*field)->store(schema_name().c_str(), schema_name().length(), scs);
112
 
 
113
 
  return true;
114
 
}
115
 
 
116
 
SchemataInfoTool::SchemataInfoTool() :
117
 
  SchemataTool("SCHEMATA_INFO")
118
 
{
119
 
  add_field("SCHEMA_NAME", message::Table::Field::VARCHAR, 64);
120
 
  add_field("DEFAULT_COLLATION_NAME", message::Table::Field::VARCHAR, 64);
121
 
}
122
 
 
123
 
bool SchemataInfoTool::Generator::fill(Field ** fields)
124
 
{
125
 
  const CHARSET_INFO * const scs= system_charset_info;
126
 
  message::Schema schema;
127
 
  Field **field= fields;
128
 
  bool parsed;
129
 
 
130
 
  parsed= plugin::StorageEngine::getSchemaDefinition(schema_name(), schema);
131
 
 
132
 
  if (not parsed)
133
 
  {
134
 
    (*field)->store(schema_name().c_str(), schema_name().length(), scs);
135
 
    field++;
136
 
 
137
 
    for (; *field ; field++)
138
 
      (*field)->store("<error>", sizeof("<error>"), scs);
139
 
 
140
 
    return true;
141
 
  }
142
 
 
143
 
  /* SCHEMA_NAME */
144
 
  (*field)->store(schema.name().c_str(), schema.name().length(), scs);
145
 
  field++;
146
 
 
147
 
  /* DEFAULT_COLLATION_NAME */
148
 
  (*field)->store(schema.collation().c_str(), schema.collation().length(), scs);
149
 
 
150
 
  return true;
 
57
  schema.Clear();
 
58
  is_schema_parsed= plugin::StorageEngine::getSchemaDefinition(*schema_iterator, schema);
 
59
 
 
60
  return true;
 
61
}
 
62
  
 
63
 
 
64
 
 
65
bool SchemasTool::Generator::populate(Field **)
 
66
{
 
67
  if (nextSchema())
 
68
  {
 
69
    fill();
 
70
    return true;
 
71
  }
 
72
 
 
73
  return false;
 
74
}
 
75
 
 
76
/**
 
77
  A lack of a parsed schema file means we are using defaults.
 
78
*/
 
79
void SchemasTool::Generator::fill()
 
80
{
 
81
  /* SCHEMA_NAME */
 
82
  push(schema.name());
 
83
 
 
84
  /* DEFAULT_COLLATION_NAME */
 
85
  if (is_schema_parsed)
 
86
    push(schema.collation());
 
87
  else
 
88
    push(scs->name);
151
89
}