~drizzle-trunk/drizzle/development

1283.3.5 by Stewart Smith
add LIBINNODB_VERSION() function
1
/*
2
  Copyright (C) 2010 Stewart Smith
3
4
  This program is free software; you can redistribute it and/or
1283.3.6 by Stewart Smith
fix (C) notice in libinnodb_version_func
5
  modify it under the terms of the GNU General Public License
1283.3.5 by Stewart Smith
add LIBINNODB_VERSION() function
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_version_func.h"
25
26
#include "embedded_innodb-1.0/innodb.h"
27
28
using namespace std;
29
using namespace drizzled;
30
31
class LibinnodbVersionFunction : public Item_str_func
32
{
33
public:
34
  LibinnodbVersionFunction() : Item_str_func() {}
35
  String *val_str(String*);
36
37
  void fix_length_and_dec()
38
  {
39
    max_length= 32;
40
  }
41
42
  const char *func_name() const
43
  {
44
    return "libinnodb_version";
45
  }
46
47
  bool check_argument_count(int n)
48
  {
49
    return (n == 0);
50
  }
51
};
52
53
54
String *LibinnodbVersionFunction::val_str(String *str)
55
{
56
  assert(fixed == true);
57
58
  if (str->alloc(50))
59
  {
60
    null_value= true;
61
    return 0;
62
  }
63
64
  null_value= false;
65
66
  uint64_t version= ib_api_version();
67
68
  int len= snprintf((char *) str->ptr(), 50,
69
                    "Release %"PRIx64", Revision %"PRIx64", Age %"PRIx64,
70
                    version >> 32,
71
                    (version >> 16) & 0xffff,
72
                    version & 0xffff);
73
74
  str->length(len);
75
76
  return str;
77
}
78
79
80
plugin::Create_function<LibinnodbVersionFunction> *libinnodb_version_func= NULL;
81
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
82
int libinnodb_version_func_initialize(module::Context &context)
1283.3.5 by Stewart Smith
add LIBINNODB_VERSION() function
83
{
84
  libinnodb_version_func= new plugin::Create_function<LibinnodbVersionFunction>("libinnodb_version");
1283.7.15 by Stewart Smith
merge plugin init with trunk: plugin::Context instead of Registry
85
  context.add(libinnodb_version_func);
1283.3.5 by Stewart Smith
add LIBINNODB_VERSION() function
86
  return 0;
87
}