~drizzle-trunk/drizzle/development

1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
1
/* vim: expandtab:shiftwidth=2:tabstop=2:smarttab:
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
2
   Copyright (C) 2009 Sun Microsystems, Inc.
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
3
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.
7
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.
12
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 */
16
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
17
#include <config.h>
2148.7.12 by Brian Aker
Merge in header fixes.
18
19
#include <drizzled/charset.h>
20
#include <drizzled/error.h>
21
#include <drizzled/function/str/strfunc.h>
22
#include <drizzled/internal/my_sys.h>
23
#include <drizzled/item/func.h>
24
#include <drizzled/message/schema.h>
25
#include <drizzled/plugin/function.h>
26
#include <drizzled/plugin/storage_engine.h>
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
27
2148.7.12 by Brian Aker
Merge in header fixes.
28
#include <iostream>
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
29
#include <stdio.h>
30
#include <string>
2148.7.12 by Brian Aker
Merge in header fixes.
31
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
32
#include <google/protobuf/io/zero_copy_stream.h>
33
#include <google/protobuf/io/zero_copy_stream_impl.h>
34
#include <google/protobuf/text_format.h>
35
36
using namespace std;
37
using namespace drizzled;
38
using namespace google;
39
40
class ShowSchemaProtoFunction : public Item_str_func
41
{
42
public:
43
  ShowSchemaProtoFunction() : Item_str_func() {}
44
  String *val_str(String*);
45
46
  void fix_length_and_dec()
47
  {
48
    max_length= 16384; /* Guesswork? */
49
    args[0]->collation.set(
50
      get_charset_by_csname(args[0]->collation.collation->csname,
51
                            MY_CS_BINSORT), DERIVATION_COERCIBLE);
52
  }
53
54
  const char *func_name() const
55
  {
56
    return "show_schema_proto";
57
  }
58
59
  bool check_argument_count(int n)
60
  {
61
    return (n == 1);
62
  }
63
};
64
65
66
String *ShowSchemaProtoFunction::val_str(String *str)
67
{
68
  assert(fixed == true);
69
70
  String *db_sptr= args[0]->val_str(str);
71
72
  if (db_sptr == NULL)
73
  {
74
    null_value= true;
75
    return NULL;
76
  }
77
78
  null_value= false;
79
2318.7.11 by Olaf van der Spek
Use String::c_str() instead of c_ptr_safe()
80
  const char* db= db_sptr->c_str();
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
81
82
  string proto_as_text("");
1966.2.1 by Brian Aker
Clean up style for shared_ptr for messages around table/schema.
83
  message::schema::shared_ptr proto;
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
84
85
2087.4.1 by Brian Aker
Merge in schema identifier.
86
  identifier::Schema schema_identifier(db);
2159.2.1 by Brian Aker
Remove the pass by reference, it really wasn't a good choice.
87
  if (not (proto= plugin::StorageEngine::getSchemaDefinition(schema_identifier)))
2159.2.2 by Brian Aker
Remove additional spot where we passed in a reference of a shared pointer.
88
  {
2159.2.1 by Brian Aker
Remove the pass by reference, it really wasn't a good choice.
89
    my_error(ER_BAD_DB_ERROR, schema_identifier);
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
90
    return NULL;
91
  }
92
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
93
  protobuf::TextFormat::PrintToString(*proto, &proto_as_text);
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
94
2275.2.12 by Olaf van der Spek
Return void
95
  str->alloc(proto_as_text.length());
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
96
  str->length(proto_as_text.length());
97
98
  strncpy(str->ptr(),proto_as_text.c_str(), proto_as_text.length());
99
100
  return str;
101
}
102
103
plugin::Create_function<ShowSchemaProtoFunction> *show_schema_proto_func= NULL;
104
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
105
static int initialize(module::Context &context)
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
106
{
107
  show_schema_proto_func= new plugin::Create_function<ShowSchemaProtoFunction>("show_schema_proto");
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
108
  context.add(show_schema_proto_func);
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
109
  return 0;
110
}
111
112
DRIZZLE_DECLARE_PLUGIN
113
{
1241.10.2 by Monty Taylor
Added support for embedding the drizzle version number in the plugin file.
114
  DRIZZLE_VERSION_ID,
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
115
  "show_schema_proto",
116
  "1.0",
117
  "Stewart Smith",
118
  "Shows text representation of schema definition proto",
119
  PLUGIN_LICENSE_GPL,
120
  initialize, /* Plugin Init */
2095.3.1 by Monty Taylor
Re-purpose the old plugin sysvar slot in the struct to be a depends list.
121
  NULL,   /* depends */
1240.5.1 by Stewart Smith
small SHOW_SCHEMA_PROTO() function (like SHOW_TABLE_PROTO()) to show content of Schema proto message in db.opt to test what we're storing.
122
  NULL    /* config options */
123
}
124
DRIZZLE_DECLARE_PLUGIN_END;