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