drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
ascii.cc
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, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <config.h>
21
22#include <drizzled/plugin.h>
23#include <drizzled/function/math/int.h>
24#include <drizzled/plugin/function.h>
25
26using namespace std;
27using namespace drizzled;
28
29class AsciiFunction :public Item_int_func
30{
31 String value;
32public:
33 int64_t val_int();
34 AsciiFunction() :Item_int_func() {}
35
36 const char *func_name() const
37 {
38 return "ascii";
39 }
40
41 void fix_length_and_dec()
42 {
43 max_length= 3;
44 }
45
47 {
48 return (n == 1);
49 }
50};
51
52
54{
55 assert(fixed == true);
56 String *res= args[0]->val_str(&value);
57
58 if (res == NULL)
59 {
60 null_value= true;
61 return 0;
62 }
63
64 null_value= false;
65 return (int64_t) ( res->length() != 0 ?
66 (unsigned char) (*res)[0] :
67 (unsigned char) 0
68 );
69}
70
72
73static int initialize(module::Context &context)
74{
75 asciiudf= new plugin::Create_function<AsciiFunction>("ascii");
76 context.add(asciiudf);
77 return 0;
78}
79
80DRIZZLE_DECLARE_PLUGIN
81{
82 DRIZZLE_VERSION_ID,
83 "ascii",
84 "1.0",
85 "Devananda van der Veen",
86 N_("ASCII function"),
87 PLUGIN_LICENSE_GPL,
88 initialize,
89 NULL,
90 NULL
91}
92DRIZZLE_DECLARE_PLUGIN_END;
int64_t val_int()
Definition ascii.cc:53
bool check_argument_count(int n)
Definition ascii.cc:46
bool fixed
Definition item.h:122
bool null_value
Definition item.h:124
TODO: Rename this file - func.h is stupid.
STL namespace.