~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/data_engine/schemas.cc

Updating test cases + added Drizzle specific schema_names and schema_info.

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 <plugin/data_engine/dictionary.h>
 
22
 
 
23
using namespace std;
 
24
using namespace drizzled;
 
25
 
 
26
SchemaTool::SchemaTool() :
 
27
  Tool("SCHEMA_NAMES")
 
28
{
 
29
  add_field("SCHEMA_NAME", message::Table::Field::VARCHAR, 64);
 
30
}
 
31
 
 
32
SchemaTool::Generator::Generator()
 
33
{
 
34
  plugin::StorageEngine::getSchemaNames(set_of_names);
 
35
 
 
36
  it= set_of_names.begin();
 
37
}
 
38
 
 
39
bool SchemaTool::Generator::populate(Field ** fields)
 
40
{
 
41
  const CHARSET_INFO * const scs= system_charset_info;
 
42
  Field **field= fields;
 
43
 
 
44
  if (it == set_of_names.end())
 
45
    return false;
 
46
 
 
47
  (*field)->store((*it).c_str(), (*it).length(), scs);
 
48
 
 
49
  it++;
 
50
 
 
51
  return true;
 
52
}
 
53
 
 
54
SchemaFullTool::SchemaFullTool() :
 
55
  Tool("SCHEMA_INFO")
 
56
{
 
57
  add_field("SCHEMA_NAME", message::Table::Field::VARCHAR, 64);
 
58
  add_field("DEFAULT_COLLATION_NAME", message::Table::Field::VARCHAR, 64);
 
59
}
 
60
 
 
61
SchemaFullTool::Generator::Generator()
 
62
{
 
63
  plugin::StorageEngine::getSchemaNames(set_of_names);
 
64
 
 
65
  it= set_of_names.begin();
 
66
}
 
67
 
 
68
bool SchemaFullTool::Generator::populate(Field ** fields)
 
69
{
 
70
  message::Schema schema;
 
71
  const CHARSET_INFO * const scs= system_charset_info;
 
72
  Field **field= fields;
 
73
  bool error;
 
74
 
 
75
  if (it == set_of_names.end())
 
76
    return false;
 
77
 
 
78
  string schema_name= (*it);
 
79
  error= plugin::StorageEngine::getSchemaDefinition(schema_name, schema);
 
80
 
 
81
  if (error)
 
82
  {
 
83
    (*field)->store((*it).c_str(), (*it).length(), scs);
 
84
    field++;
 
85
 
 
86
    (*field)->store("<error>", sizeof("<error>"), scs);
 
87
  }
 
88
  else
 
89
  {
 
90
    (*field)->store(schema.name().c_str(), schema.name().length(), scs);
 
91
    field++;
 
92
 
 
93
    (*field)->store(schema.collation().c_str(), schema.collation().length(), scs);
 
94
  }
 
95
 
 
96
  it++;
 
97
 
 
98
  return true;
 
99
}