1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
1 |
/*
|
2 |
Copyright (C) 2010 Stewart Smith
|
|
3 |
||
4 |
This program is free software; you can redistribute it and/or
|
|
5 |
modify it under the terms of the GNU General Public License
|
|
6 |
as published by the Free Software Foundation; either version 2
|
|
7 |
of the License, or (at your option) any later version.
|
|
8 |
||
9 |
This program is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU General Public License for more details.
|
|
13 |
||
14 |
You should have received a copy of the GNU General Public License
|
|
15 |
along with this program; if not, write to the Free Software
|
|
16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 |
*/
|
|
18 |
||
19 |
#include "config.h" |
|
20 |
#include <drizzled/plugin/function.h> |
|
21 |
#include <drizzled/item/func.h> |
|
22 |
#include "drizzled/charset.h" |
|
23 |
#include <drizzled/function/str/strfunc.h> |
|
24 |
#include "libinnodb_datadict_dump_func.h" |
|
25 |
||
26 |
#include "embedded_innodb-1.0/innodb.h" |
|
27 |
||
28 |
#include <sstream> |
|
29 |
#include <string> |
|
30 |
||
31 |
using namespace std; |
|
32 |
using namespace drizzled; |
|
33 |
||
34 |
class LibinnodbDatadictDumpFunction : public Item_str_func |
|
35 |
{
|
|
36 |
public: |
|
37 |
LibinnodbDatadictDumpFunction() : Item_str_func() {} |
|
38 |
String *val_str(String*); |
|
39 |
||
40 |
void fix_length_and_dec() |
|
41 |
{
|
|
42 |
max_length= 32767; |
|
43 |
}
|
|
44 |
||
45 |
const char *func_name() const |
|
46 |
{
|
|
47 |
return "libinnodb_datadict_dump"; |
|
48 |
}
|
|
49 |
||
50 |
bool check_argument_count(int n) |
|
51 |
{
|
|
52 |
return (n == 0); |
|
53 |
}
|
|
54 |
};
|
|
55 |
||
56 |
struct schema_visitor_arg |
|
57 |
{
|
|
58 |
ib_trx_t transaction; |
|
59 |
string *str; |
|
60 |
};
|
|
61 |
||
1645.1.3
by Monty Taylor
Fixed a compile issue on Solaris. |
62 |
extern "C" |
63 |
{
|
|
64 |
||
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
65 |
static int visit_table(void* arg_param, const char* name, ib_tbl_fmt_t tbl_fmt, |
66 |
ib_ulint_t page_size, int n_cols, int n_indexes) |
|
67 |
{
|
|
68 |
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param; |
|
1283.10.3
by Stewart Smith
correct production of libinnodb_datadict_dump string. |
69 |
std::stringstream ss; |
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
70 |
|
71 |
ss << name << " Format: "; |
|
72 |
||
73 |
switch (tbl_fmt) |
|
74 |
{
|
|
75 |
case IB_TBL_REDUNDANT: |
|
76 |
ss << "REDUNDANT "; |
|
77 |
break; |
|
78 |
case IB_TBL_COMPACT: |
|
79 |
ss << "COMPACT "; |
|
80 |
break; |
|
81 |
case IB_TBL_DYNAMIC: |
|
82 |
ss << "DYNAMIC "; |
|
83 |
break; |
|
84 |
case IB_TBL_COMPRESSED: |
|
85 |
ss << "COMPRESSED "; |
|
86 |
break; |
|
87 |
default: |
|
88 |
ss << "UNKNOWN(" << tbl_fmt << ") "; |
|
89 |
}
|
|
90 |
||
91 |
ss << "Page size: " << page_size |
|
92 |
<< " Columns: " << n_cols |
|
93 |
<< " Indexes: " << n_indexes |
|
94 |
<< endl; |
|
95 |
||
96 |
arg->str->append(ss.str()); |
|
97 |
||
98 |
return 0; |
|
99 |
}
|
|
100 |
||
1283.60.6
by Stewart Smith
update libinnodb_datadict_dump_func() to dump some more information from the InnoDB data dictionary. |
101 |
static int visit_table_col(void *arg_param, const char* name, ib_col_type_t, ib_ulint_t, ib_col_attr_t) |
102 |
{
|
|
103 |
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param; |
|
104 |
std::stringstream ss; |
|
105 |
||
106 |
ss << " COL: " << name << endl; |
|
107 |
||
108 |
arg->str->append(ss.str()); |
|
109 |
||
110 |
return 0; |
|
111 |
}
|
|
112 |
||
113 |
static int visit_index(void *arg_param, const char* name, ib_bool_t, ib_bool_t, int) |
|
114 |
{
|
|
115 |
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param; |
|
116 |
std::stringstream ss; |
|
117 |
||
118 |
ss << " IDX: " << name << endl; |
|
119 |
||
120 |
arg->str->append(ss.str()); |
|
121 |
||
122 |
return 0; |
|
123 |
}
|
|
124 |
||
125 |
static int visit_index_col(void* arg_param, const char* name, ib_ulint_t) |
|
126 |
{
|
|
127 |
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param; |
|
128 |
std::stringstream ss; |
|
129 |
||
130 |
ss << " IDXCOL: " << name << endl; |
|
131 |
||
132 |
arg->str->append(ss.str()); |
|
133 |
||
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
134 |
return 0; |
135 |
}
|
|
136 |
||
1645.1.3
by Monty Taylor
Fixed a compile issue on Solaris. |
137 |
}
|
138 |
||
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
139 |
static const ib_schema_visitor_t visitor = { |
140 |
IB_SCHEMA_VISITOR_TABLE_AND_INDEX_COL, |
|
141 |
visit_table, |
|
142 |
visit_table_col, |
|
143 |
visit_index, |
|
144 |
visit_index_col
|
|
145 |
};
|
|
146 |
||
1645.1.5
by Monty Taylor
More Solaris build fixes. |
147 |
extern "C" |
148 |
{
|
|
149 |
||
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
150 |
static int visit_tables(void* arg_param, const char *name, int len) |
151 |
{
|
|
152 |
ib_err_t err; |
|
153 |
struct schema_visitor_arg *arg = (struct schema_visitor_arg*) arg_param; |
|
154 |
string table_name(name, len); |
|
155 |
||
156 |
err= ib_table_schema_visit(arg->transaction, table_name.c_str(), &visitor, arg_param); |
|
157 |
||
158 |
return(err == DB_SUCCESS ? 0 : -1); |
|
159 |
}
|
|
160 |
||
1645.1.5
by Monty Taylor
More Solaris build fixes. |
161 |
}
|
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
162 |
String *LibinnodbDatadictDumpFunction::val_str(String *str) |
163 |
{
|
|
164 |
assert(fixed == true); |
|
165 |
||
166 |
if (str->alloc(50)) |
|
167 |
{
|
|
168 |
null_value= true; |
|
169 |
return 0; |
|
170 |
}
|
|
171 |
||
172 |
null_value= false; |
|
173 |
||
174 |
string dict_dump("InnoDB Data Dictionary Contents\n" |
|
175 |
"-------------------------------\n"); |
|
176 |
||
177 |
struct schema_visitor_arg arg; |
|
178 |
arg.str= &dict_dump; |
|
179 |
arg.transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ); |
|
180 |
||
181 |
ib_err_t err= ib_schema_lock_exclusive(arg.transaction); |
|
182 |
||
183 |
err = ib_schema_tables_iterate(arg.transaction, visit_tables, &arg); |
|
184 |
||
1283.10.3
by Stewart Smith
correct production of libinnodb_datadict_dump string. |
185 |
str->alloc(dict_dump.length()); |
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
186 |
str->length(dict_dump.length()); |
1283.10.3
by Stewart Smith
correct production of libinnodb_datadict_dump string. |
187 |
strncpy(str->ptr(), dict_dump.c_str(), dict_dump.length()); |
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
188 |
|
1283.10.6
by Stewart Smith
unlock datadict and rollback transaction after having dumped innodb datadict |
189 |
ib_schema_unlock(arg.transaction); |
1283.10.17
by Stewart Smith
check return code of ib_trx_rollback() in datadict_dump function. We just assert on it being successful as this function is for debug purposes only. |
190 |
|
191 |
err= ib_trx_rollback(arg.transaction); |
|
192 |
assert (err == DB_SUCCESS); |
|
1283.10.6
by Stewart Smith
unlock datadict and rollback transaction after having dumped innodb datadict |
193 |
|
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
194 |
return str; |
195 |
}
|
|
196 |
||
197 |
||
198 |
plugin::Create_function<LibinnodbDatadictDumpFunction> *libinnodb_datadict_dump_func= NULL; |
|
199 |
||
1530.2.6
by Monty Taylor
Moved plugin::Context to module::Context. |
200 |
int libinnodb_datadict_dump_func_initialize(module::Context &context) |
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
201 |
{
|
202 |
libinnodb_datadict_dump_func= new plugin::Create_function<LibinnodbDatadictDumpFunction>("libinnodb_datadict_dump"); |
|
1283.10.24
by Stewart Smith
merge trunk |
203 |
context.add(libinnodb_datadict_dump_func); |
1283.10.2
by Stewart Smith
simple LIBINNODB_DATADICT_DUMP() function to dump contents of libinnodb data dict as string. |
204 |
return 0; |
205 |
}
|