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 "ord.h"
00023
00024 #include <drizzled/charset_info.h>
00025 #include <drizzled/type/decimal.h>
00026
00027 namespace drizzled
00028 {
00029
00030 int64_t Item_func_ord::val_int()
00031 {
00032 assert(fixed == 1);
00033 String *res=args[0]->val_str(&value);
00034 if (!res)
00035 {
00036 null_value=1;
00037 return 0;
00038 }
00039 null_value=0;
00040 if (!res->length()) return 0;
00041 if (use_mb(res->charset()))
00042 {
00043 register const char *str=res->ptr();
00044 register uint32_t n=0, l=my_ismbchar(res->charset(),str,str+res->length());
00045 if (!l)
00046 return (int64_t)((unsigned char) *str);
00047 while (l--)
00048 n=(n<<8)|(uint32_t)((unsigned char) *str++);
00049 return (int64_t) n;
00050 }
00051 return (int64_t) ((unsigned char) (*res)[0]);
00052 }
00053
00054 }