1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
5
5
* Copyright (C) 2010 Stewart Smith
7
7
* This program is free software; you can redistribute it and/or modify
21
21
#include "config.h"
23
23
#include <drizzled/session.h>
24
#include "plugin/utility_functions/functions.h"
29
namespace utility_functions
32
String *Schema::val_str(String *str)
24
#include <drizzled/function/str/strfunc.h>
26
using namespace drizzled;
28
class DatabaseFunction :public Item_str_func
31
DatabaseFunction() :Item_str_func() {}
32
String *val_str(String *);
33
void fix_length_and_dec()
35
max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
38
const char *func_name() const { return "database"; }
39
const char *fully_qualified_func_name() const { return "database()"; }
42
String *DatabaseFunction::val_str(String *str)
34
44
assert(fixed == 1);
35
util::string::const_shared_ptr schema= getSession().schema();
36
if (not schema or schema->empty())
45
Session *session= current_session;
46
if (session->db.empty())
42
str->copy(*schema, system_charset_info);
52
str->copy(session->db.c_str(), session->db.length(), system_charset_info);
47
} /* namespace utility_functions */
48
} /* namespace drizzled */
56
plugin::Create_function<DatabaseFunction> *database_function= NULL;
58
static int initialize(drizzled::plugin::Registry ®istry)
60
database_function= new plugin::Create_function<DatabaseFunction>("database");
61
registry.add(database_function);
65
static int finalize(drizzled::plugin::Registry ®istry)
67
registry.remove(database_function);
68
delete database_function;
72
DRIZZLE_DECLARE_PLUGIN
78
"returns the current database",
80
initialize, /* Plugin Init */
81
finalize, /* Plugin Deinit */
82
NULL, /* system variables */
83
NULL /* config options */
85
DRIZZLE_DECLARE_PLUGIN_END;