00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <drizzled/sql_string.h>
00024 #include <drizzled/type/boolean.h>
00025 #include <drizzled/global_charset_info.h>
00026 #include <drizzled/charset_info.h>
00027
00028 namespace drizzled
00029 {
00030
00031 namespace type
00032 {
00033
00034 bool convert(String &destination, const bool source, bool ansi_display)
00035 {
00036 uint32_t mlength= (5) * system_charset_info->mbmaxlen;
00037
00038 destination.alloc(mlength);
00039 char *buffer=(char*) destination.c_ptr();
00040
00041 if (source)
00042 {
00043 if (ansi_display)
00044 {
00045 memcpy(buffer, "YES", 3);
00046 destination.length(3);
00047 }
00048 else
00049 {
00050 memcpy(buffer, "TRUE", 4);
00051 destination.length(4);
00052 }
00053 }
00054 else
00055 {
00056 if (ansi_display)
00057 {
00058 memcpy(buffer, "NO", 2);
00059 destination.length(2);
00060 }
00061 else
00062 {
00063 memcpy(buffer, "FALSE", 5);
00064 destination.length(5);
00065 }
00066 }
00067
00068 return true;
00069 }
00070
00071 bool convert(bool &destination, const char *source, const size_t source_length)
00072 {
00073 switch (source_length)
00074 {
00075 case 1:
00076 {
00077 switch (source[0])
00078 {
00079 case 'y': case 'Y':
00080 case 't': case 'T':
00081 destination= true;
00082 return true;
00083
00084 case 'n': case 'N':
00085 case 'f': case 'F':
00086 destination= false;
00087 return true;
00088 }
00089 }
00090 break;
00091
00092 case 5:
00093 if (not (my_strcasecmp(system_charset_info, source, "FALSE")))
00094 {
00095 destination= false;
00096 return true;
00097 }
00098 break;
00099
00100 case 4:
00101 if (not (my_strcasecmp(system_charset_info, source, "TRUE")))
00102 {
00103 destination= true;
00104 return true;
00105 }
00106 break;
00107
00108 case 3:
00109 if (not (my_strcasecmp(system_charset_info, source, "YES")))
00110 {
00111 destination= true;
00112 return true;
00113 }
00114 break;
00115
00116 case 2:
00117 if (not (my_strcasecmp(system_charset_info, source, "NO")))
00118 {
00119 destination= false;
00120 return true;
00121 }
00122 break;
00123 }
00124
00125
00126 destination= false;
00127 return false;
00128 }
00129
00130 bool convert(bool &destination, String &source)
00131 {
00132 return convert(destination, source.c_ptr(), source.length());
00133 }
00134
00135 }
00136 }