drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
information_schema_dictionary/table_constraints.cc
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Brian Aker
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/information_schema_dictionary/dictionary.h>
23
24using namespace std;
25using namespace drizzled;
26
27TableConstraints::TableConstraints() :
28 InformationSchema("TABLE_CONSTRAINTS")
29{
30 add_field("CONSTRAINT_CATALOG", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
31 add_field("CONSTRAINT_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
32 add_field("CONSTRAINT_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
33 add_field("TABLE_CATALOG", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
34 add_field("TABLE_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
35 add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
36 add_field("CONSTRAINT_TYPE");
37 add_field("IS_DEFERRABLE", plugin::TableFunction::BOOLEAN, 0, false);
38 add_field("INITIALLY_DEFERRED", plugin::TableFunction::BOOLEAN, 0, false);
39}
40
41TableConstraints::Generator::Generator(drizzled::Field **arg) :
42 InformationSchema::Generator(arg),
43 generator(getSession()),
44 index_iterator(0)
45{
46 while (not (table_message= generator))
47 { };
48}
49
50bool TableConstraints::Generator::populate()
51{
52 if (not table_message)
53 return false;
54
55 do
56 {
57 if (index_iterator != table_message->indexes_size())
58 {
59 drizzled::message::Table::Index index= table_message->indexes(index_iterator);
60
61 index_iterator++;
62
63 if (index.is_primary() || index.is_unique())
64 {
65 /* Constraints live in the same catalog.schema as the table they refer too. */
66 /* CONSTRAINT_CATALOG */
67 push(table_message->catalog());
68
69 /* CONSTRAINT_SCHEMA */
70 push(table_message->schema());
71
72 /* CONSTRAINT_NAME */
73 push(index.name());
74
75 /* TABLE_CATALOG */
76 push(table_message->catalog());
77
78 /* TABLE_SCHEMA */
79 push(table_message->schema());
80
81 /* TABLE_NAME */
82 push(table_message->name());
83
84 /* CONSTRAINT_TYPE */
85 if (index.is_primary())
86 {
87 push("PRIMARY KEY");
88 }
89 else if (index.is_unique())
90 {
91 push("UNIQUE");
92 }
93 else
94 {
95 assert(0);
96 push("UNIQUE");
97 }
98
99 /* IS_DEFERRABLE */
100 push(false);
101
102 /* INITIALLY_DEFERRED */
103 push(false);
104
105 return true;
106 }
107 }
108
109 index_iterator= 0;
110
111 } while ((table_message= generator));
112
113 return false;
114}
TODO: Rename this file - func.h is stupid.
STL namespace.
const char * name
Definition dict0mem.h:331