mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
cfab46f546
Fixed memory leak on shutdown (Affects the embedded version & MyODBC) client/client_priv.h: Update copyright client/completion_hash.cc: Update copyright client/completion_hash.h: Update copyright client/connect_test.c: Update copyright client/errmsg.c: Update copyright client/get_password.c: Update copyright client/insert_test.c: Update copyright client/list_test.c: Update copyright client/my_readline.h: Update copyright client/mysql.cc: Update copyright client/mysqladmin.c: Update copyright client/mysqlbinlog.cc: Update copyright client/mysqlcheck.c: Update copyright client/mysqldump.c: Update copyright client/mysqlimport.c: Update copyright client/mysqlmanager-pwgen.c: Update copyright client/mysqlmanagerc.c: Update copyright client/mysqlshow.c: Update copyright client/mysqltest.c: Update copyright client/password.c: Update copyright client/readline.cc: Update copyright client/select_test.c: Update copyright client/showdb_test.c: Update copyright client/sql_string.cc: Update copyright client/sql_string.h: Update copyright client/ssl_test.c: Update copyright client/thimble.cc: Update copyright client/thread_test.c: Update copyright div/deadlock_test.c: Update copyright extra/comp_err.c: Update copyright extra/my_print_defaults.c: Update copyright extra/perror.c: Update copyright extra/replace.c: Update copyright extra/resolve_stack_dump.c: Update copyright extra/resolveip.c: Update copyright fs/database.c: Update copyright fs/libmysqlfs.c: Update copyright fs/mysqlcorbafs.c: Update copyright fs/mysqlcorbafs.h: Update copyright fs/mysqlcorbafs_test.c: Update copyright heap/_check.c: Update copyright heap/_rectest.c: Update copyright heap/heapdef.h: Update copyright heap/hp_block.c: Update copyright heap/hp_clear.c: Update copyright heap/hp_close.c: Update copyright heap/hp_create.c: Update copyright heap/hp_delete.c: Update copyright heap/hp_extra.c: Update copyright heap/hp_hash.c: Update copyright heap/hp_info.c: Update copyright heap/hp_open.c: Update copyright heap/hp_panic.c: Update copyright heap/hp_rename.c: Update copyright heap/hp_rfirst.c: Update copyright heap/hp_rkey.c: Update copyright heap/hp_rlast.c: Update copyright heap/hp_rnext.c: Update copyright heap/hp_rprev.c: Update copyright heap/hp_rrnd.c: Update copyright heap/hp_rsame.c: Update copyright heap/hp_scan.c: Update copyright heap/hp_static.c: Update copyright heap/hp_test1.c: Update copyright heap/hp_test2.c: Update copyright heap/hp_update.c: Update copyright heap/hp_write.c: Update copyright include/config-win.h: Update copyright include/dbug.h: Update copyright include/errmsg.h: Update copyright include/ft_global.h: Update copyright include/getopt.h: Update copyright include/hash.h: Update copyright include/heap.h: Update copyright include/m_ctype.h: Update copyright include/m_string.h: Update copyright include/md5.h: Update copyright include/merge.h: Update copyright include/my_alarm.h: Update copyright include/my_base.h: Update copyright include/my_bitmap.h: Update copyright include/my_dir.h: Update copyright include/my_global.h: Update copyright include/my_list.h: Update copyright include/my_net.h: Update copyright include/my_no_pthread.h: Update copyright include/my_nosys.h: Update copyright include/my_pthread.h: Update copyright include/my_sys.h: Update copyright include/my_tree.h: Update copyright include/myisam.h: Update copyright include/myisammrg.h: Update copyright include/myisampack.h: Update copyright include/mysql.h: Update copyright include/mysql_com.h: Update copyright include/mysql_embed.h: Update copyright include/mysqld_error.h: Update copyright include/mysys_err.h: Update copyright include/nisam.h: Update copyright include/queues.h: Update copyright include/raid.h: Update copyright include/sslopt-case.h: Update copyright include/sslopt-longopts.h: Update copyright include/sslopt-usage.h: Update copyright include/sslopt-vars.h: Update copyright include/t_ctype.h: Update copyright include/thr_alarm.h: Update copyright include/thr_lock.h: Update copyright include/violite.h: Update copyright isam/_cache.c: Update copyright isam/_dbug.c: Update copyright isam/_key.c: Update copyright isam/_locking.c: Update copyright isam/_packrec.c: Update copyright isam/_page.c: Update copyright isam/_search.c: Update copyright isam/_statrec.c: Update copyright isam/changed.c: Update copyright isam/close.c: Update copyright isam/create.c: Update copyright isam/delete.c: Update copyright isam/extra.c: Update copyright isam/info.c: Update copyright isam/isamchk.c: Update copyright isam/isamdef.h: Update copyright isam/log.c: Update copyright isam/open.c: Update copyright isam/panic.c: Update copyright isam/range.c: Update copyright isam/rfirst.c: Update copyright isam/rkey.c: Update copyright isam/rlast.c: Update copyright isam/rnext.c: Update copyright isam/rprev.c: Update copyright isam/rrnd.c: Update copyright isam/rsame.c: Update copyright isam/rsamepos.c: Update copyright isam/sort.c: Update copyright isam/static.c: Update copyright isam/test1.c: Update copyright isam/test2.c: Update copyright isam/test3.c: Update copyright isam/update.c: Update copyright isam/write.c: Update copyright libmysql/conf_to_src.c: Update copyright libmysql/dll.c: Update copyright libmysql/errmsg.c: Update copyright libmysql/get_password.c: Update copyright libmysql/libmysql.c: Update copyright libmysql/manager.c: Update copyright libmysql/net.c: Update copyright libmysql/password.c: Update copyright libmysqld/lib_sql.cc: Update copyright libmysqld/lib_vio.c: Update copyright libmysqld/libmysqld.c: Update copyright merge/mrg_close.c: Update copyright merge/mrg_create.c: Update copyright merge/mrg_def.h: Update copyright merge/mrg_delete.c: Update copyright merge/mrg_extra.c: Update copyright merge/mrg_info.c: Update copyright merge/mrg_locking.c: Update copyright merge/mrg_open.c: Update copyright merge/mrg_panic.c: Update copyright merge/mrg_rrnd.c: Update copyright merge/mrg_rsame.c: Update copyright merge/mrg_static.c: Update copyright merge/mrg_update.c: Update copyright myisam/ft_boolean_search.c: Update copyright myisam/ft_dump.c: Update copyright myisam/ft_eval.h: Update copyright myisam/ft_static.c: Update copyright myisam/ft_stem.c: Update copyright myisam/ft_stopwords.c: Update copyright myisam/ft_test1.h: Update copyright myisam/mi_cache.c: Update copyright myisam/mi_changed.c: Update copyright myisam/mi_check.c: Update copyright myisam/mi_checksum.c: Update copyright myisam/mi_close.c: Update copyright myisam/mi_create.c: Update copyright myisam/mi_dbug.c: Update copyright myisam/mi_delete.c: Update copyright myisam/mi_delete_all.c: Update copyright myisam/mi_delete_table.c: Update copyright myisam/mi_dynrec.c: Update copyright myisam/mi_extra.c: Update copyright myisam/mi_info.c: Update copyright myisam/mi_key.c: Update copyright myisam/mi_locking.c: Update copyright myisam/mi_log.c: Update copyright myisam/mi_open.c: Update copyright myisam/mi_packrec.c: Update copyright myisam/mi_page.c: Update copyright myisam/mi_panic.c: Update copyright myisam/mi_range.c: Update copyright myisam/mi_rename.c: Update copyright myisam/mi_rfirst.c: Update copyright myisam/mi_rlast.c: Update copyright myisam/mi_rnext_same.c: Update copyright myisam/mi_rrnd.c: Update copyright myisam/mi_rsame.c: Update copyright myisam/mi_rsamepos.c: Update copyright myisam/mi_scan.c: Update copyright myisam/mi_search.c: Update copyright myisam/mi_static.c: Update copyright myisam/mi_statrec.c: Update copyright myisam/mi_test1.c: Update copyright myisam/mi_test2.c: Update copyright myisam/mi_test3.c: Update copyright myisam/mi_unique.c: Update copyright myisam/mi_update.c: Update copyright myisam/mi_write.c: Update copyright myisam/myisamchk.c: Update copyright myisam/myisampack.c: Update copyright myisammrg/myrg_close.c: Update copyright myisammrg/myrg_create.c: Update copyright myisammrg/myrg_def.h: Update copyright myisammrg/myrg_delete.c: Update copyright myisammrg/myrg_locking.c: Update copyright myisammrg/myrg_open.c: Update copyright myisammrg/myrg_panic.c: Update copyright myisammrg/myrg_rsame.c: Update copyright myisammrg/myrg_static.c: Update copyright myisammrg/myrg_update.c: Update copyright myisammrg/myrg_write.c: Update copyright mysql-test/r/gcc296.result: Update of benchmark results mysql-test/r/innodb.result: Update of benchmark results mysql-test/r/join_outer.result: Update of benchmark results mysql-test/r/myisam.result: Update of benchmark results mysys/array.c: Update copyright mysys/charset.c: Fix for restart of character sets mysys/checksum.c: Update copyright mysys/default.c: Update copyright mysys/errors.c: Update copyright mysys/getopt.c: Cleanup mysys/getvar.c: Update copyright mysys/hash.c: Update copyright mysys/list.c: Update copyright mysys/make-conf.c: Update copyright mysys/md5.c: Update copyright mysys/mf_brkhant.c: Update copyright mysys/mf_cache.c: Update copyright mysys/mf_casecnv.c: Update copyright mysys/mf_dirname.c: Update copyright mysys/mf_fn_ext.c: Update copyright mysys/mf_format.c: Update copyright mysys/mf_getdate.c: Update copyright mysys/mf_iocache.c: Update copyright mysys/mf_iocache2.c: Update copyright mysys/mf_keycache.c: Update copyright mysys/mf_loadpath.c: Update copyright mysys/mf_pack.c: Update copyright mysys/mf_path.c: Update copyright mysys/mf_qsort.c: Update copyright mysys/mf_qsort2.c: Update copyright mysys/mf_radix.c: Update copyright mysys/mf_same.c: Update copyright mysys/mf_sleep.c: Update copyright mysys/mf_sort.c: Update copyright mysys/mf_soundex.c: Update copyright mysys/mf_stripp.c: Update copyright mysys/mf_tempfile.c: Update copyright mysys/mf_unixpath.c: Update copyright mysys/mf_util.c: Update copyright mysys/mf_wcomp.c: Update copyright mysys/mf_wfile.c: Update copyright mysys/mulalloc.c: Update copyright mysys/my_alarm.c: Update copyright mysys/my_alloc.c: Update copyright mysys/my_append.c: Update copyright mysys/my_bit.c: Update copyright mysys/my_bitmap.c: Update copyright mysys/my_chsize.c: Update copyright mysys/my_clock.c: Update copyright mysys/my_compress.c: Update copyright mysys/my_copy.c: Update copyright mysys/my_create.c: Update copyright mysys/my_delete.c: Update copyright mysys/my_div.c: Update copyright mysys/my_dup.c: Update copyright mysys/my_error.c: Update copyright mysys/my_fopen.c: Update copyright mysys/my_fstream.c: Update copyright mysys/my_getwd.c: Update copyright mysys/my_init.c: Free 'once_alloc' memory at shutdown. mysys/my_lib.c: Update copyright mysys/my_lock.c: Update copyright mysys/my_lockmem.c: Update copyright mysys/my_lread.c: Update copyright mysys/my_lwrite.c: Update copyright mysys/my_malloc.c: Update copyright mysys/my_messnc.c: Update copyright mysys/my_mkdir.c: Update copyright mysys/my_net.c: Update copyright mysys/my_once.c: Update copyright mysys/my_open.c: Update copyright mysys/my_pread.c: Update copyright mysys/my_pthread.c: Update copyright mysys/my_quick.c: Update copyright mysys/my_read.c: Update copyright mysys/my_realloc.c: Update copyright mysys/my_redel.c: Update copyright mysys/my_rename.c: Update copyright mysys/my_seek.c: Update copyright mysys/my_static.c: Update copyright mysys/my_static.h: Update copyright mysys/my_symlink.c: Update copyright mysys/my_symlink2.c: Update copyright mysys/my_tempnam.c: Update copyright mysys/my_thr_init.c: Update copyright mysys/my_vsnprintf.c: Update copyright mysys/my_wincond.c: Update copyright mysys/my_winthread.c: Update copyright mysys/my_write.c: Update copyright mysys/mysys_priv.h: Update copyright mysys/ptr_cmp.c: Update copyright mysys/queues.c: Update copyright mysys/raid.cc: Update copyright mysys/safemalloc.c: Update copyright mysys/string.c: Update copyright mysys/test_charset.c: Update copyright mysys/test_dir.c: Update copyright mysys/test_fn.c: Update copyright mysys/testhash.c: Update copyright mysys/thr_alarm.c: Update copyright mysys/thr_lock.c: Update copyright mysys/thr_mutex.c: Update copyright mysys/thr_rwlock.c: Update copyright mysys/tree.c: Update copyright mysys/typelib.c: Update copyright pstack/debug.c: Update copyright pstack/debug.h: Update copyright pstack/demangle.h: Update copyright pstack/ieee.c: Update copyright pstack/ieee.h: Update copyright pstack/pstack.c: Update copyright readline/bind.c: Cleanup empty lines readline/complete.c: Cleanup empty lines readline/display.c: Cleanup empty lines readline/funmap.c: Cleanup empty lines readline/histexpand.c: Cleanup empty lines readline/histfile.c: Cleanup empty lines readline/history.c: Cleanup empty lines readline/history.h: Cleanup empty lines readline/input.c: Cleanup empty lines readline/kill.c: Cleanup empty lines readline/readline.c: Cleanup empty lines readline/readline.h: Cleanup empty lines readline/vi_mode.c: Cleanup empty lines sql/cache_manager.cc: Update copyright sql/cache_manager.h: Update copyright sql/convert.cc: Update copyright sql/custom_conf.h: Update copyright sql/derror.cc: Update copyright sql/field.cc: Update copyright sql/field.h: Update copyright sql/field_conv.cc: Update copyright sql/filesort.cc: Update copyright sql/frm_crypt.cc: Update copyright sql/ha_berkeley.cc: Update copyright sql/ha_heap.cc: Update copyright sql/ha_heap.h: Update copyright sql/ha_innobase.cc: Update copyright sql/ha_isam.cc: Update copyright sql/ha_isam.h: Update copyright sql/ha_isammrg.cc: Update copyright sql/ha_isammrg.h: Update copyright sql/ha_myisam.cc: Update copyright sql/handler.cc: Update copyright sql/hash_filo.cc: Update copyright sql/hash_filo.h: Update copyright sql/hostname.cc: Update copyright sql/init.cc: Update copyright sql/item.cc: Update copyright sql/item.h: Update copyright sql/item_buff.cc: Update copyright sql/item_cmpfunc.cc: Update copyright sql/item_cmpfunc.h: Update copyright sql/item_create.cc: Update copyright sql/item_create.h: Update copyright sql/item_func.cc: Update copyright sql/item_strfunc.cc: Update copyright sql/item_sum.cc: Update copyright sql/item_sum.h: Update copyright sql/item_timefunc.cc: Update copyright sql/item_timefunc.h: Update copyright sql/item_uniq.cc: Update copyright sql/item_uniq.h: Update copyright sql/key.cc: Update copyright sql/lex_symbol.h: Update copyright sql/lock.cc: Update copyright sql/log.cc: Update copyright sql/log_event.cc: Update copyright sql/log_event.h: Update copyright sql/matherr.c: Update copyright sql/mf_iocache.cc: Update copyright sql/mini_client.cc: Update copyright sql/mini_client.h: Update copyright sql/my_lock.c: Update copyright sql/mysqld.cc: Update copyright sql/net_pkg.cc: Update copyright sql/net_serv.cc: Update copyright sql/opt_sum.cc: Update copyright sql/password.c: Update copyright sql/procedure.cc: Update copyright sql/procedure.h: Update copyright sql/records.cc: Update copyright sql/repl_failsafe.cc: Update copyright sql/slave.cc: Update copyright sql/slave.h: Update copyright sql/sql_acl.cc: Update copyright sql/sql_acl.h: Update copyright sql/sql_analyse.cc: Update copyright sql/sql_analyse.h: Update copyright sql/sql_base.cc: Update copyright sql/sql_cache.cc: Update copyright sql/sql_class.cc: Update copyright sql/sql_class.h: Update copyright sql/sql_crypt.cc: Update copyright sql/sql_crypt.h: Update copyright sql/sql_db.cc: Update copyright sql/sql_delete.cc: Update copyright sql/sql_handler.cc: Update copyright sql/sql_insert.cc: Update copyright sql/sql_lex.cc: Update copyright sql/sql_lex.h: Update copyright sql/sql_list.cc: Update copyright sql/sql_list.h: Update copyright sql/sql_load.cc: Update copyright sql/sql_map.cc: Update copyright sql/sql_map.h: Update copyright sql/sql_parse.cc: Update copyright sql/sql_rename.cc: Update copyright sql/sql_repl.cc: Update copyright sql/sql_select.h: Update copyright sql/sql_string.cc: Update copyright sql/sql_string.h: Update copyright sql/sql_table.cc: Update copyright sql/sql_test.cc: Update copyright sql/sql_udf.cc: Update copyright sql/sql_udf.h: Update copyright sql/stacktrace.c: Update copyright sql/structs.h: Update copyright sql/table.cc: Update copyright sql/table.h: Update copyright sql/thr_malloc.cc: Update copyright sql/time.cc: Update copyright sql/udf_example.cc: Update copyright sql/uniques.cc: Update copyright sql/unireg.cc: Update copyright sql/unireg.h: Update copyright strings/atof.c: Update copyright strings/bchange.c: Update copyright strings/bcmp.c: Update copyright strings/bcopy-duff.c: Update copyright strings/bfill.c: Update copyright strings/bmove.c: Update copyright strings/bmove512.c: Update copyright strings/bmove_upp.c: Update copyright strings/bzero.c: Update copyright strings/conf_to_src.c: Update copyright strings/ctype-big5.c: Update copyright strings/ctype-czech.c: Update copyright strings/ctype-euc_kr.c: Update copyright strings/ctype-gb2312.c: Update copyright strings/ctype-gbk.c: Update copyright strings/ctype-latin1_de.c: Update copyright strings/ctype-sjis.c: Update copyright strings/ctype-tis620.c: Update copyright strings/ctype-ujis.c: Update copyright strings/ctype.c: Update copyright strings/do_ctype.c: Update copyright strings/int2str.c: Update copyright strings/is_prefix.c: Update copyright strings/llstr.c: Update copyright strings/longlong2str.c: Update copyright strings/memcmp.c: Update copyright strings/memcpy.c: Update copyright strings/memset.c: Update copyright strings/r_strinstr.c: Update copyright strings/str2int.c: Update copyright strings/str_test.c: Update copyright strings/strappend.c: Update copyright strings/strcat.c: Update copyright strings/strcend.c: Update copyright strings/strchr.c: Update copyright strings/strcmp.c: Update copyright strings/strcont.c: Update copyright strings/strend.c: Update copyright strings/strfill.c: Update copyright strings/strings-not-used.h: Update copyright strings/strinstr.c: Update copyright strings/strlen.c: Update copyright strings/strmake.c: Update copyright strings/strmov.c: Update copyright strings/strnlen.c: Update copyright strings/strnmov.c: Update copyright strings/strrchr.c: Update copyright strings/strstr.c: Update copyright strings/strto.c: Update copyright strings/strtol.c: Update copyright strings/strtoll.c: Update copyright strings/strtoul.c: Update copyright strings/strtoull.c: Update copyright strings/strxmov.c: Update copyright strings/strxnmov.c: Update copyright strings/t_ctype.h: Update copyright strings/udiv.c: Update copyright tools/mysqlmanager.c: Update copyright vio/test-ssl.c: Update copyright vio/test-sslclient.c: Update copyright vio/test-sslserver.c: Update copyright vio/vio.c: Update copyright vio/viosocket.c: Update copyright vio/viossl.c: Update copyright vio/viosslfactories.c: Update copyright vio/viotest-ssl.c: Update copyright
1078 lines
38 KiB
C++
1078 lines
38 KiB
C++
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
/*
|
|
Because of the function new_field() all field classes that have static
|
|
variables must declare the size_of() member function.
|
|
*/
|
|
|
|
#ifdef __GNUC__
|
|
#pragma interface /* gcc class implementation */
|
|
#endif
|
|
|
|
#define NOT_FIXED_DEC 31
|
|
|
|
class Send_field;
|
|
struct st_cache_field;
|
|
void field_conv(Field *to,Field *from);
|
|
|
|
class Field {
|
|
Field(const Item &); /* Prevent use of these */
|
|
void operator=(Field &);
|
|
public:
|
|
static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
|
|
static void operator delete(void *ptr_arg, size_t size) {} /*lint -e715 */
|
|
|
|
char *ptr; // Position to field in record
|
|
uchar *null_ptr; // Byte where null_bit is
|
|
struct st_table *table; // Pointer for table
|
|
const char *table_name,*field_name;
|
|
ulong query_id; // For quick test of used fields
|
|
// Field is part of the following keys
|
|
key_map key_start,part_of_key,part_of_sortkey;
|
|
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
|
|
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
|
|
BIT_FIELD, TIMESTAMP_FIELD,CAPITALIZE,BLOB_FIELD};
|
|
utype unireg_check;
|
|
uint32 field_length; // Length of field
|
|
uint16 flags;
|
|
uchar null_bit; // Bit used to test null bit
|
|
|
|
Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,uchar null_bit_arg,
|
|
utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg);
|
|
virtual ~Field() {}
|
|
virtual void store(const char *to,uint length)=0;
|
|
virtual void store(double nr)=0;
|
|
virtual void store(longlong nr)=0;
|
|
virtual void store_time(TIME *ltime,timestamp_type t_type);
|
|
virtual double val_real(void)=0;
|
|
virtual longlong val_int(void)=0;
|
|
virtual String *val_str(String*,String *)=0;
|
|
virtual Item_result result_type () const=0;
|
|
virtual Item_result cmp_type () const { return result_type(); }
|
|
bool eq(Field *field) { return ptr == field->ptr; }
|
|
virtual bool eq_def(Field *field);
|
|
virtual uint32 pack_length() const { return (uint32) field_length; }
|
|
virtual void reset(void) { bzero(ptr,pack_length()); }
|
|
virtual void reset_fields() {}
|
|
virtual bool binary() const { return 1; }
|
|
virtual bool zero_pack() const { return 1; }
|
|
virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
|
|
virtual uint32 key_length() const { return pack_length(); }
|
|
virtual enum_field_types type() const =0;
|
|
virtual enum_field_types real_type() const { return type(); }
|
|
inline int cmp(const char *str) { return cmp(ptr,str); }
|
|
virtual int cmp(const char *,const char *)=0;
|
|
virtual int cmp_binary(const char *a,const char *b, uint32 max_length=~0L)
|
|
{ return memcmp(a,b,pack_length()); }
|
|
virtual int cmp_offset(uint row_offset)
|
|
{ return memcmp(ptr,ptr+row_offset,pack_length()); }
|
|
virtual int cmp_binary_offset(uint row_offset)
|
|
{ return memcmp(ptr,ptr+row_offset,pack_length()); }
|
|
virtual int key_cmp(const byte *a,const byte *b)
|
|
{ return cmp((char*) a,(char*) b); }
|
|
virtual int key_cmp(const byte *str, uint length)
|
|
{ return cmp(ptr,(char*) str); }
|
|
virtual uint decimals() const { return 0; }
|
|
virtual void sql_type(String &str) const =0;
|
|
// Caller beware: sql_type can change str.Ptr, so check
|
|
// ptr() to see if it changed if you are using your own buffer
|
|
// in str and restore it with set() if needed
|
|
|
|
virtual uint size_of() const =0; // For new field
|
|
inline bool is_null(uint row_offset=0)
|
|
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
|
|
inline bool is_real_null(uint row_offset=0)
|
|
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
|
|
inline void set_null(int row_offset=0)
|
|
{ if (null_ptr) null_ptr[row_offset]|= null_bit; }
|
|
inline void set_notnull(int row_offset=0)
|
|
{ if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
|
|
inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
|
|
inline bool real_maybe_null(void) { return null_ptr != 0; }
|
|
virtual void make_field(Send_field *)=0;
|
|
virtual void sort_string(char *buff,uint length)=0;
|
|
virtual bool optimize_range();
|
|
virtual bool store_for_compare() { return 0; }
|
|
Field *new_field(MEM_ROOT *root, struct st_table *new_table)
|
|
{
|
|
Field *tmp= (Field*) memdup_root(root,(char*) this,size_of());
|
|
if (tmp)
|
|
{
|
|
tmp->table=new_table;
|
|
tmp->key_start=tmp->part_of_key=tmp->part_of_sortkey=0;
|
|
tmp->unireg_check=Field::NONE;
|
|
tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | ZEROFILL_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
|
|
tmp->reset_fields();
|
|
}
|
|
return tmp;
|
|
}
|
|
inline void move_field(char *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
|
|
{
|
|
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
|
|
}
|
|
inline void move_field(char *ptr_arg) { ptr=ptr_arg; }
|
|
inline void move_field(my_ptrdiff_t ptr_diff)
|
|
{
|
|
ptr=ADD_TO_PTR(ptr,ptr_diff,char*);
|
|
if (null_ptr)
|
|
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
|
|
}
|
|
inline void get_image(char *buff,uint length)
|
|
{ memcpy(buff,ptr,length); }
|
|
inline void set_image(char *buff,uint length)
|
|
{ memcpy(ptr,buff,length); }
|
|
virtual void get_key_image(char *buff,uint length)
|
|
{ get_image(buff,length); }
|
|
virtual void set_key_image(char *buff,uint length)
|
|
{ set_image(buff,length); }
|
|
inline int cmp_image(char *buff,uint length)
|
|
{
|
|
if (binary())
|
|
return memcmp(ptr,buff,length);
|
|
else
|
|
return my_casecmp(ptr,buff,length);
|
|
}
|
|
inline longlong val_int_offset(uint row_offset)
|
|
{
|
|
ptr+=row_offset;
|
|
longlong tmp=val_int();
|
|
ptr-=row_offset;
|
|
return tmp;
|
|
}
|
|
bool send(THD *thd, String *packet);
|
|
virtual char *pack(char* to, const char *from, uint max_length=~(uint) 0)
|
|
{
|
|
uint32 length=pack_length();
|
|
memcpy(to,from,length);
|
|
return to+length;
|
|
}
|
|
virtual const char *unpack(char* to, const char *from)
|
|
{
|
|
uint length=pack_length();
|
|
memcpy(to,from,length);
|
|
return from+length;
|
|
}
|
|
virtual char *pack_key(char* to, const char *from, uint max_length)
|
|
{
|
|
return pack(to,from,max_length);
|
|
}
|
|
virtual char *pack_key_from_key_image(char* to, const char *from,
|
|
uint max_length)
|
|
{
|
|
return pack(to,from,max_length);
|
|
}
|
|
virtual uint packed_col_length(const char *to, uint length)
|
|
{ return length;}
|
|
virtual uint max_packed_col_length(uint max_length)
|
|
{ return max_length;}
|
|
|
|
virtual int pack_cmp(const char *a,const char *b, uint key_length_arg)
|
|
{ return cmp(a,b); }
|
|
virtual int pack_cmp(const char *b, uint key_length_arg)
|
|
{ return cmp(ptr,b); }
|
|
uint offset(); // Should be inline ...
|
|
void copy_from_tmp(int offset);
|
|
uint fill_cache_field(struct st_cache_field *copy);
|
|
virtual bool get_date(TIME *ltime,bool fuzzydate);
|
|
virtual bool get_time(TIME *ltime);
|
|
friend bool reopen_table(THD *,struct st_table *,bool);
|
|
friend int cre_myisam(my_string name, register TABLE *form, uint options,
|
|
ulonglong auto_increment_value);
|
|
friend class Copy_field;
|
|
friend class Item_avg_field;
|
|
friend class Item_std_field;
|
|
friend class Item_sum_num;
|
|
friend class Item_sum_sum;
|
|
friend class Item_sum_str;
|
|
friend class Item_sum_count;
|
|
friend class Item_sum_avg;
|
|
friend class Item_sum_std;
|
|
friend class Item_sum_min;
|
|
friend class Item_sum_max;
|
|
};
|
|
|
|
|
|
class Field_num :public Field {
|
|
public:
|
|
const uint8 dec;
|
|
bool zerofill,unsigned_flag; // Purify cannot handle bit fields
|
|
Field_num(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg, utype unireg_check_arg,
|
|
const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
|
|
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg),
|
|
dec(dec_arg),zerofill(zero_arg),unsigned_flag(unsigned_arg)
|
|
{
|
|
if (zerofill)
|
|
flags|=ZEROFILL_FLAG;
|
|
if (unsigned_flag)
|
|
flags|=UNSIGNED_FLAG;
|
|
}
|
|
Item_result result_type () const { return REAL_RESULT; }
|
|
void prepend_zeros(String *value);
|
|
void add_zerofill_and_unsigned(String &res) const;
|
|
friend class create_field;
|
|
void make_field(Send_field *);
|
|
uint decimals() const { return (uint) dec; }
|
|
uint size_of() const { return sizeof(*this); }
|
|
bool eq_def(Field *field);
|
|
};
|
|
|
|
|
|
class Field_str :public Field {
|
|
public:
|
|
Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg, utype unireg_check_arg,
|
|
const char *field_name_arg,
|
|
struct st_table *table_arg)
|
|
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg)
|
|
{}
|
|
Item_result result_type () const { return STRING_RESULT; }
|
|
uint decimals() const { return NOT_FIXED_DEC; }
|
|
friend class create_field;
|
|
void make_field(Send_field *);
|
|
uint size_of() const { return sizeof(*this); }
|
|
};
|
|
|
|
|
|
class Field_decimal :public Field_num {
|
|
public:
|
|
Field_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
dec_arg, zero_arg,unsigned_arg)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_DECIMAL;}
|
|
enum ha_base_keytype key_type() const
|
|
{ return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
|
|
void reset(void);
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
void overflow(bool negative);
|
|
bool zero_pack() const { return 0; }
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
class Field_tiny :public Field_num {
|
|
public:
|
|
Field_tiny(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
bool zero_arg, bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
0, zero_arg,unsigned_arg)
|
|
{}
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
enum_field_types type() const { return FIELD_TYPE_TINY;}
|
|
enum ha_base_keytype key_type() const
|
|
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 1; }
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
class Field_short :public Field_num {
|
|
public:
|
|
Field_short(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
bool zero_arg, bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
0, zero_arg,unsigned_arg)
|
|
{}
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
enum_field_types type() const { return FIELD_TYPE_SHORT;}
|
|
enum ha_base_keytype key_type() const
|
|
{ return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=ptr[1]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 2; }
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
class Field_medium :public Field_num {
|
|
public:
|
|
Field_medium(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
bool zero_arg, bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
0, zero_arg,unsigned_arg)
|
|
{}
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
enum_field_types type() const { return FIELD_TYPE_INT24;}
|
|
enum ha_base_keytype key_type() const
|
|
{ return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 3; }
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
class Field_long :public Field_num {
|
|
public:
|
|
Field_long(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
bool zero_arg, bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
0, zero_arg,unsigned_arg)
|
|
{}
|
|
Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,bool unsigned_arg)
|
|
:Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
|
NONE, field_name_arg, table_arg,0,0,unsigned_arg)
|
|
{}
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
enum_field_types type() const { return FIELD_TYPE_LONG;}
|
|
enum ha_base_keytype key_type() const
|
|
{ return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 4; }
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
#ifdef HAVE_LONG_LONG
|
|
class Field_longlong :public Field_num {
|
|
public:
|
|
Field_longlong(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
bool zero_arg, bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
0, zero_arg,unsigned_arg)
|
|
{}
|
|
Field_longlong(uint32 len_arg,bool maybe_null_arg,
|
|
const char *field_name_arg,
|
|
struct st_table *table_arg, bool unsigned_arg)
|
|
:Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
|
NONE, field_name_arg, table_arg,0,0,unsigned_arg)
|
|
{}
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
enum_field_types type() const { return FIELD_TYPE_LONGLONG;}
|
|
enum ha_base_keytype key_type() const
|
|
{ return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 8; }
|
|
void sql_type(String &str) const;
|
|
};
|
|
#endif
|
|
|
|
class Field_float :public Field_num {
|
|
public:
|
|
Field_float(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
dec_arg, zero_arg,unsigned_arg)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_FLOAT;}
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { bzero(ptr,sizeof(float)); }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return sizeof(float); }
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
class Field_double :public Field_num {
|
|
public:
|
|
Field_double(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,
|
|
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg,
|
|
dec_arg, zero_arg,unsigned_arg)
|
|
{}
|
|
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
|
|
struct st_table *table_arg, uint8 dec_arg)
|
|
:Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
|
|
NONE, field_name_arg, table_arg,dec_arg,0,0)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_DOUBLE;}
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { bzero(ptr,sizeof(double)); }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return sizeof(double); }
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
/* Everything saved in this will disapper. It will always return NULL */
|
|
|
|
class Field_null :public Field_str {
|
|
static uchar null[1];
|
|
public:
|
|
Field_null(char *ptr_arg, uint32 len_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg)
|
|
:Field_str(ptr_arg, len_arg, null, 1,
|
|
unireg_check_arg, field_name_arg, table_arg)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_NULL;}
|
|
void store(const char *to, uint length) { null[0]=1; }
|
|
void store(double nr) { null[0]=1; }
|
|
void store(longlong nr) { null[0]=1; }
|
|
void reset(void) {}
|
|
double val_real(void) { return 0.0;}
|
|
longlong val_int(void) { return 0;}
|
|
String *val_str(String *value,String *value2)
|
|
{ value2->length(0); return value2;}
|
|
int cmp(const char *a, const char *b) { return 0;}
|
|
void sort_string(char *buff, uint length) {}
|
|
uint32 pack_length() const { return 0; }
|
|
void sql_type(String &str) const { str.set("null",4); }
|
|
uint size_of() const { return sizeof(*this); }
|
|
};
|
|
|
|
|
|
class Field_timestamp :public Field_num {
|
|
public:
|
|
Field_timestamp(char *ptr_arg, uint32 len_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg);
|
|
enum Item_result result_type () const { return field_length == 8 || field_length == 14 ? INT_RESULT : STRING_RESULT; }
|
|
enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;}
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 4; }
|
|
void sql_type(String &str) const;
|
|
bool store_for_compare() { return 1; }
|
|
bool zero_pack() const { return 0; }
|
|
void set_time();
|
|
inline long get_timestamp()
|
|
{
|
|
#ifdef WORDS_BIGENDIAN
|
|
if (table->db_low_byte_first)
|
|
return sint4korr(ptr);
|
|
#endif
|
|
long tmp;
|
|
longget(tmp,ptr);
|
|
return tmp;
|
|
}
|
|
void fill_and_store(char *from,uint len);
|
|
bool get_date(TIME *ltime,bool fuzzydate);
|
|
bool get_time(TIME *ltime);
|
|
};
|
|
|
|
|
|
class Field_year :public Field_tiny {
|
|
public:
|
|
Field_year(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg)
|
|
:Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg, 1, 1)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_YEAR;}
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
void sql_type(String &str) const;
|
|
};
|
|
|
|
|
|
class Field_date :public Field_str {
|
|
public:
|
|
Field_date(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg)
|
|
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_DATE;}
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 4; }
|
|
void sql_type(String &str) const;
|
|
bool store_for_compare() { return 1; }
|
|
bool zero_pack() const { return 1; }
|
|
};
|
|
|
|
class Field_newdate :public Field_str {
|
|
public:
|
|
Field_newdate(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg)
|
|
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_DATE;}
|
|
enum_field_types real_type() const { return FIELD_TYPE_NEWDATE; }
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void store_time(TIME *ltime,timestamp_type type);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 3; }
|
|
void sql_type(String &str) const;
|
|
bool store_for_compare() { return 1; }
|
|
bool zero_pack() const { return 1; }
|
|
bool get_date(TIME *ltime,bool fuzzydate);
|
|
bool get_time(TIME *ltime);
|
|
};
|
|
|
|
|
|
class Field_time :public Field_str {
|
|
public:
|
|
Field_time(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg)
|
|
:Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_TIME;}
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
bool get_time(TIME *ltime);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 3; }
|
|
void sql_type(String &str) const;
|
|
bool store_for_compare() { return 1; }
|
|
bool zero_pack() const { return 1; }
|
|
};
|
|
|
|
|
|
class Field_datetime :public Field_str {
|
|
public:
|
|
Field_datetime(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg)
|
|
:Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg)
|
|
{}
|
|
enum_field_types type() const { return FIELD_TYPE_DATETIME;}
|
|
#ifdef HAVE_LONG_LONG
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
|
|
#endif
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void store_time(TIME *ltime,timestamp_type type);
|
|
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return 8; }
|
|
void sql_type(String &str) const;
|
|
bool store_for_compare() { return 1; }
|
|
bool zero_pack() const { return 1; }
|
|
bool get_date(TIME *ltime,bool fuzzydate);
|
|
bool get_time(TIME *ltime);
|
|
};
|
|
|
|
|
|
class Field_string :public Field_str {
|
|
bool binary_flag;
|
|
public:
|
|
Field_string(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,bool binary_arg)
|
|
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg),
|
|
binary_flag(binary_arg)
|
|
{
|
|
if (binary_arg)
|
|
flags|=BINARY_FLAG;
|
|
}
|
|
Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
|
struct st_table *table_arg, bool binary_arg)
|
|
:Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
|
NONE, field_name_arg, table_arg),
|
|
binary_flag(binary_arg)
|
|
{
|
|
if (binary_arg)
|
|
flags|=BINARY_FLAG;
|
|
}
|
|
|
|
enum_field_types type() const
|
|
{
|
|
return ((table && table->db_create_options & HA_OPTION_PACK_RECORD &&
|
|
field_length >= 4) ?
|
|
FIELD_TYPE_VAR_STRING : FIELD_TYPE_STRING);
|
|
}
|
|
enum ha_base_keytype key_type() const
|
|
{ return binary_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
|
|
bool zero_pack() const { return 0; }
|
|
bool binary() const { return binary_flag; }
|
|
void reset(void) { bfill(ptr,field_length,' '); }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
void sql_type(String &str) const;
|
|
char *pack(char *to, const char *from, uint max_length=~(uint) 0);
|
|
const char *unpack(char* to, const char *from);
|
|
int pack_cmp(const char *a,const char *b,uint key_length);
|
|
int pack_cmp(const char *b,uint key_length);
|
|
uint packed_col_length(const char *to, uint length);
|
|
uint max_packed_col_length(uint max_length);
|
|
uint size_of() const { return sizeof(*this); }
|
|
enum_field_types real_type() const { return FIELD_TYPE_STRING; }
|
|
};
|
|
|
|
|
|
class Field_varstring :public Field_str {
|
|
bool binary_flag;
|
|
public:
|
|
Field_varstring(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,bool binary_arg)
|
|
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg),
|
|
binary_flag(binary_arg)
|
|
{
|
|
if (binary_arg)
|
|
flags|=BINARY_FLAG;
|
|
}
|
|
Field_varstring(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
|
struct st_table *table_arg, bool binary_arg)
|
|
:Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
|
NONE, field_name_arg, table_arg),
|
|
binary_flag(binary_arg)
|
|
{
|
|
if (binary_arg)
|
|
flags|=BINARY_FLAG;
|
|
}
|
|
|
|
enum_field_types type() const { return FIELD_TYPE_VAR_STRING; }
|
|
enum ha_base_keytype key_type() const
|
|
{ return binary_flag ? HA_KEYTYPE_VARBINARY : HA_KEYTYPE_VARTEXT; }
|
|
bool zero_pack() const { return 0; }
|
|
bool binary() const { return binary_flag; }
|
|
void reset(void) { bzero(ptr,field_length+2); }
|
|
uint32 pack_length() const { return (uint32) field_length+2; }
|
|
uint32 key_length() const { return (uint32) field_length; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
void sql_type(String &str) const;
|
|
char *pack(char *to, const char *from, uint max_length=~(uint) 0);
|
|
const char *unpack(char* to, const char *from);
|
|
int pack_cmp(const char *a, const char *b, uint key_length);
|
|
int pack_cmp(const char *b, uint key_length);
|
|
uint packed_col_length(const char *to, uint length);
|
|
uint max_packed_col_length(uint max_length);
|
|
uint size_of() const { return sizeof(*this); }
|
|
enum_field_types real_type() const { return FIELD_TYPE_VAR_STRING; }
|
|
};
|
|
|
|
|
|
class Field_blob :public Field_str {
|
|
uint packlength;
|
|
String value; // For temporaries
|
|
bool binary_flag;
|
|
public:
|
|
Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,uint blob_pack_length,
|
|
bool binary_arg);
|
|
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
|
struct st_table *table_arg, bool binary_arg)
|
|
:Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
|
NONE, field_name_arg, table_arg),
|
|
packlength(3),binary_flag(binary_arg)
|
|
{
|
|
flags|= BLOB_FLAG;
|
|
if (binary_arg)
|
|
flags|=BINARY_FLAG;
|
|
}
|
|
enum_field_types type() const { return FIELD_TYPE_BLOB;}
|
|
enum ha_base_keytype key_type() const
|
|
{ return binary_flag ? HA_KEYTYPE_VARBINARY : HA_KEYTYPE_VARTEXT; }
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
int cmp(const char *a, uint32 a_length, const char *b, uint32 b_length);
|
|
int cmp_offset(uint offset);
|
|
int cmp_binary(const char *a,const char *b, uint32 max_length=~0L);
|
|
int cmp_binary_offset(uint row_offset);
|
|
int key_cmp(const byte *,const byte*);
|
|
int key_cmp(const byte *str, uint length);
|
|
uint32 key_length() const { return 0; }
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const
|
|
{ return (uint32) (packlength+table->blob_ptr_size); }
|
|
void reset(void) { bzero(ptr, packlength+sizeof(char*)); }
|
|
void reset_fields() { bzero((char*) &value,sizeof(value)); }
|
|
void store_length(uint32 number);
|
|
inline uint32 get_length(uint row_offset=0)
|
|
{ return get_length(ptr+row_offset); }
|
|
uint32 get_length(const char *ptr);
|
|
bool binary() const { return binary_flag; }
|
|
inline void get_ptr(char **str)
|
|
{
|
|
memcpy_fixed(str,ptr+packlength,sizeof(char*));
|
|
}
|
|
inline void set_ptr(char *length,char *data)
|
|
{
|
|
memcpy(ptr,length,packlength);
|
|
memcpy_fixed(ptr+packlength,&data,sizeof(char*));
|
|
}
|
|
inline void set_ptr(uint32 length,char *data)
|
|
{
|
|
store_length(length);
|
|
memcpy_fixed(ptr+packlength,&data,sizeof(char*));
|
|
}
|
|
void get_key_image(char *buff,uint length);
|
|
void set_key_image(char *buff,uint length);
|
|
void sql_type(String &str) const;
|
|
inline bool copy()
|
|
{ char *tmp;
|
|
get_ptr(&tmp);
|
|
if (value.copy(tmp,get_length()))
|
|
{
|
|
Field_blob::reset();
|
|
return 1;
|
|
}
|
|
tmp=(char*) value.ptr(); memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
|
|
return 0;
|
|
}
|
|
char *pack(char *to, const char *from, uint max_length= ~(uint) 0);
|
|
const char *unpack(char *to, const char *from);
|
|
char *pack_key(char *to, const char *from, uint max_length);
|
|
char *pack_key_from_key_image(char* to, const char *from, uint max_length);
|
|
int pack_cmp(const char *a, const char *b, uint key_length);
|
|
int pack_cmp(const char *b, uint key_length);
|
|
uint packed_col_length(const char *col_ptr, uint length);
|
|
uint max_packed_col_length(uint max_length);
|
|
inline void free() { value.free(); }
|
|
inline void clear_temporary() { bzero((char*) &value,sizeof(value)); }
|
|
friend void field_conv(Field *to,Field *from);
|
|
uint size_of() const { return sizeof(*this); }
|
|
};
|
|
|
|
|
|
class Field_enum :public Field_str {
|
|
protected:
|
|
uint packlength;
|
|
public:
|
|
TYPELIB *typelib;
|
|
Field_enum(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,uint packlength_arg,
|
|
TYPELIB *typelib_arg)
|
|
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg, table_arg),
|
|
packlength(packlength_arg),typelib(typelib_arg)
|
|
{
|
|
flags|=ENUM_FLAG;
|
|
}
|
|
enum_field_types type() const { return FIELD_TYPE_STRING; }
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
|
enum ha_base_keytype key_type() const;
|
|
void store(const char *to,uint length);
|
|
void store(double nr);
|
|
void store(longlong nr);
|
|
void reset() { bzero(ptr,packlength); }
|
|
double val_real(void);
|
|
longlong val_int(void);
|
|
String *val_str(String*,String *);
|
|
int cmp(const char *,const char*);
|
|
void sort_string(char *buff,uint length);
|
|
uint32 pack_length() const { return (uint32) packlength; }
|
|
void store_type(ulonglong value);
|
|
void sql_type(String &str) const;
|
|
uint size_of() const { return sizeof(*this); }
|
|
enum_field_types real_type() const { return FIELD_TYPE_ENUM; }
|
|
virtual bool zero_pack() const { return 0; }
|
|
bool optimize_range() { return 0; }
|
|
bool binary() const { return 0; }
|
|
bool eq_def(Field *field);
|
|
};
|
|
|
|
|
|
class Field_set :public Field_enum {
|
|
public:
|
|
Field_set(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
uchar null_bit_arg,
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
struct st_table *table_arg,uint32 packlength_arg,
|
|
TYPELIB *typelib_arg)
|
|
:Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
unireg_check_arg, field_name_arg,
|
|
table_arg, packlength_arg,
|
|
typelib_arg)
|
|
{
|
|
flags=(flags & ~ENUM_FLAG) | SET_FLAG;
|
|
}
|
|
void store(const char *to,uint length);
|
|
void store(double nr) { Field_set::store((longlong) nr); }
|
|
void store(longlong nr);
|
|
virtual bool zero_pack() const { return 1; }
|
|
String *val_str(String*,String *);
|
|
void sql_type(String &str) const;
|
|
enum_field_types real_type() const { return FIELD_TYPE_SET; }
|
|
};
|
|
|
|
|
|
/*
|
|
** Create field class for CREATE TABLE
|
|
*/
|
|
|
|
class create_field :public Sql_alloc {
|
|
public:
|
|
const char *field_name;
|
|
const char *change; // If done with alter table
|
|
const char *after; // Put column after this one
|
|
Item *def; // Default value
|
|
enum enum_field_types sql_type;
|
|
uint32 length;
|
|
uint decimals,flags,pack_length;
|
|
Field::utype unireg_check;
|
|
TYPELIB *interval; // Which interval to use
|
|
Field *field; // For alter table
|
|
|
|
uint8 row,col,sc_length,interval_id; // For rea_create_table
|
|
uint offset,pack_flag;
|
|
create_field() :after(0) {}
|
|
create_field(Field *field, Field *orig_field);
|
|
};
|
|
|
|
|
|
/*
|
|
** A class for sending info to the client
|
|
*/
|
|
|
|
class Send_field {
|
|
public:
|
|
const char *table_name,*col_name;
|
|
uint length,flags,decimals;
|
|
enum_field_types type;
|
|
Send_field() {}
|
|
};
|
|
|
|
|
|
/*
|
|
** A class for quick copying data to fields
|
|
*/
|
|
|
|
class Copy_field :public Sql_alloc {
|
|
void (*get_copy_func(Field *to,Field *from))(Copy_field *);
|
|
public:
|
|
char *from_ptr,*to_ptr;
|
|
uchar *from_null_ptr,*to_null_ptr;
|
|
my_bool *null_row;
|
|
uint from_bit,to_bit;
|
|
uint from_length,to_length;
|
|
Field *from_field,*to_field;
|
|
String tmp; // For items
|
|
|
|
Copy_field() {}
|
|
~Copy_field() {}
|
|
void set(Field *to,Field *from,bool save); // Field to field
|
|
void set(char *to,Field *from); // Field to string
|
|
void (*do_copy)(Copy_field *);
|
|
void (*do_copy2)(Copy_field *); // Used to handle null values
|
|
};
|
|
|
|
|
|
Field *make_field(char *ptr, uint32 field_length,
|
|
uchar *null_pos, uchar null_bit,
|
|
uint pack_flag, Field::utype unireg_check,
|
|
TYPELIB *interval, const char *field_name,
|
|
struct st_table *table);
|
|
uint pack_length_to_packflag(uint type);
|
|
uint32 calc_pack_length(enum_field_types type,uint32 length);
|
|
bool set_field_to_null(Field *field);
|
|
uint find_enum(TYPELIB *typelib,const char *x, uint length);
|
|
ulonglong find_set(TYPELIB *typelib,const char *x, uint length);
|
|
bool test_if_int(const char *str,int length);
|
|
|
|
/*
|
|
** The following are for the interface with the .frm file
|
|
*/
|
|
|
|
#define FIELDFLAG_DECIMAL 1
|
|
#define FIELDFLAG_BINARY 1 // Shares same flag
|
|
#define FIELDFLAG_NUMBER 2
|
|
#define FIELDFLAG_ZEROFILL 4
|
|
#define FIELDFLAG_PACK 120 // Bits used for packing
|
|
#define FIELDFLAG_INTERVAL 256
|
|
#define FIELDFLAG_BITFIELD 512 // mangled with dec!
|
|
#define FIELDFLAG_BLOB 1024 // mangled with dec!
|
|
#define FIELDFLAG_LEFT_FULLSCREEN 8192
|
|
#define FIELDFLAG_RIGHT_FULLSCREEN 16384
|
|
#define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output
|
|
#define FIELDFLAG_SUM ((uint) 32768)// predit: +#fieldflag
|
|
#define FIELDFLAG_MAYBE_NULL ((uint) 32768)// sql
|
|
#define FIELDFLAG_PACK_SHIFT 3
|
|
#define FIELDFLAG_DEC_SHIFT 8
|
|
#define FIELDFLAG_MAX_DEC 31
|
|
#define FIELDFLAG_NUM_SCREEN_TYPE 0x7F01
|
|
#define FIELDFLAG_ALFA_SCREEN_TYPE 0x7800
|
|
|
|
#define FIELD_SORT_REVERSE 16384
|
|
|
|
#define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */
|
|
|
|
#define f_is_dec(x) ((x) & FIELDFLAG_DECIMAL)
|
|
#define f_is_num(x) ((x) & FIELDFLAG_NUMBER)
|
|
#define f_is_zerofill(x) ((x) & FIELDFLAG_ZEROFILL)
|
|
#define f_is_packed(x) ((x) & FIELDFLAG_PACK)
|
|
#define f_packtype(x) (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
|
|
#define f_decimals(x) ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
|
|
#define f_is_alpha(x) (!f_is_num(x))
|
|
#define f_is_binary(x) ((x) & FIELDFLAG_BINARY)
|
|
#define f_is_enum(x) ((x) & FIELDFLAG_INTERVAL)
|
|
#define f_is_bitfield(x) ((x) & FIELDFLAG_BITFIELD)
|
|
#define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
|
|
#define f_is_equ(x) ((x) & (1+2+FIELDFLAG_PACK+31*256))
|
|
#define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT)
|
|
#define f_maybe_null(x) (x & FIELDFLAG_MAYBE_NULL)
|