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"
34
#include "drizzled/temporal.h"
41
Uuid::Uuid(unsigned char *ptr_arg,
43
unsigned char *null_ptr_arg,
44
unsigned char null_bit_arg,
45
const char *field_name_arg) :
46
Field(ptr_arg, len_arg,
55
int Uuid::cmp(const unsigned char *a, const unsigned char *b)
57
return memcmp(a, b, sizeof(uuid_t));
60
int Uuid::store(const char *from, uint32_t length, const CHARSET_INFO * const )
62
ASSERT_COLUMN_MARKED_FOR_WRITE;
71
if (length != uuid_st::DISPLAY_LENGTH)
73
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
79
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
88
int Uuid::store(int64_t , bool )
90
ASSERT_COLUMN_MARKED_FOR_WRITE;
91
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
95
int Uuid::store_decimal(const drizzled::my_decimal*)
97
ASSERT_COLUMN_MARKED_FOR_WRITE;
98
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
102
void Uuid::sql_type(String &res) const
104
res.set_ascii(STRING_WITH_LEN("uuid"));
107
double Uuid::val_real()
109
ASSERT_COLUMN_MARKED_FOR_READ;
110
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
114
int64_t Uuid::val_int()
116
ASSERT_COLUMN_MARKED_FOR_READ;
117
my_error(ER_INVALID_UUID_VALUE, MYF(ME_FATALERROR));
122
void Uuid::generate()
125
uuid_generate_time(uu);
126
memcpy(ptr, uu, sizeof(uuid_t));
130
void Uuid::set(const unsigned char *arg)
132
memcpy(ptr, arg, sizeof(uuid_t));
137
String *Uuid::val_str(String *val_buffer, String *)
139
const CHARSET_INFO * const cs= &my_charset_bin;
140
uint32_t mlength= (uuid_st::DISPLAY_BUFFER_LENGTH) * cs->mbmaxlen;
143
val_buffer->alloc(mlength);
144
char *buffer=(char*) val_buffer->ptr();
146
ASSERT_COLUMN_MARKED_FOR_READ;
151
val_buffer->length(uuid_st::DISPLAY_LENGTH);
156
void Uuid::sort_string(unsigned char *to, uint32_t length_arg)
158
assert(length_arg == uuid_st::LENGTH);
159
memcpy(to, ptr, length_arg);
162
bool Uuid::get_date(DRIZZLE_TIME *ltime, uint32_t )
171
struct timeval ret_tv;
173
ret_tv.tv_sec= ret_tv.tv_usec= 0;
177
temporal.from_time_t(ret_tv.tv_sec);
179
ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
180
ltime->year= temporal.years();
181
ltime->month= temporal.months();
182
ltime->day= temporal.days();
183
ltime->hour= temporal.hours();
184
ltime->minute= temporal.minutes();
185
ltime->second= temporal.seconds();
186
ltime->second_part= temporal.nseconds();
190
memset(ltime, 0, sizeof(DRIZZLE_TIME));
195
bool Uuid::get_time(DRIZZLE_TIME *ltime)
197
return get_date(ltime, 0);
200
} /* namespace field */
201
} /* namespace drizzled */