~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/database_function/database_function.cc

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *  Copyright (C) 2010 Stewart Smith
6
 
 *
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; version 2 of the License.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
 
23
 
#include <drizzled/session.h>
24
 
#include <drizzled/function/str/strfunc.h>
25
 
 
26
 
using namespace drizzled;
27
 
 
28
 
class DatabaseFunction :public Item_str_func
29
 
{
30
 
public:
31
 
  DatabaseFunction() :Item_str_func() {}
32
 
  String *val_str(String *);
33
 
  void fix_length_and_dec()
34
 
  {
35
 
    max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
36
 
    maybe_null=1;
37
 
  }
38
 
  const char *func_name() const { return "database"; }
39
 
  const char *fully_qualified_func_name() const { return "database()"; }
40
 
};
41
 
 
42
 
String *DatabaseFunction::val_str(String *str)
43
 
{
44
 
  assert(fixed == 1);
45
 
  Session *session= current_session;
46
 
  if (session->db.empty())
47
 
  {
48
 
    null_value= 1;
49
 
    return 0;
50
 
  }
51
 
  else
52
 
    str->copy(session->db.c_str(), session->db.length(), system_charset_info);
53
 
  return str;
54
 
}
55
 
 
56
 
plugin::Create_function<DatabaseFunction> *database_function= NULL;
57
 
 
58
 
static int initialize(drizzled::plugin::Context &context)
59
 
{
60
 
  database_function= new plugin::Create_function<DatabaseFunction>("database");
61
 
  context.add(database_function);
62
 
  return 0;
63
 
}
64
 
 
65
 
DRIZZLE_DECLARE_PLUGIN
66
 
{
67
 
  DRIZZLE_VERSION_ID,
68
 
  "database_function",
69
 
  "1.0",
70
 
  "Stewart Smith",
71
 
  "returns the current database",
72
 
  PLUGIN_LICENSE_GPL,
73
 
  initialize, /* Plugin Init */
74
 
  NULL,   /* system variables */
75
 
  NULL    /* config options */
76
 
}
77
 
DRIZZLE_DECLARE_PLUGIN_END;