00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <drizzled/plugin.h>
00023 #include <drizzled/function/math/int.h>
00024 #include <drizzled/plugin/function.h>
00025
00026 using namespace std;
00027 using namespace drizzled;
00028
00029 class AsciiFunction :public Item_int_func
00030 {
00031 String value;
00032 public:
00033 int64_t val_int();
00034 AsciiFunction() :Item_int_func() {}
00035
00036 const char *func_name() const
00037 {
00038 return "ascii";
00039 }
00040
00041 void fix_length_and_dec()
00042 {
00043 max_length= 3;
00044 }
00045
00046 bool check_argument_count(int n)
00047 {
00048 return (n == 1);
00049 }
00050 };
00051
00052
00053 int64_t AsciiFunction::val_int()
00054 {
00055 assert(fixed == true);
00056 String *res= args[0]->val_str(&value);
00057
00058 if (res == NULL)
00059 {
00060 null_value= true;
00061 return 0;
00062 }
00063
00064 null_value= false;
00065 return (int64_t) ( res->length() != 0 ?
00066 (unsigned char) (*res)[0] :
00067 (unsigned char) 0
00068 );
00069 }
00070
00071 plugin::Create_function<AsciiFunction> *asciiudf= NULL;
00072
00073 static int initialize(module::Context &context)
00074 {
00075 asciiudf= new plugin::Create_function<AsciiFunction>("ascii");
00076 context.add(asciiudf);
00077 return 0;
00078 }
00079
00080 DRIZZLE_DECLARE_PLUGIN
00081 {
00082 DRIZZLE_VERSION_ID,
00083 "ascii",
00084 "1.0",
00085 "Devananda van der Veen",
00086 "Return the ASCII value of a character",
00087 PLUGIN_LICENSE_GPL,
00088 initialize,
00089 NULL,
00090 NULL
00091 }
00092 DRIZZLE_DECLARE_PLUGIN_END;