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 "haildb_datadict_dump_func.h"
32
using namespace drizzled;
34
class HailDBDatadictDumpFunction : public Item_str_func
37
HailDBDatadictDumpFunction() : Item_str_func() {}
38
String *val_str(String*);
40
void fix_length_and_dec()
45
const char *func_name() const
47
return "haildb_datadict_dump";
50
bool check_argument_count(int n)
56
struct schema_visitor_arg
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)
68
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param;
71
ss << name << " Format: ";
75
case IB_TBL_REDUNDANT:
84
case IB_TBL_COMPRESSED:
88
ss << "UNKNOWN(" << tbl_fmt << ") ";
91
ss << "Page size: " << page_size
92
<< " Columns: " << n_cols
93
<< " Indexes: " << n_indexes
96
arg->str->append(ss.str());
101
static int visit_table_col(void *arg_param, const char* name, ib_col_type_t, ib_ulint_t, ib_col_attr_t)
103
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param;
104
std::stringstream ss;
106
ss << " COL: " << name << endl;
108
arg->str->append(ss.str());
113
static int visit_index(void *arg_param, const char* name, ib_bool_t, ib_bool_t, int)
115
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param;
116
std::stringstream ss;
118
ss << " IDX: " << name << endl;
120
arg->str->append(ss.str());
125
static int visit_index_col(void* arg_param, const char* name, ib_ulint_t)
127
struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param;
128
std::stringstream ss;
130
ss << " IDXCOL: " << name << endl;
132
arg->str->append(ss.str());
139
static const ib_schema_visitor_t visitor = {
140
IB_SCHEMA_VISITOR_TABLE_AND_INDEX_COL,
150
static int visit_tables(void* arg_param, const char *name, int len)
153
struct schema_visitor_arg *arg = (struct schema_visitor_arg*) arg_param;
154
string table_name(name, len);
156
err= ib_table_schema_visit(arg->transaction, table_name.c_str(), &visitor, arg_param);
158
return(err == DB_SUCCESS ? 0 : -1);
162
String *HailDBDatadictDumpFunction::val_str(String *str)
169
string dict_dump("HailDB Data Dictionary Contents\n"
170
"-------------------------------\n");
172
struct schema_visitor_arg arg;
174
arg.transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
176
ib_err_t err= ib_schema_lock_exclusive(arg.transaction);
178
err = ib_schema_tables_iterate(arg.transaction, visit_tables, &arg);
180
str->alloc(dict_dump.length());
181
str->length(dict_dump.length());
182
strncpy(str->ptr(), dict_dump.c_str(), dict_dump.length());
184
ib_schema_unlock(arg.transaction);
186
err= ib_trx_rollback(arg.transaction);
187
assert (err == DB_SUCCESS);
193
plugin::Create_function<HailDBDatadictDumpFunction> *haildb_datadict_dump_func= NULL;
195
int haildb_datadict_dump_func_initialize(module::Context &context)
197
haildb_datadict_dump_func= new plugin::Create_function<HailDBDatadictDumpFunction>("haildb_datadict_dump");
198
context.add(haildb_datadict_dump_func);