1
/* vim: expandtab:shiftwidth=2:tabstop=2:smarttab:
2
Copyright (C) 2009 Sun Microsystems
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
#include <drizzled/server_includes.h>
18
#include <drizzled/plugin/function.h>
19
#include <drizzled/item/func.h>
20
#include <drizzled/function/str/strfunc.h>
21
#include <drizzled/error.h>
22
#include <drizzled/current_session.h>
23
#include <drizzled/db.h>
28
#include <drizzled/message/schema.pb.h>
29
#include <google/protobuf/io/zero_copy_stream.h>
30
#include <google/protobuf/io/zero_copy_stream_impl.h>
31
#include <google/protobuf/text_format.h>
34
using namespace drizzled;
35
using namespace google;
37
class ShowSchemaProtoFunction : public Item_str_func
40
ShowSchemaProtoFunction() : Item_str_func() {}
41
String *val_str(String*);
43
void fix_length_and_dec()
45
max_length= 16384; /* Guesswork? */
46
args[0]->collation.set(
47
get_charset_by_csname(args[0]->collation.collation->csname,
48
MY_CS_BINSORT), DERIVATION_COERCIBLE);
51
const char *func_name() const
53
return "show_schema_proto";
56
bool check_argument_count(int n)
63
String *ShowSchemaProtoFunction::val_str(String *str)
65
assert(fixed == true);
67
String *db_sptr= args[0]->val_str(str);
77
const char* db= db_sptr->c_ptr_safe();
79
string proto_as_text("");
80
message::Schema proto;
82
int err= get_database_metadata(db, &proto);
86
my_error(ER_BAD_DB_ERROR, MYF(0), db);
90
protobuf::TextFormat::PrintToString(proto, &proto_as_text);
92
if (str->alloc(proto_as_text.length()))
98
str->length(proto_as_text.length());
100
strncpy(str->ptr(),proto_as_text.c_str(), proto_as_text.length());
105
plugin::Create_function<ShowSchemaProtoFunction> *show_schema_proto_func= NULL;
107
static int initialize(plugin::Registry ®istry)
109
show_schema_proto_func= new plugin::Create_function<ShowSchemaProtoFunction>("show_schema_proto");
110
registry.add(show_schema_proto_func);
114
static int finalize(plugin::Registry ®istry)
116
registry.remove(show_schema_proto_func);
117
delete show_schema_proto_func;
121
DRIZZLE_DECLARE_PLUGIN
126
"Shows text representation of schema definition proto",
128
initialize, /* Plugin Init */
129
finalize, /* Plugin Deinit */
130
NULL, /* status variables */
131
NULL, /* system variables */
132
NULL /* config options */
134
DRIZZLE_DECLARE_PLUGIN_END;