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_st * 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 double Uuid::val_real() const
00102 {
00103 ASSERT_COLUMN_MARKED_FOR_READ;
00104 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00105 return 0;
00106 }
00107
00108 int64_t Uuid::val_int() const
00109 {
00110 ASSERT_COLUMN_MARKED_FOR_READ;
00111 my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
00112 return 0;
00113 }
00114
00115 #ifdef NOT_YET
00116 void Uuid::generate()
00117 {
00118 uuid_t uu;
00119 uuid_generate_time(uu);
00120 memcpy(ptr, uu, sizeof(uuid_t));
00121 is_set= true;
00122 }
00123
00124 void Uuid::set(const unsigned char *arg)
00125 {
00126 memcpy(ptr, arg, sizeof(uuid_t));
00127 is_set= true;
00128 }
00129 #endif
00130
00131 String *Uuid::val_str(String *val_buffer, String *) const
00132 {
00133 const charset_info_st * const cs= &my_charset_bin;
00134 uint32_t mlength= (type::Uuid::DISPLAY_BUFFER_LENGTH) * cs->mbmaxlen;
00135 type::Uuid uu;
00136
00137 val_buffer->alloc(mlength);
00138 char *buffer=(char*) val_buffer->ptr();
00139
00140 ASSERT_COLUMN_MARKED_FOR_READ;
00141
00142 uu.unpack(ptr);
00143 uu.unparse(buffer);
00144
00145 val_buffer->length(type::Uuid::DISPLAY_LENGTH);
00146
00147 return val_buffer;
00148 }
00149
00150 void Uuid::sort_string(unsigned char *to, uint32_t length_arg)
00151 {
00152 assert(length_arg == type::Uuid::LENGTH);
00153 memcpy(to, ptr, length_arg);
00154 }
00155
00156 bool Uuid::get_date(type::Time <ime, uint32_t ) const
00157 {
00158 type::Uuid uu;
00159
00160 uu.unpack(ptr);
00161
00162 if (uu.isTimeType())
00163 {
00164 struct timeval ret_tv;
00165
00166 memset(&ret_tv, 0, sizeof(struct timeval));
00167
00168 uu.time(ret_tv);
00169
00170 ltime.store(ret_tv);
00171
00172 return false;
00173 }
00174 ltime.reset();
00175
00176 return true;
00177 }
00178
00179 bool Uuid::get_time(type::Time <ime) const
00180 {
00181 return get_date(ltime, 0);
00182 }
00183
00184 }
00185 }