1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
26
26
#define DRIZZLED_FIELD_H
28
28
#include "drizzled/sql_error.h"
29
#include "drizzled/type/decimal.h"
29
#include "drizzled/decimal.h"
30
30
#include "drizzled/key_map.h"
31
31
#include "drizzled/sql_list.h"
32
32
#include "drizzled/structs.h"
142
140
utype unireg_check;
143
141
uint32_t field_length; /**< Length of this field in bytes */
146
bool isUnsigned() const
148
return flags & UNSIGNED_FLAG;
152
143
uint16_t field_index; /**< Index of this Field in Table::fields array */
156
uint16_t position() const
161
void setPosition(uint32_t arg)
166
144
unsigned char null_bit; /**< Bit used to test null bit */
168
146
If true, this field was created in create_tmp_field_from_item from a NULL
188
166
utype unireg_check_arg,
189
167
const char *field_name_arg);
190
168
virtual ~Field() {}
192
bool hasDefault() const
194
return not (flags & NO_DEFAULT_VALUE_FLAG);
197
169
/* Store functions returns 1 on overflow and -1 on fatal error */
198
170
virtual int store(const char *to,
200
172
const CHARSET_INFO * const cs)=0;
201
173
virtual int store(double nr)=0;
202
174
virtual int store(int64_t nr, bool unsigned_val)=0;
203
virtual int store_decimal(const type::Decimal *d)=0;
204
int store_and_check(enum_check_fields check_level,
207
const CHARSET_INFO * const cs);
175
virtual int store_decimal(const my_decimal *d)=0;
176
int store(const char *to,
178
const CHARSET_INFO * const cs,
179
enum_check_fields check_level);
209
181
This is called when storing a date in a string.
212
184
Needs to be changed if/when we want to support different time formats.
214
virtual int store_time(type::Time *ltime, enum enum_drizzle_timestamp_type t_type);
215
virtual double val_real()=0;
216
virtual int64_t val_int()=0;
217
virtual type::Decimal *val_decimal(type::Decimal *);
218
String *val_str_internal(String *str)
186
virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
187
virtual double val_real(void)=0;
188
virtual int64_t val_int(void)=0;
189
virtual my_decimal *val_decimal(my_decimal *);
190
inline String *val_str(String *str)
220
192
return val_str(str, str);
240
212
virtual Item_result result_type () const=0;
241
213
virtual Item_result cmp_type () const { return result_type(); }
242
214
virtual Item_result cast_to_int_type () const { return result_type(); }
245
216
Check whether a field type can be partially indexed by a key.
288
259
virtual bool eq_def(Field *field);
290
virtual bool is_timestamp() const
296
262
* Returns size (in bytes) used to store field data in memory
297
263
* (i.e. it returns the maximum size of the field in a row of the table,
335
301
virtual uint32_t key_length() const;
336
302
virtual enum_field_types type() const =0;
337
303
virtual enum_field_types real_type() const;
338
virtual int cmp_max(const unsigned char *a, const unsigned char *b, uint32_t max_len);
304
inline int cmp(const unsigned char *str) { return cmp(ptr,str); }
305
virtual int cmp_max(const unsigned char *a, const unsigned char *b,
339
307
virtual int cmp(const unsigned char *,const unsigned char *)=0;
340
int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
341
308
virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
342
309
uint32_t max_length=UINT32_MAX);
343
310
virtual int cmp_offset(uint32_t row_offset);
389
356
uint32_t new_null_bit);
390
357
/** This is used to generate a field in Table from TableShare */
391
358
Field *clone(memory::Root *mem_root, Table *new_table);
392
void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
359
inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
395
362
null_ptr= null_ptr_arg;
396
363
null_bit= null_bit_arg;
398
void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
365
inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
399
366
virtual void move_field_offset(ptrdiff_t ptr_diff)
401
368
ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
471
438
return return_value;
474
String *val_str_internal(String *str, const unsigned char *new_ptr)
440
inline String *val_str(String *str, const unsigned char *new_ptr)
476
442
unsigned char *old_ptr= ptr;
477
443
ptr= const_cast<unsigned char*>(new_ptr);
478
val_str_internal(str);
584
550
return max_length;
587
uint32_t offset(const unsigned char *record)
553
inline uint32_t offset(const unsigned char *record)
589
555
return (uint32_t) (ptr - record);
591
557
void copy_from_tmp(int offset);
592
558
uint32_t fill_cache_field(CacheField *copy);
593
virtual bool get_date(type::Time *ltime,uint32_t fuzzydate);
594
virtual bool get_time(type::Time *ltime);
559
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
560
virtual bool get_time(DRIZZLE_TIME *ltime);
595
561
virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
596
562
virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
597
563
virtual bool has_charset(void) const { return false; }
681
647
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
682
const drizzled::error_t code,
684
650
enum enum_drizzle_timestamp_type ts_type);
685
bool check_overflow(int op_result)
651
inline bool check_overflow(int op_result)
687
653
return (op_result == E_DEC_OVERFLOW);
717
683
value converted from val
719
int64_t convert_decimal2int64_t(const type::Decimal *val,
685
int64_t convert_decimal2int64_t(const my_decimal *val,
720
686
bool unsigned_flag,
722
688
/* The max. number of characters */
723
uint32_t char_length() const
689
inline uint32_t char_length() const
725
691
return field_length / charset()->mbmaxlen;
728
enum column_format_type column_format() const
694
inline enum column_format_type column_format() const
730
696
return (enum column_format_type)
731
697
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
752
718
bool isWriteSet();
753
719
void setReadSet(bool arg= true);
754
720
void setWriteSet(bool arg= true);
758
void pack_num(uint64_t arg, unsigned char *destination= NULL);
759
void pack_num(uint32_t arg, unsigned char *destination= NULL);
760
uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
761
uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
764
std::ostream& operator<<(std::ostream& output, const Field &field);
766
723
} /* namespace drizzled */
768
725
/** @TODO Why is this in the middle of the file???*/
822
778
String tmp; // For items
841
782
void set(Field *to,Field *from,bool save); // Field to field
842
783
void set(unsigned char *to,Field *from); // Field to string
843
784
void (*do_copy)(CopyField *);