1
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
#include <uuid/uuid.h>
28
#include "drizzled/field/uuid.h"
30
#include "drizzled/error.h"
31
#include "drizzled/internal/my_sys.h"
32
#include "drizzled/session.h"
33
#include "drizzled/table.h"
40
Uuid::Uuid(unsigned char *ptr_arg,
42
unsigned char *null_ptr_arg,
43
unsigned char null_bit_arg,
44
const char *field_name_arg) :
45
Field(ptr_arg, len_arg,
54
int Uuid::cmp(const unsigned char *a, const unsigned char *b)
56
return memcmp(a, b, sizeof(uuid_t));
59
int Uuid::store(const char *from, uint32_t length, const CHARSET_INFO * const )
61
ASSERT_COLUMN_MARKED_FOR_WRITE;
70
if (length != type::Uuid::DISPLAY_LENGTH)
72
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
78
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
87
int Uuid::store(int64_t , bool )
89
ASSERT_COLUMN_MARKED_FOR_WRITE;
90
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
94
int Uuid::store_decimal(const drizzled::type::Decimal*)
96
ASSERT_COLUMN_MARKED_FOR_WRITE;
97
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
101
void Uuid::sql_type(String &res) const
103
res.set_ascii(STRING_WITH_LEN("uuid"));
106
double Uuid::val_real()
108
ASSERT_COLUMN_MARKED_FOR_READ;
109
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
113
int64_t Uuid::val_int()
115
ASSERT_COLUMN_MARKED_FOR_READ;
116
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
121
void Uuid::generate()
124
uuid_generate_time(uu);
125
memcpy(ptr, uu, sizeof(uuid_t));
129
void Uuid::set(const unsigned char *arg)
131
memcpy(ptr, arg, sizeof(uuid_t));
136
String *Uuid::val_str(String *val_buffer, String *)
138
const CHARSET_INFO * const cs= &my_charset_bin;
139
uint32_t mlength= (type::Uuid::DISPLAY_BUFFER_LENGTH) * cs->mbmaxlen;
142
val_buffer->alloc(mlength);
143
char *buffer=(char*) val_buffer->ptr();
145
ASSERT_COLUMN_MARKED_FOR_READ;
150
val_buffer->length(type::Uuid::DISPLAY_LENGTH);
155
void Uuid::sort_string(unsigned char *to, uint32_t length_arg)
157
assert(length_arg == type::Uuid::LENGTH);
158
memcpy(to, ptr, length_arg);
161
bool Uuid::get_date(type::Time <ime, uint32_t )
169
struct timeval ret_tv;
171
memset(&ret_tv, 0, sizeof(struct timeval));
184
bool Uuid::get_time(type::Time <ime)
186
return get_date(ltime, 0);
189
} /* namespace field */
190
} /* namespace drizzled */