00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include <algorithm>
00025
00026 #include <uuid/uuid.h>
00027
00028 #include <drizzled/field/uuid.h>
00029
00030 #include <drizzled/error.h>
00031 #include <drizzled/internal/my_sys.h>
00032 #include <drizzled/session.h>
00033 #include <drizzled/table.h>
00034
00035 namespace drizzled
00036 {
00037 namespace field
00038 {
00039
00040 Uuid::Uuid(unsigned char *ptr_arg,
00041 uint32_t len_arg,
00042 unsigned char *null_ptr_arg,
00043 unsigned char null_bit_arg,
00044 const char *field_name_arg) :
00045 Field(ptr_arg, len_arg,
00046 null_ptr_arg,
00047 null_bit_arg,
00048 Field::NONE,
00049 field_name_arg),
00050 is_set(false)
00051 {
00052 }
00053
00054 int Uuid::cmp(const unsigned char *a, const unsigned char *b)
00055 {
00056 return memcmp(a, b, sizeof(uuid_t));
00057 }
00058
00059 int Uuid::store(const char *from, uint32_t length, const CHARSET_INFO * const )
00060 {
00061 ASSERT_COLUMN_MARKED_FOR_WRITE;
00062 type::Uuid uu;
00063
00064 if (is_set)
00065 {
00066 is_set= false;
00067 return 0;
00068 }
00069
00070 if (length != type::Uuid::DISPLAY_LENGTH)
00071 {
00072 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00073 return 1;
00074 }
00075
00076 if (uu.parse(from))
00077 {
00078 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00079 return 1;
00080 }
00081
00082 uu.pack(ptr);
00083
00084 return 0;
00085 }
00086
00087 int Uuid::store(int64_t , bool )
00088 {
00089 ASSERT_COLUMN_MARKED_FOR_WRITE;
00090 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00091 return 1;
00092 }
00093
00094 int Uuid::store_decimal(const drizzled::type::Decimal*)
00095 {
00096 ASSERT_COLUMN_MARKED_FOR_WRITE;
00097 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00098 return 1;
00099 }
00100
00101 void Uuid::sql_type(String &res) const
00102 {
00103 res.set_ascii(STRING_WITH_LEN("uuid"));
00104 }
00105
00106 double Uuid::val_real() const
00107 {
00108 ASSERT_COLUMN_MARKED_FOR_READ;
00109 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00110 return 0;
00111 }
00112
00113 int64_t Uuid::val_int() const
00114 {
00115 ASSERT_COLUMN_MARKED_FOR_READ;
00116 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00117 return 0;
00118 }
00119
00120 #ifdef NOT_YET
00121 void Uuid::generate()
00122 {
00123 uuid_t uu;
00124 uuid_generate_time(uu);
00125 memcpy(ptr, uu, sizeof(uuid_t));
00126 is_set= true;
00127 }
00128
00129 void Uuid::set(const unsigned char *arg)
00130 {
00131 memcpy(ptr, arg, sizeof(uuid_t));
00132 is_set= true;
00133 }
00134 #endif
00135
00136 String *Uuid::val_str(String *val_buffer, String *) const
00137 {
00138 const CHARSET_INFO * const cs= &my_charset_bin;
00139 uint32_t mlength= (type::Uuid::DISPLAY_BUFFER_LENGTH) * cs->mbmaxlen;
00140 type::Uuid uu;
00141
00142 val_buffer->alloc(mlength);
00143 char *buffer=(char*) val_buffer->ptr();
00144
00145 ASSERT_COLUMN_MARKED_FOR_READ;
00146
00147 uu.unpack(ptr);
00148 uu.unparse(buffer);
00149
00150 val_buffer->length(type::Uuid::DISPLAY_LENGTH);
00151
00152 return val_buffer;
00153 }
00154
00155 void Uuid::sort_string(unsigned char *to, uint32_t length_arg)
00156 {
00157 assert(length_arg == type::Uuid::LENGTH);
00158 memcpy(to, ptr, length_arg);
00159 }
00160
00161 bool Uuid::get_date(type::Time <ime, uint32_t ) const
00162 {
00163 type::Uuid uu;
00164
00165 uu.unpack(ptr);
00166
00167 if (uu.isTimeType())
00168 {
00169 struct timeval ret_tv;
00170
00171 memset(&ret_tv, 0, sizeof(struct timeval));
00172
00173 uu.time(ret_tv);
00174
00175 ltime.store(ret_tv);
00176
00177 return false;
00178 }
00179 ltime.reset();
00180
00181 return true;
00182 }
00183
00184 bool Uuid::get_time(type::Time <ime) const
00185 {
00186 return get_date(ltime, 0);
00187 }
00188
00189 }
00190 }