~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/embedded_innodb/libinnodb_version_func.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

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_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
 
 
82
int libinnodb_version_func_initialize(plugin::Context &context)
 
83
{
 
84
  libinnodb_version_func= new plugin::Create_function<LibinnodbVersionFunction>("libinnodb_version");
 
85
  context.add(libinnodb_version_func);
 
86
  return 0;
 
87
}