~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/embedded_innodb/libinnodb_datadict_dump_func.cc

  • Committer: Jay Pipes
  • Date: 2010-04-08 16:27:25 UTC
  • mfrom: (1405.6.10 replication-pairs)
  • mto: This revision was merged to the branch mainline in revision 1457.
  • Revision ID: jpipes@serialcoder-20100408162725-sugbgn38oxjqclq2
Merge trunk and replication-pairs with conflict resolution

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
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)
 
64
{
 
65
  struct schema_visitor_arg *arg= (struct schema_visitor_arg*)arg_param;
 
66
  std::stringstream ss;
 
67
 
 
68
  ss << name << " Format: ";
 
69
 
 
70
  switch (tbl_fmt)
 
71
  {
 
72
  case IB_TBL_REDUNDANT:
 
73
    ss << "REDUNDANT ";
 
74
    break;
 
75
  case IB_TBL_COMPACT:
 
76
    ss << "COMPACT ";
 
77
    break;
 
78
  case IB_TBL_DYNAMIC:
 
79
    ss << "DYNAMIC ";
 
80
    break;
 
81
  case IB_TBL_COMPRESSED:
 
82
    ss << "COMPRESSED ";
 
83
    break;
 
84
  default:
 
85
    ss << "UNKNOWN(" << tbl_fmt << ") ";
 
86
  }
 
87
 
 
88
  ss << "Page size: " << page_size
 
89
     << " Columns: " << n_cols
 
90
     << " Indexes: " << n_indexes
 
91
     << endl;
 
92
 
 
93
  arg->str->append(ss.str());
 
94
 
 
95
  return 0;
 
96
}
 
97
 
 
98
static int visit_table_col(void *, const char*, ib_col_type_t, ib_ulint_t, ib_col_attr_t)
 
99
{
 
100
  return 0;
 
101
}
 
102
 
 
103
static int visit_index(void *, const char*, ib_bool_t, ib_bool_t, int)
 
104
{
 
105
  return 0;
 
106
}
 
107
 
 
108
static int visit_index_col(void*, const char*, ib_ulint_t)
 
109
{
 
110
  return 0;
 
111
}
 
112
 
 
113
static const ib_schema_visitor_t visitor = {
 
114
  IB_SCHEMA_VISITOR_TABLE_AND_INDEX_COL,
 
115
  visit_table,
 
116
  visit_table_col,
 
117
  visit_index,
 
118
  visit_index_col
 
119
};
 
120
 
 
121
static int visit_tables(void* arg_param, const char *name, int len)
 
122
{
 
123
  ib_err_t        err;
 
124
  struct schema_visitor_arg *arg = (struct schema_visitor_arg*) arg_param;
 
125
  string table_name(name, len);
 
126
 
 
127
  err= ib_table_schema_visit(arg->transaction, table_name.c_str(), &visitor, arg_param);
 
128
 
 
129
  return(err == DB_SUCCESS ? 0 : -1);
 
130
}
 
131
 
 
132
String *LibinnodbDatadictDumpFunction::val_str(String *str)
 
133
{
 
134
  assert(fixed == true);
 
135
 
 
136
  if (str->alloc(50))
 
137
  {
 
138
    null_value= true;
 
139
    return 0;
 
140
  }
 
141
 
 
142
  null_value= false;
 
143
 
 
144
  string dict_dump("InnoDB Data Dictionary Contents\n"
 
145
                   "-------------------------------\n");
 
146
 
 
147
  struct schema_visitor_arg arg;
 
148
  arg.str= &dict_dump;
 
149
  arg.transaction=  ib_trx_begin(IB_TRX_REPEATABLE_READ);
 
150
 
 
151
  ib_err_t err= ib_schema_lock_exclusive(arg.transaction);
 
152
 
 
153
  err = ib_schema_tables_iterate(arg.transaction, visit_tables, &arg);
 
154
 
 
155
  str->alloc(dict_dump.length());
 
156
  str->length(dict_dump.length());
 
157
  strncpy(str->ptr(), dict_dump.c_str(), dict_dump.length());
 
158
 
 
159
  ib_schema_unlock(arg.transaction);
 
160
 
 
161
  err= ib_trx_rollback(arg.transaction);
 
162
  assert (err == DB_SUCCESS);
 
163
 
 
164
  return str;
 
165
}
 
166
 
 
167
 
 
168
plugin::Create_function<LibinnodbDatadictDumpFunction> *libinnodb_datadict_dump_func= NULL;
 
169
 
 
170
int libinnodb_datadict_dump_func_initialize(plugin::Context &context)
 
171
{
 
172
  libinnodb_datadict_dump_func= new plugin::Create_function<LibinnodbDatadictDumpFunction>("libinnodb_datadict_dump");
 
173
  context.add(libinnodb_datadict_dump_func);
 
174
  return 0;
 
175
}