~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/haildb_version_func.cc

  • Committer: Barry.Leslie at PrimeBase
  • Date: 2010-10-20 20:41:00 UTC
  • mfrom: (1863 staging)
  • mto: This revision was merged to the branch mainline in revision 1871.
  • Revision ID: barry.leslie@primebase.com-20101020204100-oyj6p5cfssjw3p62
Merged with 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 "haildb_version_func.h"
25
 
 
26
 
#if defined(HAVE_HAILDB_H)
27
 
# include <haildb.h>
28
 
#else
29
 
# include <embedded_innodb-1.0/innodb.h>
30
 
#endif /* HAVE_HAILDB_H */
31
 
 
32
 
using namespace std;
33
 
using namespace drizzled;
34
 
 
35
 
class HailDBVersionFunction : public Item_str_func
36
 
{
37
 
public:
38
 
  HailDBVersionFunction() : Item_str_func() {}
39
 
  String *val_str(String*);
40
 
 
41
 
  void fix_length_and_dec()
42
 
  {
43
 
    max_length= 32;
44
 
  }
45
 
 
46
 
  const char *func_name() const
47
 
  {
48
 
    return "haildb_version";
49
 
  }
50
 
 
51
 
  bool check_argument_count(int n)
52
 
  {
53
 
    return (n == 0);
54
 
  }
55
 
};
56
 
 
57
 
 
58
 
String *HailDBVersionFunction::val_str(String *str)
59
 
{
60
 
  assert(fixed == true);
61
 
 
62
 
  if (str->alloc(50))
63
 
  {
64
 
    null_value= true;
65
 
    return 0;
66
 
  }
67
 
 
68
 
  null_value= false;
69
 
 
70
 
  uint64_t version= ib_api_version();
71
 
 
72
 
  int len= snprintf((char *) str->ptr(), 50,
73
 
                    "Release %"PRIx64", Revision %"PRIx64", Age %"PRIx64,
74
 
                    version >> 32,
75
 
                    (version >> 16) & 0xffff,
76
 
                    version & 0xffff);
77
 
 
78
 
  str->length(len);
79
 
 
80
 
  return str;
81
 
}
82
 
 
83
 
 
84
 
plugin::Create_function<HailDBVersionFunction> *haildb_version_func= NULL;
85
 
 
86
 
int haildb_version_func_initialize(module::Context &context)
87
 
{
88
 
  haildb_version_func= new plugin::Create_function<HailDBVersionFunction>("haildb_version");
89
 
  context.add(haildb_version_func);
90
 
  return 0;
91
 
}