2
Copyright (C) 2010 Stewart Smith
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.
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.
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.
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"
26
#include "embedded_innodb-1.0/innodb.h"
32
using namespace drizzled;
34
class LibinnodbDatadictDumpFunction : public Item_str_func
37
LibinnodbDatadictDumpFunction() : Item_str_func() {}
38
String *val_str(String*);
40
void fix_length_and_dec()
45
const char *func_name() const
47
return "libinnodb_datadict_dump";
50
bool check_argument_count(int n)
56
struct schema_visitor_arg
62
static int visit_table(void* arg_param, const char* name, ib_tbl_fmt_t tbl_fmt,
63
ib_ulint_t page_size, int n_cols, int n_indexes)
65
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param;
68
ss << name << " Format: ";
72
case IB_TBL_REDUNDANT:
81
case IB_TBL_COMPRESSED:
85
ss << "UNKNOWN(" << tbl_fmt << ") ";
88
ss << "Page size: " << page_size
89
<< " Columns: " << n_cols
90
<< " Indexes: " << n_indexes
93
arg->str->append(ss.str());
98
static int visit_table_col(void *, const char*, ib_col_type_t, ib_ulint_t, ib_col_attr_t)
103
static int visit_index(void *, const char*, ib_bool_t, ib_bool_t, int)
108
static int visit_index_col(void*, const char*, ib_ulint_t)
113
static const ib_schema_visitor_t visitor = {
114
IB_SCHEMA_VISITOR_TABLE_AND_INDEX_COL,
121
static int visit_tables(void* arg_param, const char *name, int len)
124
struct schema_visitor_arg *arg = (struct schema_visitor_arg*) arg_param;
125
string table_name(name, len);
127
err= ib_table_schema_visit(arg->transaction, table_name.c_str(), &visitor, arg_param);
129
return(err == DB_SUCCESS ? 0 : -1);
132
String *LibinnodbDatadictDumpFunction::val_str(String *str)
134
assert(fixed == true);
144
string dict_dump("InnoDB Data Dictionary Contents\n"
145
"-------------------------------\n");
147
struct schema_visitor_arg arg;
149
arg.transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
151
ib_err_t err= ib_schema_lock_exclusive(arg.transaction);
153
err = ib_schema_tables_iterate(arg.transaction, visit_tables, &arg);
155
str->alloc(dict_dump.length());
156
str->length(dict_dump.length());
157
strncpy(str->ptr(), dict_dump.c_str(), dict_dump.length());
159
ib_schema_unlock(arg.transaction);
161
err= ib_trx_rollback(arg.transaction);
162
assert (err == DB_SUCCESS);
168
plugin::Create_function<LibinnodbDatadictDumpFunction> *libinnodb_datadict_dump_func= NULL;
170
int libinnodb_datadict_dump_func_initialize(plugin::Context &context)
172
libinnodb_datadict_dump_func= new plugin::Create_function<LibinnodbDatadictDumpFunction>("libinnodb_datadict_dump");
173
context.add(libinnodb_datadict_dump_func);