2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2000-2006 MySQL AB
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-12-05 12:03:00 +01:00
|
|
|
Because of the function new_field() all field classes that have static
|
|
|
|
variables must declare the size_of() member function.
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
2005-05-04 15:05:56 +02:00
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
2000-07-31 21:29:14 +02:00
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NOT_FIXED_DEC 31
|
2005-06-20 19:49:04 +02:00
|
|
|
#define DATETIME_DEC 6
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
class Send_field;
|
2002-12-11 08:17:51 +01:00
|
|
|
class Protocol;
|
2005-07-22 22:43:59 +02:00
|
|
|
class create_field;
|
2000-07-31 21:29:14 +02:00
|
|
|
struct st_cache_field;
|
2007-02-06 10:08:57 +01:00
|
|
|
int field_conv(Field *to,Field *from);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-03-23 07:36:48 +01:00
|
|
|
inline uint get_enum_pack_length(int elements)
|
|
|
|
{
|
|
|
|
return elements < 256 ? 1 : 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint get_set_pack_length(int elements)
|
|
|
|
{
|
|
|
|
uint len= (elements + 7) / 8;
|
|
|
|
return len > 4 ? 8 : len;
|
|
|
|
}
|
|
|
|
|
2002-12-11 08:17:51 +01:00
|
|
|
class Field
|
|
|
|
{
|
2001-11-06 23:13:29 +01:00
|
|
|
Field(const Item &); /* Prevent use of these */
|
2000-07-31 21:29:14 +02:00
|
|
|
void operator=(Field &);
|
|
|
|
public:
|
2000-08-23 14:02:27 +02:00
|
|
|
static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
|
2005-02-04 21:01:30 +01:00
|
|
|
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-08-02 14:05:10 +02:00
|
|
|
char *ptr; // Position to field in record
|
|
|
|
uchar *null_ptr; // Byte where null_bit is
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
Note that you can use table->in_use as replacement for current_thd member
|
|
|
|
only inside of val_*() and store() members (e.g. you can't use it in cons)
|
|
|
|
*/
|
2002-08-02 14:05:10 +02:00
|
|
|
struct st_table *table; // Pointer for table
|
2004-03-30 18:24:28 +02:00
|
|
|
struct st_table *orig_table; // Pointer to original table
|
2005-02-04 21:01:30 +01:00
|
|
|
const char **table_name, *field_name;
|
2002-06-02 20:22:20 +02:00
|
|
|
LEX_STRING comment;
|
2002-07-17 14:17:20 +02:00
|
|
|
/* Field is part of the following keys */
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
key_map key_start, part_of_key, part_of_key_not_clustered;
|
|
|
|
key_map part_of_sortkey;
|
2004-04-02 08:12:53 +02:00
|
|
|
/*
|
|
|
|
We use three additional unireg types for TIMESTAMP to overcome limitation
|
|
|
|
of current binary format of .frm file. We'd like to be able to support
|
|
|
|
NOW() as default and on update value for such fields but unable to hold
|
|
|
|
this info anywhere except unireg_check field. This issue will be resolved
|
|
|
|
in more clean way with transition to new text based .frm format.
|
|
|
|
See also comment for Field_timestamp::Field_timestamp().
|
|
|
|
*/
|
2001-12-05 12:03:00 +01:00
|
|
|
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
|
|
|
|
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
|
2004-04-02 08:12:53 +02:00
|
|
|
BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
|
|
|
|
TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
|
2003-03-27 10:09:09 +01:00
|
|
|
enum geometry_type
|
|
|
|
{
|
|
|
|
GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3,
|
|
|
|
GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6,
|
|
|
|
GEOM_GEOMETRYCOLLECTION = 7
|
|
|
|
};
|
2002-02-22 12:24:42 +01:00
|
|
|
enum imagetype { itRAW, itMBR};
|
2003-05-03 01:16:56 +02:00
|
|
|
|
2001-12-05 12:03:00 +01:00
|
|
|
utype unireg_check;
|
2002-08-02 14:05:10 +02:00
|
|
|
uint32 field_length; // Length of field
|
2005-07-18 13:31:02 +02:00
|
|
|
uint32 flags;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
uint16 field_index; // field number in fields array
|
2002-08-02 14:05:10 +02:00
|
|
|
uchar null_bit; // Bit used to test null bit
|
2001-12-05 12:03:00 +01:00
|
|
|
|
|
|
|
Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,uchar null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
utype unireg_check_arg, const char *field_name_arg);
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual ~Field() {}
|
2004-04-12 00:42:39 +02:00
|
|
|
/* Store functions returns 1 on overflow and -1 on fatal error */
|
2002-08-24 13:49:04 +02:00
|
|
|
virtual int store(const char *to,uint length,CHARSET_INFO *cs)=0;
|
|
|
|
virtual int store(double nr)=0;
|
2005-09-14 00:41:44 +02:00
|
|
|
virtual int store(longlong nr, bool unsigned_val)=0;
|
2005-02-08 23:50:45 +01:00
|
|
|
virtual int store_decimal(const my_decimal *d)=0;
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual double val_real(void)=0;
|
|
|
|
virtual longlong val_int(void)=0;
|
2005-02-08 23:50:45 +01:00
|
|
|
virtual my_decimal *val_decimal(my_decimal *);
|
2004-04-07 16:04:28 +02:00
|
|
|
inline String *val_str(String *str) { return val_str(str, str); }
|
|
|
|
/*
|
|
|
|
val_str(buf1, buf2) gets two buffers and should use them as follows:
|
2004-04-06 21:35:26 +02:00
|
|
|
if it needs a temp buffer to convert result to string - use buf1
|
|
|
|
example Field_tiny::val_str()
|
|
|
|
if the value exists as a string already - use buf2
|
|
|
|
example Field_string::val_str()
|
|
|
|
consequently, buf2 may be created as 'String buf;' - no memory
|
|
|
|
will be allocated for it. buf1 will be allocated to hold a
|
|
|
|
value if it's too small. Using allocated buffer for buf2 may result in
|
|
|
|
an unnecessary free (and later, may be an alloc).
|
|
|
|
This trickery is used to decrease a number of malloc calls.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual String *val_str(String*,String *)=0;
|
2005-02-04 21:01:30 +01:00
|
|
|
String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
|
2006-07-26 01:12:48 +02:00
|
|
|
/*
|
|
|
|
str_needs_quotes() returns TRUE if the value returned by val_str() needs
|
|
|
|
to be quoted when used in constructing an SQL query.
|
|
|
|
*/
|
|
|
|
virtual bool str_needs_quotes() { return FALSE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual Item_result result_type () const=0;
|
|
|
|
virtual Item_result cmp_type () const { return result_type(); }
|
2005-04-29 16:03:34 +02:00
|
|
|
virtual Item_result cast_to_int_type () const { return result_type(); }
|
2005-05-26 03:11:47 +02:00
|
|
|
static bool type_can_have_key_part(enum_field_types);
|
2005-03-23 07:36:48 +01:00
|
|
|
static enum_field_types field_type_merge(enum_field_types, enum_field_types);
|
|
|
|
static Item_result result_merge_type(enum_field_types);
|
2006-06-14 14:57:23 +02:00
|
|
|
virtual bool eq(Field *field)
|
2005-02-04 21:01:30 +01:00
|
|
|
{
|
|
|
|
return (ptr == field->ptr && null_ptr == field->null_ptr &&
|
|
|
|
null_bit == field->null_bit);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual bool eq_def(Field *field);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
pack_length() returns size (in bytes) used to store field data in memory
|
|
|
|
(i.e. it returns the maximum size of the field in a row of the table,
|
|
|
|
which is located in RAM).
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual uint32 pack_length() const { return (uint32) field_length; }
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
pack_length_in_rec() returns size (in bytes) used to store field data on
|
|
|
|
storage (i.e. it returns the maximal size of the field in a row of the
|
|
|
|
table, which is located on disk).
|
|
|
|
*/
|
2005-02-04 21:01:30 +01:00
|
|
|
virtual uint32 pack_length_in_rec() const { return pack_length(); }
|
2006-08-14 12:29:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
data_length() return the "real size" of the data in memory.
|
|
|
|
*/
|
2006-11-16 02:55:17 +01:00
|
|
|
virtual uint32 data_length() { return pack_length(); }
|
2005-10-13 23:04:52 +02:00
|
|
|
virtual uint32 sort_length() const { return pack_length(); }
|
2006-12-06 18:45:57 +01:00
|
|
|
virtual int reset(void) { bzero(ptr,pack_length()); return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual void reset_fields() {}
|
2002-07-25 00:00:56 +02:00
|
|
|
virtual void set_default()
|
|
|
|
{
|
2006-12-14 23:51:37 +01:00
|
|
|
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values -
|
2003-05-26 19:59:09 +02:00
|
|
|
table->record[0]);
|
2006-12-14 23:51:37 +01:00
|
|
|
memcpy(ptr, ptr + l_offset, pack_length());
|
2002-08-08 02:12:02 +02:00
|
|
|
if (null_ptr)
|
|
|
|
*null_ptr= ((*null_ptr & (uchar) ~null_bit) |
|
2006-12-14 23:51:37 +01:00
|
|
|
null_ptr[l_offset] & null_bit);
|
2002-07-25 00:00:56 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
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); }
|
2005-07-18 13:31:02 +02:00
|
|
|
virtual int cmp_max(const char *a, const char *b, uint max_len)
|
|
|
|
{ return cmp(a, b); }
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual int cmp(const char *,const char *)=0;
|
2001-12-05 12:03:00 +01:00
|
|
|
virtual int cmp_binary(const char *a,const char *b, uint32 max_length=~0L)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ return memcmp(a,b,pack_length()); }
|
2006-02-24 15:38:20 +01:00
|
|
|
virtual int cmp_offset(uint row_offset)
|
|
|
|
{ return cmp(ptr,ptr+row_offset); }
|
|
|
|
virtual int cmp_binary_offset(uint row_offset)
|
2005-02-04 21:01:30 +01:00
|
|
|
{ return cmp_binary(ptr, ptr+row_offset); };
|
2000-07-31 21:29:14 +02:00
|
|
|
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; }
|
2002-07-17 14:17:20 +02:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2002-08-08 02:12:02 +02:00
|
|
|
virtual void sql_type(String &str) const =0;
|
2002-08-02 14:05:10 +02:00
|
|
|
virtual uint size_of() const =0; // For new field
|
2007-03-28 15:30:03 +02:00
|
|
|
inline bool is_null(my_ptrdiff_t row_offset= 0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
|
2007-03-28 15:30:03 +02:00
|
|
|
inline bool is_real_null(my_ptrdiff_t row_offset= 0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
|
2003-09-11 18:06:23 +02:00
|
|
|
inline bool is_null_in_record(const uchar *record)
|
|
|
|
{
|
|
|
|
if (!null_ptr)
|
|
|
|
return 0;
|
|
|
|
return test(record[(uint) (null_ptr - (uchar*) table->record[0])] &
|
|
|
|
null_bit);
|
|
|
|
}
|
2005-07-22 23:05:16 +02:00
|
|
|
inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
|
|
|
|
{
|
|
|
|
if (!null_ptr)
|
|
|
|
return 0;
|
|
|
|
return test(null_ptr[offset] & null_bit);
|
|
|
|
}
|
2007-03-28 15:30:03 +02:00
|
|
|
inline void set_null(my_ptrdiff_t row_offset= 0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ if (null_ptr) null_ptr[row_offset]|= null_bit; }
|
2007-03-28 15:30:03 +02:00
|
|
|
inline void set_notnull(my_ptrdiff_t row_offset= 0)
|
2001-12-05 12:03:00 +01:00
|
|
|
{ if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
|
2000-07-31 21:29:14 +02:00
|
|
|
inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
|
|
|
|
inline bool real_maybe_null(void) { return null_ptr != 0; }
|
2006-05-08 20:05:25 +02:00
|
|
|
|
2006-09-13 19:25:12 +02:00
|
|
|
enum {
|
|
|
|
LAST_NULL_BYTE_UNDEF= 0
|
|
|
|
};
|
|
|
|
|
2006-05-08 20:05:25 +02:00
|
|
|
/*
|
2006-09-13 19:25:12 +02:00
|
|
|
Find the position of the last null byte for the field.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
last_null_byte()
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Return a pointer to the last byte of the null bytes where the
|
|
|
|
field conceptually is placed.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
The position of the last null byte relative to the beginning of
|
|
|
|
the record. If the field does not use any bits of the null
|
|
|
|
bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
|
2006-05-08 20:05:25 +02:00
|
|
|
*/
|
|
|
|
my_size_t last_null_byte() const {
|
|
|
|
my_size_t bytes= do_last_null_byte();
|
2006-11-27 17:16:08 +01:00
|
|
|
DBUG_PRINT("debug", ("last_null_byte() ==> %ld", (long) bytes));
|
2006-05-08 20:05:25 +02:00
|
|
|
DBUG_ASSERT(bytes <= table->s->null_bytes);
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
2005-02-04 21:01:30 +01:00
|
|
|
virtual void make_field(Send_field *);
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual void sort_string(char *buff,uint length)=0;
|
2004-07-08 14:45:25 +02:00
|
|
|
virtual bool optimize_range(uint idx, uint part);
|
2004-09-28 13:29:38 +02:00
|
|
|
/*
|
|
|
|
This should be true for fields which, when compared with constant
|
|
|
|
items, can be casted to longlong. In this case we will at 'fix_fields'
|
|
|
|
stage cast the constant items to longlongs and at the execution stage
|
|
|
|
use field->val_int() for comparison. Used to optimize clauses like
|
|
|
|
'a_column BETWEEN date_const, date_const'.
|
|
|
|
*/
|
|
|
|
virtual bool can_be_compared_as_longlong() const { return FALSE; }
|
2003-06-13 23:00:04 +02:00
|
|
|
virtual void free() {}
|
2006-06-26 20:57:18 +02:00
|
|
|
virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
|
|
|
|
bool keep_type);
|
2005-02-04 21:01:30 +01:00
|
|
|
virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
|
|
|
|
char *new_ptr, uchar *new_null_ptr,
|
|
|
|
uint new_null_bit);
|
2005-11-23 21:45:02 +01:00
|
|
|
Field *clone(MEM_ROOT *mem_root, struct st_table *new_table);
|
2005-05-07 08:59:12 +02:00
|
|
|
inline void move_field(char *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
|
2001-12-05 12:03:00 +01:00
|
|
|
{
|
|
|
|
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
inline void move_field(char *ptr_arg) { ptr=ptr_arg; }
|
2005-11-23 21:45:02 +01:00
|
|
|
virtual void move_field_offset(my_ptrdiff_t ptr_diff)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
ptr=ADD_TO_PTR(ptr,ptr_diff,char*);
|
|
|
|
if (null_ptr)
|
|
|
|
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
|
|
|
|
}
|
2002-12-19 12:27:46 +01:00
|
|
|
inline void get_image(char *buff,uint length, CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ memcpy(buff,ptr,length); }
|
2002-12-19 12:27:46 +01:00
|
|
|
inline void set_image(char *buff,uint length, CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ memcpy(ptr,buff,length); }
|
2007-04-29 01:16:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copy a field part into an output buffer.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Field::get_key_image()
|
|
|
|
buff [out] output buffer
|
|
|
|
length output buffer size
|
|
|
|
type itMBR for geometry blobs, otherwise itRAW
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This function makes a copy of field part of size equal to or
|
|
|
|
less than "length" parameter value.
|
|
|
|
For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
|
|
|
|
is padded by zero byte.
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
For variable length character fields (i.e. UTF-8) the "length"
|
|
|
|
parameter means a number of output buffer bytes as if all field
|
|
|
|
characters have maximal possible size (mbmaxlen). In the other words,
|
|
|
|
"length" parameter is a number of characters multiplied by
|
|
|
|
field_charset->mbmaxlen.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
Number of copied bytes (excluding padded zero bytes -- see above).
|
|
|
|
*/
|
|
|
|
|
2007-04-29 05:51:51 +02:00
|
|
|
virtual uint get_key_image(char *buff, uint length, imagetype type)
|
2007-04-29 01:16:17 +02:00
|
|
|
{
|
2007-04-29 05:51:51 +02:00
|
|
|
get_image(buff, length, &my_charset_bin);
|
2007-04-29 01:16:17 +02:00
|
|
|
return length;
|
|
|
|
}
|
2005-02-04 21:01:30 +01:00
|
|
|
virtual void set_key_image(char *buff,uint length)
|
|
|
|
{ set_image(buff,length, &my_charset_bin); }
|
2000-07-31 21:29:14 +02:00
|
|
|
inline longlong val_int_offset(uint row_offset)
|
|
|
|
{
|
|
|
|
ptr+=row_offset;
|
|
|
|
longlong tmp=val_int();
|
|
|
|
ptr-=row_offset;
|
|
|
|
return tmp;
|
|
|
|
}
|
2006-01-09 11:35:40 +01:00
|
|
|
inline longlong val_int(char *new_ptr)
|
|
|
|
{
|
|
|
|
char *old_ptr= ptr;
|
|
|
|
longlong return_value;
|
|
|
|
ptr= new_ptr;
|
|
|
|
return_value= val_int();
|
|
|
|
ptr= old_ptr;
|
|
|
|
return return_value;
|
|
|
|
}
|
2005-02-04 21:01:30 +01:00
|
|
|
inline String *val_str(String *str, char *new_ptr)
|
|
|
|
{
|
|
|
|
char *old_ptr= ptr;
|
|
|
|
ptr= new_ptr;
|
|
|
|
val_str(str);
|
|
|
|
ptr= old_ptr;
|
|
|
|
return str;
|
|
|
|
}
|
2003-01-03 12:52:53 +01:00
|
|
|
virtual bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual char *pack(char* to, const char *from, uint max_length=~(uint) 0)
|
|
|
|
{
|
2001-12-05 12:03:00 +01:00
|
|
|
uint32 length=pack_length();
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
|
|
|
}
|
2001-01-17 02:15:20 +01:00
|
|
|
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)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
return pack(to,from,max_length);
|
|
|
|
}
|
2004-06-24 14:54:28 +02:00
|
|
|
virtual const char *unpack_key(char* to, const char *from, uint max_length)
|
|
|
|
{
|
|
|
|
return unpack(to,from);
|
|
|
|
}
|
2001-11-03 14:18:09 +01:00
|
|
|
virtual uint packed_col_length(const char *to, uint length)
|
|
|
|
{ return length;}
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual uint max_packed_col_length(uint max_length)
|
2001-11-03 14:18:09 +01:00
|
|
|
{ return max_length;}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-02-04 21:01:30 +01:00
|
|
|
virtual int pack_cmp(const char *a,const char *b, uint key_length_arg,
|
|
|
|
my_bool insert_or_update)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ return cmp(a,b); }
|
2005-02-04 21:01:30 +01:00
|
|
|
virtual int pack_cmp(const char *b, uint key_length_arg,
|
|
|
|
my_bool insert_or_update)
|
2000-10-25 00:50:46 +02:00
|
|
|
{ return cmp(ptr,b); }
|
2006-11-21 21:32:58 +01:00
|
|
|
uint offset(byte *record)
|
|
|
|
{
|
|
|
|
return (uint) (ptr - (char*) record);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
void copy_from_tmp(int offset);
|
|
|
|
uint fill_cache_field(struct st_cache_field *copy);
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
|
|
|
|
virtual bool get_time(MYSQL_TIME *ltime);
|
2003-01-29 14:31:20 +01:00
|
|
|
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
|
2005-02-28 10:59:46 +01:00
|
|
|
virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
|
2003-05-23 10:10:25 +02:00
|
|
|
virtual bool has_charset(void) const { return FALSE; }
|
2006-12-14 23:51:37 +01:00
|
|
|
virtual void set_charset(CHARSET_INFO *charset_arg) { }
|
2006-11-09 11:41:34 +01:00
|
|
|
virtual enum Derivation derivation(void) const
|
|
|
|
{ return DERIVATION_IMPLICIT; }
|
2006-12-14 23:51:37 +01:00
|
|
|
virtual void set_derivation(enum Derivation derivation_arg) { }
|
2005-04-01 14:04:50 +02:00
|
|
|
bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
|
2004-06-18 08:11:31 +02:00
|
|
|
int cuted_increment);
|
2005-04-01 14:04:50 +02:00
|
|
|
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code,
|
2004-06-18 08:11:31 +02:00
|
|
|
const char *str, uint str_len,
|
|
|
|
timestamp_type ts_type, int cuted_increment);
|
2005-04-01 14:04:50 +02:00
|
|
|
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code,
|
2004-06-18 08:11:31 +02:00
|
|
|
longlong nr, timestamp_type ts_type,
|
|
|
|
int cuted_increment);
|
2005-04-01 14:04:50 +02:00
|
|
|
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code,
|
2004-06-18 08:11:31 +02:00
|
|
|
double nr, timestamp_type ts_type);
|
2005-02-10 14:41:51 +01:00
|
|
|
inline bool check_overflow(int op_result)
|
|
|
|
{
|
|
|
|
return (op_result == E_DEC_OVERFLOW);
|
|
|
|
}
|
|
|
|
int warn_if_overflow(int op_result);
|
2005-11-23 21:45:02 +01:00
|
|
|
void init(TABLE *table_arg)
|
|
|
|
{
|
|
|
|
orig_table= table= table_arg;
|
|
|
|
table_name= &table_arg->alias;
|
|
|
|
}
|
|
|
|
|
2004-06-17 12:48:31 +02:00
|
|
|
/* maximum possible display length */
|
2006-12-14 23:51:37 +01:00
|
|
|
virtual uint32 max_display_length()= 0;
|
2005-07-22 22:43:59 +02:00
|
|
|
|
|
|
|
virtual uint is_equal(create_field *new_field);
|
2005-02-08 23:50:45 +01:00
|
|
|
/* convert decimal to longlong with overflow check */
|
|
|
|
longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
|
|
|
|
int *err);
|
2006-03-28 15:06:06 +02:00
|
|
|
/* The max. number of characters */
|
2006-03-29 22:20:14 +02:00
|
|
|
inline uint32 char_length() const
|
2006-03-28 15:06:06 +02:00
|
|
|
{
|
|
|
|
return field_length / charset()->mbmaxlen;
|
|
|
|
}
|
|
|
|
|
2006-06-21 10:00:19 +02:00
|
|
|
/* Hash value */
|
|
|
|
virtual void hash(ulong *nr, ulong *nr2);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2003-03-18 00:07:40 +01:00
|
|
|
friend class Item_func_group_concat;
|
2006-05-08 20:05:25 +02:00
|
|
|
|
|
|
|
private:
|
2006-09-13 19:25:12 +02:00
|
|
|
/*
|
|
|
|
Primitive for implementing last_null_byte().
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
do_last_null_byte()
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Primitive for the implementation of the last_null_byte()
|
|
|
|
function. This represents the inheritance interface and can be
|
|
|
|
overridden by subclasses.
|
|
|
|
*/
|
2006-05-08 20:05:25 +02:00
|
|
|
virtual my_size_t do_last_null_byte() const;
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_num :public Field {
|
|
|
|
public:
|
|
|
|
const uint8 dec;
|
2002-08-02 14:05:10 +02:00
|
|
|
bool zerofill,unsigned_flag; // Purify cannot handle bit fields
|
2000-07-31 21:29:14 +02:00
|
|
|
Field_num(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg, utype unireg_check_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
const char *field_name_arg,
|
2005-02-08 23:50:45 +01:00
|
|
|
uint8 dec_arg, bool zero_arg, bool unsigned_arg);
|
2000-07-31 21:29:14 +02:00
|
|
|
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 *);
|
2001-12-05 12:03:00 +01:00
|
|
|
uint decimals() const { return (uint) dec; }
|
2000-07-31 21:29:14 +02:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
|
|
|
bool eq_def(Field *field);
|
2005-02-08 23:50:45 +01:00
|
|
|
int store_decimal(const my_decimal *);
|
|
|
|
my_decimal *val_decimal(my_decimal *);
|
2005-07-22 22:43:59 +02:00
|
|
|
uint is_equal(create_field *new_field);
|
2007-03-29 06:08:30 +02:00
|
|
|
int check_int(CHARSET_INFO *cs, const char *str, int length,
|
|
|
|
const char *int_end, int error);
|
|
|
|
bool get_int(CHARSET_INFO *cs, const char *from, uint len,
|
|
|
|
longlong *rnd, ulonglong unsigned_max,
|
|
|
|
longlong signed_min, longlong signed_max);
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_str :public Field {
|
2002-03-12 18:37:58 +01:00
|
|
|
protected:
|
|
|
|
CHARSET_INFO *field_charset;
|
2006-11-09 11:41:34 +01:00
|
|
|
enum Derivation field_derivation;
|
2004-08-19 03:02:09 +02:00
|
|
|
public:
|
2000-07-31 21:29:14 +02:00
|
|
|
Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg, utype unireg_check_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
const char *field_name_arg, CHARSET_INFO *charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
Item_result result_type () const { return STRING_RESULT; }
|
|
|
|
uint decimals() const { return NOT_FIXED_DEC; }
|
2004-08-19 03:02:09 +02:00
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val)=0;
|
2005-02-08 23:50:45 +01:00
|
|
|
int store_decimal(const my_decimal *);
|
2004-08-19 03:02:09 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *cs)=0;
|
2000-07-31 21:29:14 +02:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
2002-11-06 14:01:12 +01:00
|
|
|
CHARSET_INFO *charset(void) const { return field_charset; }
|
2006-12-14 23:51:37 +01:00
|
|
|
void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; }
|
2006-11-09 11:41:34 +01:00
|
|
|
enum Derivation derivation(void) const { return field_derivation; }
|
|
|
|
virtual void set_derivation(enum Derivation derivation_arg)
|
|
|
|
{ field_derivation= derivation_arg; }
|
2004-08-19 12:15:10 +02:00
|
|
|
bool binary() const { return field_charset == &my_charset_bin; }
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return field_length; }
|
2002-06-04 07:23:57 +02:00
|
|
|
friend class create_field;
|
2005-02-08 23:50:45 +01:00
|
|
|
my_decimal *val_decimal(my_decimal *);
|
2006-07-26 01:12:48 +02:00
|
|
|
virtual bool str_needs_quotes() { return TRUE; }
|
2007-04-27 12:21:23 +02:00
|
|
|
bool compare_str_field_flags(create_field *new_field, uint32 flags);
|
2005-07-22 22:43:59 +02:00
|
|
|
uint is_equal(create_field *new_field);
|
2005-02-08 23:50:45 +01:00
|
|
|
};
|
|
|
|
|
2005-02-15 15:45:00 +01:00
|
|
|
|
|
|
|
/* base class for Field_string, Field_varstring and Field_blob */
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
class Field_longstr :public Field_str
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Field_longstr(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
|
|
uchar null_bit_arg, utype unireg_check_arg,
|
2007-01-27 02:46:45 +01:00
|
|
|
const char *field_name_arg, CHARSET_INFO *charset_arg)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
|
2007-01-27 02:46:45 +01:00
|
|
|
field_name_arg, charset_arg)
|
2005-02-08 23:50:45 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
int store_decimal(const my_decimal *d);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* base class for float and double and decimal (old one) */
|
|
|
|
class Field_real :public Field_num {
|
|
|
|
public:
|
|
|
|
Field_real(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
|
|
uchar null_bit_arg, utype unireg_check_arg,
|
|
|
|
const char *field_name_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,
|
2005-11-23 21:45:02 +01:00
|
|
|
field_name_arg, dec_arg, zero_arg, unsigned_arg)
|
2005-02-08 23:50:45 +01:00
|
|
|
{}
|
|
|
|
int store_decimal(const my_decimal *);
|
|
|
|
my_decimal *val_decimal(my_decimal *);
|
Bug #24791: Union with AVG-groups generates wrong results
The problem in this bug is when we create temporary tables. When
temporary tables are created for unions, there is some
inferrence being carried out regarding the type of the column.
Whenever this column type is inferred to be REAL (i.e. FLOAT or
DOUBLE), MySQL will always try to maintain exact precision, and
if that is not possible (there are hardware limits, since FLOAT
and DOUBLE are stored as approximate values) will switch to
using approximate values. The problem here is that at this point
the information about number of significant digits is not
available. Furthermore, the number of significant digits should
be increased for the AVG function, however, this was not properly
handled. There are 4 parts to the problem:
#1: DOUBLE and FLOAT fields don't display their proper display
lengths in max_display_length(). This is hard-coded as 53 for
DOUBLE and 24 for FLOAT. Now changed to instead return the
field_length.
#2: Type holders for temporary tables do not preserve the
max_length of the Item's from which they are created, and is
instead reverted to the 53 and 24 from above. This causes
*all* fields to get non-fixed significant digits.
#3: AVG function does not update max_length (display length)
when updating number of decimals.
#4: The function that switches to non-fixed number of
significant digits should use DBL_DIG + 2 or FLT_DIG + 2 as
cut-off values (Since fixed precision does not use the 'e'
notation)
Of these points, #1 is the controversial one, but this
change is preferred and has been cleared with Monty. The
function causes quite a few unit tests to blow up and they had
to b changed, but each one is annotated and motivated. We
frequently see the magical 53 and 24 give way to more relevant
numbers.
2007-03-22 10:56:47 +01:00
|
|
|
uint32 max_display_length() { return field_length; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
class Field_decimal :public Field_real {
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
|
|
|
Field_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2005-02-08 23:50:45 +01:00
|
|
|
dec_arg, zero_arg, unsigned_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_DECIMAL;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const
|
2002-12-11 08:17:51 +01:00
|
|
|
{ return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void);
|
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
/* New decimal/numeric field which use fixed point arithmetic */
|
|
|
|
class Field_new_decimal :public Field_num {
|
|
|
|
public:
|
2005-05-05 17:06:49 +02:00
|
|
|
/* The maximum number of decimal digits can be stored */
|
|
|
|
uint precision;
|
2005-02-08 23:50:45 +01:00
|
|
|
uint bin_size;
|
2005-05-25 17:33:32 +02:00
|
|
|
/*
|
|
|
|
Constructors take max_length of the field as a parameter - not the
|
|
|
|
precision as the number of decimal digits allowed.
|
|
|
|
So for example we need to count length from precision handling
|
|
|
|
CREATE TABLE ( DECIMAL(x,y))
|
|
|
|
*/
|
2005-02-08 23:50:45 +01:00
|
|
|
Field_new_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,
|
|
|
|
uint8 dec_arg, bool zero_arg, bool unsigned_arg);
|
|
|
|
Field_new_decimal(uint32 len_arg, bool maybe_null_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
const char *field_name_arg, uint8 dec_arg,
|
2005-05-05 17:06:49 +02:00
|
|
|
bool unsigned_arg);
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_NEWDECIMAL;}
|
2005-02-08 23:50:45 +01:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
|
|
|
|
Item_result result_type () const { return DECIMAL_RESULT; }
|
2006-12-06 19:02:39 +01:00
|
|
|
int reset(void);
|
2005-02-08 23:50:45 +01:00
|
|
|
bool store_value(const my_decimal *decimal_value);
|
|
|
|
void set_value_on_overflow(my_decimal *decimal_value, bool sign);
|
|
|
|
int store(const char *to, uint length, CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2007-03-23 21:08:31 +01:00
|
|
|
int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
|
2005-02-08 23:50:45 +01:00
|
|
|
int store_decimal(const my_decimal *);
|
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
my_decimal *val_decimal(my_decimal *);
|
|
|
|
String *val_str(String*, String *);
|
|
|
|
int cmp(const char *, const char*);
|
|
|
|
void sort_string(char *buff, uint length);
|
|
|
|
bool zero_pack() const { return 0; }
|
|
|
|
void sql_type(String &str) const;
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return field_length; }
|
2005-02-08 23:50:45 +01:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
|
|
|
uint32 pack_length() const { return (uint32) bin_size; }
|
2006-06-27 10:02:02 +02:00
|
|
|
uint is_equal(create_field *new_field);
|
2005-02-08 23:50:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
class Field_tiny :public Field_num {
|
|
|
|
public:
|
|
|
|
Field_tiny(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
|
|
bool zero_arg, bool unsigned_arg)
|
|
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
0, zero_arg,unsigned_arg)
|
|
|
|
{}
|
|
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_TINY;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const
|
|
|
|
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return 4; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_short :public Field_num {
|
|
|
|
public:
|
|
|
|
Field_short(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
|
|
bool zero_arg, bool unsigned_arg)
|
|
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
0, zero_arg,unsigned_arg)
|
|
|
|
{}
|
2003-08-28 01:11:54 +02:00
|
|
|
Field_short(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
bool unsigned_arg)
|
2003-08-28 01:11:54 +02:00
|
|
|
:Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg, 0, 0, unsigned_arg)
|
2003-08-28 01:11:54 +02:00
|
|
|
{}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_SHORT;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const
|
|
|
|
{ return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=ptr[1]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return 6; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_medium :public Field_num {
|
|
|
|
public:
|
|
|
|
Field_medium(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
|
|
bool zero_arg, bool unsigned_arg)
|
|
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
0, zero_arg,unsigned_arg)
|
|
|
|
{}
|
|
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_INT24;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const
|
|
|
|
{ return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return 8; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_long :public Field_num {
|
|
|
|
public:
|
|
|
|
Field_long(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
|
|
bool zero_arg, bool unsigned_arg)
|
|
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
0, zero_arg,unsigned_arg)
|
|
|
|
{}
|
|
|
|
Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
bool unsigned_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg,0,0,unsigned_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
|
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_LONG;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const
|
|
|
|
{ return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return 11; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LONG_LONG
|
|
|
|
class Field_longlong :public Field_num {
|
|
|
|
public:
|
|
|
|
Field_longlong(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
|
|
bool zero_arg, bool unsigned_arg)
|
|
|
|
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
0, zero_arg,unsigned_arg)
|
|
|
|
{}
|
2001-09-27 20:45:48 +02:00
|
|
|
Field_longlong(uint32 len_arg,bool maybe_null_arg,
|
|
|
|
const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
bool unsigned_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg,0,0,unsigned_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
|
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_LONGLONG;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const
|
|
|
|
{ return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void)
|
|
|
|
{
|
|
|
|
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2004-09-28 13:29:38 +02:00
|
|
|
bool can_be_compared_as_longlong() const { return TRUE; }
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return 20; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
|
|
|
|
class Field_float :public Field_real {
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
|
|
|
Field_float(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-02-08 23:50:45 +01:00
|
|
|
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
|
|
|
|
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2005-02-08 23:50:45 +01:00
|
|
|
dec_arg, zero_arg, unsigned_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2003-08-28 01:11:54 +02:00
|
|
|
Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
uint8 dec_arg)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg, dec_arg, 0, 0)
|
2003-08-28 01:11:54 +02:00
|
|
|
{}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_FLOAT;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { bzero(ptr,sizeof(float)); return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
class Field_double :public Field_real {
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
2007-01-31 06:51:05 +01:00
|
|
|
my_bool not_fixed;
|
2000-07-31 21:29:14 +02:00
|
|
|
Field_double(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg,
|
2007-01-31 07:07:56 +01:00
|
|
|
dec_arg, zero_arg, unsigned_arg),
|
2007-01-31 06:51:05 +01:00
|
|
|
not_fixed(dec_arg >= NOT_FIXED_DEC)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
|
|
|
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
uint8 dec_arg)
|
2007-01-31 07:07:56 +01:00
|
|
|
:Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
|
2007-01-31 09:53:36 +01:00
|
|
|
NONE, field_name_arg, dec_arg, 0, 0),
|
2007-01-31 06:51:05 +01:00
|
|
|
not_fixed(dec_arg >= NOT_FIXED_DEC)
|
|
|
|
{}
|
|
|
|
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
|
2007-01-31 09:53:36 +01:00
|
|
|
uint8 dec_arg, my_bool not_fixed_srg)
|
2007-01-31 07:07:56 +01:00
|
|
|
:Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
|
2007-01-31 09:53:36 +01:00
|
|
|
NONE, field_name_arg, dec_arg, 0, 0),
|
|
|
|
not_fixed(not_fixed_srg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_DOUBLE;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { bzero(ptr,sizeof(double)); return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2007-02-23 12:13:55 +01:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
/* Everything saved in this will disappear. It will always return NULL */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
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,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_str(ptr_arg, len_arg, null, 1,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_NULL;}
|
2003-12-15 16:58:15 +01:00
|
|
|
int store(const char *to, uint length, CHARSET_INFO *cs)
|
|
|
|
{ null[0]=1; return 0; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(double nr) { null[0]=1; return 0; }
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; }
|
|
|
|
int store_decimal(const my_decimal *d) { null[0]=1; return 0; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void) { return 0.0;}
|
|
|
|
longlong val_int(void) { return 0;}
|
2005-02-08 23:50:45 +01:00
|
|
|
my_decimal *val_decimal(my_decimal *) { return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
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; }
|
2002-12-17 08:25:27 +01:00
|
|
|
void sql_type(String &str) const;
|
2000-07-31 21:29:14 +02:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return 4; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-12-14 16:43:01 +01:00
|
|
|
class Field_timestamp :public Field_str {
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
|
|
|
Field_timestamp(char *ptr_arg, uint32 len_arg,
|
2004-10-01 16:54:06 +02:00
|
|
|
uchar *null_ptr_arg, uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE *share, CHARSET_INFO *cs);
|
2006-07-22 00:08:00 +02:00
|
|
|
Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
|
2006-08-01 06:49:43 +02:00
|
|
|
CHARSET_INFO *cs);
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
|
2002-12-14 16:43:01 +01:00
|
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2004-09-28 13:29:38 +02:00
|
|
|
bool can_be_compared_as_longlong() const { return TRUE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
bool zero_pack() const { return 0; }
|
|
|
|
void set_time();
|
2002-07-25 00:00:56 +02:00
|
|
|
virtual void set_default()
|
|
|
|
{
|
2004-04-02 08:12:53 +02:00
|
|
|
if (table->timestamp_field == this &&
|
|
|
|
unireg_check != TIMESTAMP_UN_FIELD)
|
2004-01-30 13:13:19 +01:00
|
|
|
set_time();
|
|
|
|
else
|
|
|
|
Field::set_default();
|
2002-07-25 00:00:56 +02:00
|
|
|
}
|
2004-10-01 16:54:06 +02:00
|
|
|
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
|
|
|
|
inline long get_timestamp(my_bool *null_value)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-10-01 16:54:06 +02:00
|
|
|
if ((*null_value= is_null()))
|
|
|
|
return 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2006-06-20 23:14:53 +02:00
|
|
|
if (table && table->s->db_low_byte_first)
|
2000-07-31 21:29:14 +02:00
|
|
|
return sint4korr(ptr);
|
|
|
|
#endif
|
|
|
|
long tmp;
|
|
|
|
longget(tmp,ptr);
|
|
|
|
return tmp;
|
|
|
|
}
|
2007-03-23 21:08:31 +01:00
|
|
|
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
|
|
|
|
bool get_time(MYSQL_TIME *ltime);
|
2004-10-01 16:54:06 +02:00
|
|
|
timestamp_auto_set_type get_auto_set_type() const;
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_year :public Field_tiny {
|
|
|
|
public:
|
|
|
|
Field_year(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, 1, 1)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_YEAR;}
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
void sql_type(String &str) const;
|
2004-09-28 13:29:38 +02:00
|
|
|
bool can_be_compared_as_longlong() const { return TRUE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_date :public Field_str {
|
|
|
|
public:
|
2001-12-05 12:03:00 +01:00
|
|
|
Field_date(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2001-12-29 14:15:51 +01:00
|
|
|
Field_date(bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2001-12-29 14:15:51 +01:00
|
|
|
:Field_str((char*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg, cs) {}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_DATE;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
|
|
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2004-09-28 13:29:38 +02:00
|
|
|
bool can_be_compared_as_longlong() const { return TRUE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
bool zero_pack() const { return 1; }
|
|
|
|
};
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
class Field_newdate :public Field_str {
|
|
|
|
public:
|
2001-12-05 12:03:00 +01:00
|
|
|
Field_newdate(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_DATE;}
|
|
|
|
enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
|
|
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2007-03-23 21:08:31 +01:00
|
|
|
int store_time(MYSQL_TIME *ltime, timestamp_type type);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2004-09-28 13:29:38 +02:00
|
|
|
bool can_be_compared_as_longlong() const { return TRUE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
bool zero_pack() const { return 1; }
|
2007-03-23 21:08:31 +01:00
|
|
|
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
|
|
|
|
bool get_time(MYSQL_TIME *ltime);
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_time :public Field_str {
|
|
|
|
public:
|
2001-12-05 12:03:00 +01:00
|
|
|
Field_time(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2001-12-29 14:15:51 +01:00
|
|
|
Field_time(bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2001-12-29 14:15:51 +01:00
|
|
|
:Field_str((char*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg, cs) {}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_TIME;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
|
|
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
2007-03-23 21:08:31 +01:00
|
|
|
int store_time(MYSQL_TIME *ltime, timestamp_type type);
|
2006-12-06 18:45:57 +01:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2007-03-23 21:08:31 +01:00
|
|
|
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2007-03-23 21:08:31 +01:00
|
|
|
bool get_time(MYSQL_TIME *ltime);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2004-09-28 13:29:38 +02:00
|
|
|
bool can_be_compared_as_longlong() const { return TRUE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
bool zero_pack() const { return 1; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_datetime :public Field_str {
|
|
|
|
public:
|
2001-12-05 12:03:00 +01:00
|
|
|
Field_datetime(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{}
|
2001-12-29 14:15:51 +01:00
|
|
|
Field_datetime(bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2001-12-29 14:15:51 +01:00
|
|
|
:Field_str((char*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg, cs) {}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_DATETIME;}
|
2000-07-31 21:29:14 +02:00
|
|
|
#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; }
|
2005-06-20 19:49:04 +02:00
|
|
|
uint decimals() const { return DATETIME_DEC; }
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2007-03-23 21:08:31 +01:00
|
|
|
int store_time(MYSQL_TIME *ltime, timestamp_type type);
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void)
|
|
|
|
{
|
|
|
|
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2002-12-11 08:17:51 +01:00
|
|
|
bool send_binary(Protocol *protocol);
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2004-09-28 13:29:38 +02:00
|
|
|
bool can_be_compared_as_longlong() const { return TRUE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
bool zero_pack() const { return 1; }
|
2007-03-23 21:08:31 +01:00
|
|
|
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
|
|
|
|
bool get_time(MYSQL_TIME *ltime);
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
class Field_string :public Field_longstr {
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
2006-04-05 11:29:04 +02:00
|
|
|
bool can_alter_field_type;
|
2000-07-31 21:29:14 +02:00
|
|
|
Field_string(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2006-04-05 18:12:26 +02:00
|
|
|
unireg_check_arg, field_name_arg, cs),
|
2006-04-05 11:29:04 +02:00
|
|
|
can_alter_field_type(1) {};
|
2000-07-31 21:29:14 +02:00
|
|
|
Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_longstr((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
|
2006-04-05 18:12:26 +02:00
|
|
|
NONE, field_name_arg, cs),
|
2006-04-05 11:29:04 +02:00
|
|
|
can_alter_field_type(1) {};
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
enum_field_types type() const
|
|
|
|
{
|
2006-04-05 11:29:04 +02:00
|
|
|
return ((can_alter_field_type && orig_table &&
|
2005-02-04 21:01:30 +01:00
|
|
|
orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
|
|
|
|
field_length >= 4) &&
|
|
|
|
orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
|
|
|
|
MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
enum ha_base_keytype key_type() const
|
2002-10-25 10:58:32 +02:00
|
|
|
{ return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
|
2000-07-31 21:29:14 +02:00
|
|
|
bool zero_pack() const { return 0; }
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void)
|
|
|
|
{
|
2007-01-09 20:35:30 +01:00
|
|
|
charset()->cset->fill(charset(),ptr,field_length,
|
|
|
|
(has_charset() ? ' ' : 0));
|
2006-12-06 18:45:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
2006-12-06 19:02:39 +01:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2004-08-31 13:35:04 +02:00
|
|
|
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2005-06-15 17:27:33 +02:00
|
|
|
my_decimal *val_decimal(my_decimal *);
|
2000-07-31 21:29:14 +02:00
|
|
|
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);
|
2005-02-04 21:01:30 +01:00
|
|
|
int pack_cmp(const char *a,const char *b,uint key_length,
|
|
|
|
my_bool insert_or_update);
|
|
|
|
int pack_cmp(const char *b,uint key_length,my_bool insert_or_update);
|
2001-11-03 14:18:09 +01:00
|
|
|
uint packed_col_length(const char *to, uint length);
|
2000-07-31 21:29:14 +02:00
|
|
|
uint max_packed_col_length(uint max_length);
|
|
|
|
uint size_of() const { return sizeof(*this); }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types real_type() const { return MYSQL_TYPE_STRING; }
|
2004-03-26 13:11:46 +01:00
|
|
|
bool has_charset(void) const
|
|
|
|
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
|
2006-06-26 20:57:18 +02:00
|
|
|
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
|
2007-04-29 05:51:51 +02:00
|
|
|
virtual uint get_key_image(char *buff,uint length, imagetype type);
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
class Field_varstring :public Field_longstr {
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
2005-02-04 21:01:30 +01:00
|
|
|
/* Store number of bytes used to store length (1 or 2) */
|
|
|
|
uint32 length_bytes;
|
|
|
|
Field_varstring(char *ptr_arg,
|
|
|
|
uint32 len_arg, uint length_bytes_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
uchar *null_ptr_arg, uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE *share, CHARSET_INFO *cs)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, cs),
|
2005-02-08 23:50:45 +01:00
|
|
|
length_bytes(length_bytes_arg)
|
2005-02-04 21:01:30 +01:00
|
|
|
{
|
2005-11-23 21:45:02 +01:00
|
|
|
share->varchar_fields++;
|
2005-02-04 21:01:30 +01:00
|
|
|
}
|
2003-12-19 15:25:50 +01:00
|
|
|
Field_varstring(uint32 len_arg,bool maybe_null_arg,
|
2005-02-08 23:50:45 +01:00
|
|
|
const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE *share, CHARSET_INFO *cs)
|
2005-02-08 23:50:45 +01:00
|
|
|
:Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
|
2005-11-23 21:45:02 +01:00
|
|
|
NONE, field_name_arg, cs),
|
2005-02-08 23:50:45 +01:00
|
|
|
length_bytes(len_arg < 256 ? 1 :2)
|
2005-02-04 21:01:30 +01:00
|
|
|
{
|
2005-11-23 21:45:02 +01:00
|
|
|
share->varchar_fields++;
|
2005-02-04 21:01:30 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-02-04 21:01:30 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
|
|
|
|
enum ha_base_keytype key_type() const;
|
2000-07-31 21:29:14 +02:00
|
|
|
bool zero_pack() const { return 0; }
|
2006-12-06 19:02:39 +01:00
|
|
|
int reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
|
2005-02-04 21:01:30 +01:00
|
|
|
uint32 pack_length() const { return (uint32) field_length+length_bytes; }
|
2000-07-31 21:29:14 +02:00
|
|
|
uint32 key_length() const { return (uint32) field_length; }
|
2005-10-13 23:04:52 +02:00
|
|
|
uint32 sort_length() const
|
|
|
|
{
|
|
|
|
return (uint32) field_length + (field_charset == &my_charset_bin ?
|
|
|
|
length_bytes : 0);
|
|
|
|
}
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2004-08-31 13:35:04 +02:00
|
|
|
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2005-06-15 17:27:33 +02:00
|
|
|
my_decimal *val_decimal(my_decimal *);
|
2005-07-18 13:31:02 +02:00
|
|
|
int cmp_max(const char *, const char *, uint max_length);
|
|
|
|
int cmp(const char *a,const char*b)
|
|
|
|
{
|
2005-11-10 18:43:17 +01:00
|
|
|
return cmp_max(a, b, ~0L);
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
void sort_string(char *buff,uint length);
|
2007-04-29 05:51:51 +02:00
|
|
|
uint get_key_image(char *buff,uint length, imagetype type);
|
2005-02-04 21:01:30 +01:00
|
|
|
void set_key_image(char *buff,uint length);
|
2000-07-31 21:29:14 +02:00
|
|
|
void sql_type(String &str) const;
|
|
|
|
char *pack(char *to, const char *from, uint max_length=~(uint) 0);
|
2004-08-24 15:32:57 +02:00
|
|
|
char *pack_key(char *to, const char *from, uint max_length);
|
2005-02-04 21:01:30 +01:00
|
|
|
char *pack_key_from_key_image(char* to, const char *from, uint max_length);
|
2000-07-31 21:29:14 +02:00
|
|
|
const char *unpack(char* to, const char *from);
|
2005-02-04 21:01:30 +01:00
|
|
|
const char *unpack_key(char* to, const char *from, uint max_length);
|
|
|
|
int pack_cmp(const char *a, const char *b, uint key_length,
|
|
|
|
my_bool insert_or_update);
|
|
|
|
int pack_cmp(const char *b, uint key_length,my_bool insert_or_update);
|
|
|
|
int cmp_binary(const char *a,const char *b, uint32 max_length=~0L);
|
|
|
|
int key_cmp(const byte *,const byte*);
|
|
|
|
int key_cmp(const byte *str, uint length);
|
2001-11-03 14:18:09 +01:00
|
|
|
uint packed_col_length(const char *to, uint length);
|
2000-07-31 21:29:14 +02:00
|
|
|
uint max_packed_col_length(uint max_length);
|
2006-11-16 02:55:17 +01:00
|
|
|
uint32 data_length();
|
2000-07-31 21:29:14 +02:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
2005-02-04 21:01:30 +01:00
|
|
|
enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
|
2004-03-26 13:11:46 +01:00
|
|
|
bool has_charset(void) const
|
|
|
|
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
|
2006-06-26 20:57:18 +02:00
|
|
|
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
|
2005-02-04 21:01:30 +01:00
|
|
|
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
|
|
|
|
char *new_ptr, uchar *new_null_ptr,
|
|
|
|
uint new_null_bit);
|
2005-07-22 22:43:59 +02:00
|
|
|
uint is_equal(create_field *new_field);
|
2006-06-21 10:00:19 +02:00
|
|
|
void hash(ulong *nr, ulong *nr2);
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
class Field_blob :public Field_longstr {
|
2003-03-18 12:30:32 +01:00
|
|
|
protected:
|
2000-07-31 21:29:14 +02:00
|
|
|
uint packlength;
|
2002-08-02 14:05:10 +02:00
|
|
|
String value; // For temporaries
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
2001-12-05 12:03:00 +01:00
|
|
|
Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
|
2000-07-31 21:29:14 +02:00
|
|
|
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
CHARSET_INFO *cs)
|
|
|
|
:Field_longstr((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
|
|
|
|
NONE, field_name_arg, cs),
|
2004-01-15 18:06:22 +01:00
|
|
|
packlength(4)
|
2003-12-19 15:25:50 +01:00
|
|
|
{
|
|
|
|
flags|= BLOB_FLAG;
|
|
|
|
}
|
2006-07-22 00:08:00 +02:00
|
|
|
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
2006-08-01 06:49:43 +02:00
|
|
|
CHARSET_INFO *cs, bool set_packlength)
|
2006-07-22 00:08:00 +02:00
|
|
|
:Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
|
2006-08-01 06:49:43 +02:00
|
|
|
NONE, field_name_arg, cs)
|
2006-07-22 00:08:00 +02:00
|
|
|
{
|
|
|
|
flags|= BLOB_FLAG;
|
|
|
|
packlength= 4;
|
|
|
|
if (set_packlength)
|
|
|
|
{
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 l_char_length= len_arg/cs->mbmaxlen;
|
|
|
|
packlength= l_char_length <= 255 ? 1 :
|
|
|
|
l_char_length <= 65535 ? 2 :
|
|
|
|
l_char_length <= 16777215 ? 3 : 4;
|
2006-07-22 00:08:00 +02:00
|
|
|
}
|
|
|
|
}
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_BLOB;}
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const
|
2005-02-04 21:01:30 +01:00
|
|
|
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2000-07-31 21:29:14 +02:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*,String *);
|
2005-06-15 17:27:33 +02:00
|
|
|
my_decimal *val_decimal(my_decimal *);
|
2005-07-18 13:31:02 +02:00
|
|
|
int cmp_max(const char *, const char *, uint max_length);
|
|
|
|
int cmp(const char *a,const char*b)
|
2005-11-10 18:43:17 +01:00
|
|
|
{ return cmp_max(a, b, ~0L); }
|
2001-12-05 12:03:00 +01:00
|
|
|
int cmp(const char *a, uint32 a_length, const char *b, uint32 b_length);
|
|
|
|
int cmp_binary(const char *a,const char *b, uint32 max_length=~0L);
|
2000-07-31 21:29:14 +02:00
|
|
|
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);
|
2001-12-05 12:03:00 +01:00
|
|
|
uint32 pack_length() const
|
2005-02-04 21:01:30 +01:00
|
|
|
{ return (uint32) (packlength+table->s->blob_ptr_size); }
|
2005-10-13 23:04:52 +02:00
|
|
|
uint32 sort_length() const;
|
2004-02-17 00:35:17 +01:00
|
|
|
inline uint32 max_data_length() const
|
2004-02-10 12:42:46 +01:00
|
|
|
{
|
2004-02-17 00:35:17 +01:00
|
|
|
return (uint32) (((ulonglong) 1 << (packlength*8)) -1);
|
2004-02-10 12:42:46 +01:00
|
|
|
}
|
2006-12-06 18:45:57 +01:00
|
|
|
int reset(void) { bzero(ptr, packlength+sizeof(char*)); return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
void reset_fields() { bzero((char*) &value,sizeof(value)); }
|
2007-04-19 18:43:42 +02:00
|
|
|
static void store_length(char *ptr, uint packlength, uint32 number);
|
|
|
|
inline void store_length(uint32 number)
|
|
|
|
{
|
|
|
|
store_length(ptr, packlength, number);
|
|
|
|
}
|
|
|
|
|
2001-12-05 12:03:00 +01:00
|
|
|
inline uint32 get_length(uint row_offset=0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{ return get_length(ptr+row_offset); }
|
2001-12-05 12:03:00 +01:00
|
|
|
uint32 get_length(const char *ptr);
|
2004-06-24 14:54:28 +02:00
|
|
|
void put_length(char *pos, uint32 length);
|
2000-07-31 21:29:14 +02:00
|
|
|
inline void get_ptr(char **str)
|
|
|
|
{
|
|
|
|
memcpy_fixed(str,ptr+packlength,sizeof(char*));
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
inline void get_ptr(char **str, uint row_offset)
|
|
|
|
{
|
|
|
|
memcpy_fixed(str,ptr+packlength+row_offset,sizeof(char*));
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
inline void set_ptr(char *length,char *data)
|
|
|
|
{
|
|
|
|
memcpy(ptr,length,packlength);
|
|
|
|
memcpy_fixed(ptr+packlength,&data,sizeof(char*));
|
|
|
|
}
|
2007-04-19 18:43:42 +02:00
|
|
|
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length,char *data)
|
|
|
|
{
|
|
|
|
char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,char*);
|
|
|
|
store_length(ptr_ofs, packlength, length);
|
|
|
|
memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*));
|
|
|
|
}
|
2001-12-05 12:03:00 +01:00
|
|
|
inline void set_ptr(uint32 length,char *data)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2007-04-19 18:43:42 +02:00
|
|
|
set_ptr_offset(0, length, data);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2007-04-29 05:51:51 +02:00
|
|
|
uint get_key_image(char *buff,uint length, imagetype type);
|
2005-02-04 21:01:30 +01:00
|
|
|
void set_key_image(char *buff,uint length);
|
2000-07-31 21:29:14 +02:00
|
|
|
void sql_type(String &str) const;
|
|
|
|
inline bool copy()
|
|
|
|
{ char *tmp;
|
|
|
|
get_ptr(&tmp);
|
2002-11-06 14:43:22 +01:00
|
|
|
if (value.copy(tmp,get_length(),charset()))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
Field_blob::reset();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
tmp=(char*) value.ptr(); memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
|
|
|
|
return 0;
|
|
|
|
}
|
2001-01-17 02:15:20 +01:00
|
|
|
char *pack(char *to, const char *from, uint max_length= ~(uint) 0);
|
|
|
|
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);
|
2005-02-04 21:01:30 +01:00
|
|
|
const char *unpack(char *to, const char *from);
|
2004-06-24 14:54:28 +02:00
|
|
|
const char *unpack_key(char* to, const char *from, uint max_length);
|
2005-02-04 21:01:30 +01:00
|
|
|
int pack_cmp(const char *a, const char *b, uint key_length,
|
|
|
|
my_bool insert_or_update);
|
|
|
|
int pack_cmp(const char *b, uint key_length,my_bool insert_or_update);
|
2001-11-03 14:18:09 +01:00
|
|
|
uint packed_col_length(const char *col_ptr, uint length);
|
|
|
|
uint max_packed_col_length(uint max_length);
|
2003-06-13 23:00:04 +02:00
|
|
|
void free() { value.free(); }
|
2000-07-31 21:29:14 +02:00
|
|
|
inline void clear_temporary() { bzero((char*) &value,sizeof(value)); }
|
2007-02-06 10:08:57 +01:00
|
|
|
friend int field_conv(Field *to,Field *from);
|
2000-07-31 21:29:14 +02:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
2003-06-13 23:00:04 +02:00
|
|
|
bool has_charset(void) const
|
2003-05-23 10:10:25 +02:00
|
|
|
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length();
|
2007-04-27 12:21:23 +02:00
|
|
|
uint is_equal(create_field *new_field);
|
2005-02-15 15:45:00 +01:00
|
|
|
};
|
|
|
|
|
2005-02-04 21:01:30 +01:00
|
|
|
|
2004-01-15 18:06:22 +01:00
|
|
|
#ifdef HAVE_SPATIAL
|
2002-02-22 12:24:42 +01:00
|
|
|
class Field_geom :public Field_blob {
|
|
|
|
public:
|
2003-03-27 10:09:09 +01:00
|
|
|
enum geometry_type geom_type;
|
2003-06-13 23:00:04 +02:00
|
|
|
|
2002-02-22 12:24:42 +01:00
|
|
|
Field_geom(char *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
|
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE *share, uint blob_pack_length,
|
2003-03-27 10:09:09 +01:00
|
|
|
enum geometry_type geom_type_arg)
|
2002-02-22 12:24:42 +01:00
|
|
|
:Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
field_name_arg, share, blob_pack_length, &my_charset_bin)
|
2003-03-27 10:09:09 +01:00
|
|
|
{ geom_type= geom_type_arg; }
|
2002-02-22 12:24:42 +01:00
|
|
|
Field_geom(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE *share, enum geometry_type geom_type_arg)
|
|
|
|
:Field_blob(len_arg, maybe_null_arg, field_name_arg, &my_charset_bin)
|
2003-03-27 10:09:09 +01:00
|
|
|
{ geom_type= geom_type_arg; }
|
2005-02-04 21:01:30 +01:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY2; }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_GEOMETRY; }
|
2002-10-04 09:48:32 +02:00
|
|
|
void sql_type(String &str) const;
|
2003-03-18 12:30:32 +01:00
|
|
|
int store(const char *to, uint length, CHARSET_INFO *charset);
|
2005-04-29 17:23:02 +02:00
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2005-04-29 17:23:02 +02:00
|
|
|
int store_decimal(const my_decimal *);
|
2007-04-29 05:51:51 +02:00
|
|
|
uint get_key_image(char *buff,uint length,imagetype type);
|
2005-08-05 17:19:51 +02:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
2007-03-26 12:17:40 +02:00
|
|
|
int reset(void) { return !maybe_null() || Field_blob::reset(); }
|
2002-02-22 12:24:42 +01:00
|
|
|
};
|
2004-01-15 18:06:22 +01:00
|
|
|
#endif /*HAVE_SPATIAL*/
|
2002-02-22 12:24:42 +01:00
|
|
|
|
2005-02-04 21:01:30 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
class Field_enum :public Field_str {
|
|
|
|
protected:
|
|
|
|
uint packlength;
|
|
|
|
public:
|
|
|
|
TYPELIB *typelib;
|
|
|
|
Field_enum(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
uchar null_bit_arg,
|
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
|
|
|
uint packlength_arg,
|
|
|
|
TYPELIB *typelib_arg,
|
|
|
|
CHARSET_INFO *charset_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
unireg_check_arg, field_name_arg, charset_arg),
|
2000-07-31 21:29:14 +02:00
|
|
|
packlength(packlength_arg),typelib(typelib_arg)
|
2002-06-12 14:04:18 +02:00
|
|
|
{
|
2000-07-31 21:29:14 +02:00
|
|
|
flags|=ENUM_FLAG;
|
2002-06-12 14:04:18 +02:00
|
|
|
}
|
2006-12-14 18:58:07 +01:00
|
|
|
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_STRING; }
|
2000-07-31 21:29:14 +02:00
|
|
|
enum Item_result cmp_type () const { return INT_RESULT; }
|
2005-04-29 16:03:34 +02:00
|
|
|
enum Item_result cast_to_int_type () const { return INT_RESULT; }
|
2000-07-31 21:29:14 +02:00
|
|
|
enum ha_base_keytype key_type() const;
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2000-07-31 21:29:14 +02:00
|
|
|
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); }
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual bool zero_pack() const { return 0; }
|
2004-07-08 14:45:25 +02:00
|
|
|
bool optimize_range(uint idx, uint part) { return 0; }
|
2000-07-31 21:29:14 +02:00
|
|
|
bool eq_def(Field *field);
|
2003-05-23 10:10:25 +02:00
|
|
|
bool has_charset(void) const { return TRUE; }
|
2005-02-28 10:59:46 +01:00
|
|
|
/* enum and set are sorted as integers */
|
|
|
|
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Field_set :public Field_enum {
|
|
|
|
public:
|
|
|
|
Field_set(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar null_bit_arg,
|
2000-07-31 21:29:14 +02:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
uint32 packlength_arg,
|
2002-10-25 12:08:47 +02:00
|
|
|
TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
:Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
|
|
|
|
unireg_check_arg, field_name_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
packlength_arg,
|
|
|
|
typelib_arg,charset_arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
flags=(flags & ~ENUM_FLAG) | SET_FLAG;
|
|
|
|
}
|
2002-08-24 13:49:04 +02:00
|
|
|
int store(const char *to,uint length,CHARSET_INFO *charset);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(double nr) { return Field_set::store((longlong) nr, FALSE); }
|
|
|
|
int store(longlong nr, bool unsigned_val);
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual bool zero_pack() const { return 1; }
|
|
|
|
String *val_str(String*,String *);
|
|
|
|
void sql_type(String &str) const;
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types real_type() const { return MYSQL_TYPE_SET; }
|
2003-05-23 10:10:25 +02:00
|
|
|
bool has_charset(void) const { return TRUE; }
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-02-24 15:38:20 +01:00
|
|
|
/*
|
|
|
|
Note:
|
|
|
|
To use Field_bit::cmp_binary() you need to copy the bits stored in
|
|
|
|
the beginning of the record (the NULL bytes) to each memory you
|
|
|
|
want to compare (where the arguments point).
|
|
|
|
|
|
|
|
This is the reason:
|
|
|
|
- Field_bit::cmp_binary() is only implemented in the base class
|
|
|
|
(Field::cmp_binary()).
|
|
|
|
- Field::cmp_binary() currenly use pack_length() to calculate how
|
|
|
|
long the data is.
|
|
|
|
- pack_length() includes size of the bits stored in the NULL bytes
|
|
|
|
of the record.
|
|
|
|
*/
|
2005-02-04 21:01:30 +01:00
|
|
|
class Field_bit :public Field {
|
|
|
|
public:
|
|
|
|
uchar *bit_ptr; // position in record where 'uneven' bits store
|
|
|
|
uchar bit_ofs; // offset to 'uneven' high bits
|
|
|
|
uint bit_len; // number of 'uneven' high bits
|
2006-04-05 02:54:58 +02:00
|
|
|
uint bytes_in_rec;
|
2005-02-04 21:01:30 +01:00
|
|
|
Field_bit(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
|
|
|
uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg);
|
2006-12-02 02:26:52 +01:00
|
|
|
enum_field_types type() const { return MYSQL_TYPE_BIT; }
|
2005-02-04 21:01:30 +01:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
|
2006-04-05 02:54:58 +02:00
|
|
|
uint32 key_length() const { return (uint32) (field_length + 7) / 8; }
|
2006-12-14 23:51:37 +01:00
|
|
|
uint32 max_display_length() { return field_length; }
|
2005-02-04 21:01:30 +01:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
|
|
|
Item_result result_type () const { return INT_RESULT; }
|
2006-12-06 19:02:39 +01:00
|
|
|
int reset(void) { bzero(ptr, bytes_in_rec); return 0; }
|
2005-02-04 21:01:30 +01:00
|
|
|
int store(const char *to, uint length, CHARSET_INFO *charset);
|
|
|
|
int store(double nr);
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val);
|
2005-02-08 23:50:45 +01:00
|
|
|
int store_decimal(const my_decimal *);
|
2005-02-04 21:01:30 +01:00
|
|
|
double val_real(void);
|
|
|
|
longlong val_int(void);
|
|
|
|
String *val_str(String*, String *);
|
2006-07-26 01:12:48 +02:00
|
|
|
virtual bool str_needs_quotes() { return TRUE; }
|
2005-02-08 23:50:45 +01:00
|
|
|
my_decimal *val_decimal(my_decimal *);
|
2005-02-04 21:01:30 +01:00
|
|
|
int cmp(const char *a, const char *b)
|
|
|
|
{ return cmp_binary(a, b); }
|
2006-02-24 15:38:20 +01:00
|
|
|
int cmp_binary_offset(uint row_offset)
|
|
|
|
{ return cmp_offset(row_offset); }
|
2005-07-18 13:31:02 +02:00
|
|
|
int cmp_max(const char *a, const char *b, uint max_length);
|
2005-02-04 21:01:30 +01:00
|
|
|
int key_cmp(const byte *a, const byte *b)
|
|
|
|
{ return cmp_binary((char *) a, (char *) b); }
|
|
|
|
int key_cmp(const byte *str, uint length);
|
|
|
|
int cmp_offset(uint row_offset);
|
2007-04-29 05:51:51 +02:00
|
|
|
uint get_key_image(char *buff, uint length, imagetype type);
|
2005-02-04 21:01:30 +01:00
|
|
|
void set_key_image(char *buff, uint length)
|
|
|
|
{ Field_bit::store(buff, length, &my_charset_bin); }
|
|
|
|
void sort_string(char *buff, uint length)
|
|
|
|
{ get_key_image(buff, length, itRAW); }
|
2006-04-05 02:54:58 +02:00
|
|
|
uint32 pack_length() const { return (uint32) (field_length + 7) / 8; }
|
|
|
|
uint32 pack_length_in_rec() const { return bytes_in_rec; }
|
2005-02-04 21:01:30 +01:00
|
|
|
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);
|
2006-05-03 15:00:38 +02:00
|
|
|
virtual void set_default();
|
|
|
|
|
2005-02-04 21:01:30 +01:00
|
|
|
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
|
|
|
|
char *new_ptr, uchar *new_null_ptr,
|
|
|
|
uint new_null_bit);
|
2005-06-30 10:38:29 +02:00
|
|
|
void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
|
|
|
|
{
|
|
|
|
bit_ptr= bit_ptr_arg;
|
|
|
|
bit_ofs= bit_ofs_arg;
|
|
|
|
}
|
2006-06-14 14:57:23 +02:00
|
|
|
bool eq(Field *field)
|
|
|
|
{
|
|
|
|
return (Field::eq(field) &&
|
|
|
|
field->type() == type() &&
|
|
|
|
bit_ptr == ((Field_bit *)field)->bit_ptr &&
|
|
|
|
bit_ofs == ((Field_bit *)field)->bit_ofs);
|
|
|
|
}
|
2005-11-23 21:45:02 +01:00
|
|
|
void move_field_offset(my_ptrdiff_t ptr_diff)
|
|
|
|
{
|
|
|
|
Field::move_field_offset(ptr_diff);
|
|
|
|
bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*);
|
|
|
|
}
|
2006-05-08 20:05:25 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual my_size_t do_last_null_byte() const;
|
2005-02-04 21:01:30 +01:00
|
|
|
};
|
|
|
|
|
2006-01-03 17:54:54 +01:00
|
|
|
|
2006-12-05 10:46:03 +01:00
|
|
|
/**
|
|
|
|
BIT field represented as chars for non-MyISAM tables.
|
|
|
|
|
|
|
|
@todo The inheritance relationship is backwards since Field_bit is
|
|
|
|
an extended version of Field_bit_as_char and not the other way
|
|
|
|
around. Hence, we should refactor it to fix the hierarchy order.
|
|
|
|
*/
|
2005-04-12 09:27:43 +02:00
|
|
|
class Field_bit_as_char: public Field_bit {
|
|
|
|
public:
|
|
|
|
Field_bit_as_char(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
|
2006-01-03 17:54:54 +01:00
|
|
|
uchar null_bit_arg,
|
2005-11-23 21:45:02 +01:00
|
|
|
enum utype unireg_check_arg, const char *field_name_arg);
|
2005-04-12 09:27:43 +02:00
|
|
|
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
|
2005-04-12 20:12:00 +02:00
|
|
|
uint size_of() const { return sizeof(*this); }
|
2005-04-12 09:27:43 +02:00
|
|
|
int store(const char *to, uint length, CHARSET_INFO *charset);
|
|
|
|
int store(double nr) { return Field_bit::store(nr); }
|
2005-09-14 00:41:44 +02:00
|
|
|
int store(longlong nr, bool unsigned_val)
|
|
|
|
{ return Field_bit::store(nr, unsigned_val); }
|
2005-04-12 09:27:43 +02:00
|
|
|
void sql_type(String &str) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*
|
2002-07-17 14:17:20 +02:00
|
|
|
Create field class for CREATE TABLE
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
2005-03-13 21:50:43 +01:00
|
|
|
class create_field :public Sql_alloc
|
|
|
|
{
|
2000-07-31 21:29:14 +02:00
|
|
|
public:
|
|
|
|
const char *field_name;
|
2002-08-02 14:05:10 +02:00
|
|
|
const char *change; // If done with alter table
|
|
|
|
const char *after; // Put column after this one
|
2002-08-30 11:40:40 +02:00
|
|
|
LEX_STRING comment; // Comment for field
|
2002-08-02 14:05:10 +02:00
|
|
|
Item *def; // Default value
|
2000-07-31 21:29:14 +02:00
|
|
|
enum enum_field_types sql_type;
|
2005-10-25 22:56:17 +02:00
|
|
|
/*
|
|
|
|
At various stages in execution this can be length of field in bytes or
|
|
|
|
max number of characters.
|
|
|
|
*/
|
2005-02-04 21:01:30 +01:00
|
|
|
ulong length;
|
2005-10-31 07:22:33 +01:00
|
|
|
/*
|
2006-02-23 22:00:15 +01:00
|
|
|
The value of `length' as set by parser: is the number of characters
|
|
|
|
for most of the types, or of bytes for BLOBs or numeric types.
|
2005-10-31 07:22:33 +01:00
|
|
|
*/
|
2006-02-21 17:52:20 +01:00
|
|
|
uint32 char_length;
|
2005-02-04 21:01:30 +01:00
|
|
|
uint decimals, flags, pack_length, key_length;
|
2000-07-31 21:29:14 +02:00
|
|
|
Field::utype unireg_check;
|
2002-08-02 14:05:10 +02:00
|
|
|
TYPELIB *interval; // Which interval to use
|
2006-09-20 18:46:12 +02:00
|
|
|
TYPELIB *save_interval; // Temporary copy for the above
|
|
|
|
// Used only for UCS2 intervals
|
2004-12-02 09:48:43 +01:00
|
|
|
List<String> interval_list;
|
2002-10-02 12:33:08 +02:00
|
|
|
CHARSET_INFO *charset;
|
2003-03-27 10:09:09 +01:00
|
|
|
Field::geometry_type geom_type;
|
2002-08-02 14:05:10 +02:00
|
|
|
Field *field; // For alter table
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-08-02 14:05:10 +02:00
|
|
|
uint8 row,col,sc_length,interval_id; // For rea_create_table
|
2000-07-31 21:29:14 +02:00
|
|
|
uint offset,pack_flag;
|
|
|
|
create_field() :after(0) {}
|
2000-10-14 02:16:35 +02:00
|
|
|
create_field(Field *field, Field *orig_field);
|
2003-08-11 15:18:34 +02:00
|
|
|
void create_length_to_internal_length(void);
|
2005-03-13 21:50:43 +01:00
|
|
|
|
|
|
|
/* Init for a tmp table field. To be extended if need be. */
|
|
|
|
void init_for_tmp_table(enum_field_types sql_type_arg,
|
|
|
|
uint32 max_length, uint32 decimals,
|
|
|
|
bool maybe_null, bool is_unsigned);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
bool init(THD *thd, char *field_name, enum_field_types type, char *length,
|
|
|
|
char *decimals, uint type_modifier, Item *default_value,
|
|
|
|
Item *on_update_value, LEX_STRING *comment, char *change,
|
|
|
|
List<String> *interval_list, CHARSET_INFO *cs,
|
|
|
|
uint uint_geom_type);
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2002-07-17 14:17:20 +02:00
|
|
|
A class for sending info to the client
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
class Send_field {
|
|
|
|
public:
|
2002-06-12 23:13:12 +02:00
|
|
|
const char *db_name;
|
|
|
|
const char *table_name,*org_table_name;
|
|
|
|
const char *col_name,*org_col_name;
|
2003-02-04 02:19:19 +01:00
|
|
|
ulong length;
|
|
|
|
uint charsetnr, flags, decimals;
|
2000-07-31 21:29:14 +02:00
|
|
|
enum_field_types type;
|
|
|
|
Send_field() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2002-08-02 14:05:10 +02:00
|
|
|
A class for quick copying data to fields
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2002-08-02 14:05:10 +02:00
|
|
|
String tmp; // For items
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
Copy_field() {}
|
|
|
|
~Copy_field() {}
|
2002-08-02 14:05:10 +02:00
|
|
|
void set(Field *to,Field *from,bool save); // Field to field
|
|
|
|
void set(char *to,Field *from); // Field to string
|
2000-07-31 21:29:14 +02:00
|
|
|
void (*do_copy)(Copy_field *);
|
2002-08-02 14:05:10 +02:00
|
|
|
void (*do_copy2)(Copy_field *); // Used to handle null values
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
Field *make_field(TABLE_SHARE *share, char *ptr, uint32 field_length,
|
2001-12-05 12:03:00 +01:00
|
|
|
uchar *null_pos, uchar null_bit,
|
2002-06-02 20:22:20 +02:00
|
|
|
uint pack_flag, enum_field_types field_type,
|
2002-10-25 10:58:32 +02:00
|
|
|
CHARSET_INFO *cs,
|
2003-03-27 10:09:09 +01:00
|
|
|
Field::geometry_type geom_type,
|
2002-06-02 20:22:20 +02:00
|
|
|
Field::utype unireg_check,
|
2005-11-23 21:45:02 +01:00
|
|
|
TYPELIB *interval, const char *field_name);
|
2000-07-31 21:29:14 +02:00
|
|
|
uint pack_length_to_packflag(uint type);
|
2005-02-04 21:01:30 +01:00
|
|
|
enum_field_types get_blob_type_from_length(ulong length);
|
2000-07-31 21:29:14 +02:00
|
|
|
uint32 calc_pack_length(enum_field_types type,uint32 length);
|
2004-03-16 11:59:22 +01:00
|
|
|
int set_field_to_null(Field *field);
|
|
|
|
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
/*
|
2002-08-02 14:05:10 +02:00
|
|
|
The following are for the interface with the .frm file
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define FIELDFLAG_DECIMAL 1
|
2003-07-28 16:58:52 +02:00
|
|
|
#define FIELDFLAG_BINARY 1 // Shares same flag
|
2000-07-31 21:29:14 +02:00
|
|
|
#define FIELDFLAG_NUMBER 2
|
|
|
|
#define FIELDFLAG_ZEROFILL 4
|
2002-08-02 14:05:10 +02:00
|
|
|
#define FIELDFLAG_PACK 120 // Bits used for packing
|
2005-01-18 15:04:16 +01:00
|
|
|
#define FIELDFLAG_INTERVAL 256 // mangled with decimals!
|
|
|
|
#define FIELDFLAG_BITFIELD 512 // mangled with decimals!
|
|
|
|
#define FIELDFLAG_BLOB 1024 // mangled with decimals!
|
|
|
|
#define FIELDFLAG_GEOM 2048 // mangled with decimals!
|
2002-02-22 12:24:42 +01:00
|
|
|
|
2005-04-12 09:27:43 +02:00
|
|
|
#define FIELDFLAG_TREAT_BIT_AS_CHAR 4096 /* use Field_bit_as_char */
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#define FIELDFLAG_LEFT_FULLSCREEN 8192
|
|
|
|
#define FIELDFLAG_RIGHT_FULLSCREEN 16384
|
2002-08-02 14:05:10 +02:00
|
|
|
#define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output
|
2005-02-04 21:01:30 +01:00
|
|
|
#define FIELDFLAG_NO_DEFAULT 16384 /* sql */
|
2002-08-02 14:05:10 +02:00
|
|
|
#define FIELDFLAG_SUM ((uint) 32768)// predit: +#fieldflag
|
|
|
|
#define FIELDFLAG_MAYBE_NULL ((uint) 32768)// sql
|
2000-07-31 21:29:14 +02:00
|
|
|
#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 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)
|
2001-12-05 12:03:00 +01:00
|
|
|
#define f_decimals(x) ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
|
2000-07-31 21:29:14 +02:00
|
|
|
#define f_is_alpha(x) (!f_is_num(x))
|
2003-07-28 16:58:52 +02:00
|
|
|
#define f_is_binary(x) ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
|
2005-01-18 15:04:16 +01:00
|
|
|
#define f_is_enum(x) (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
|
|
|
|
#define f_is_bitfield(x) (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
|
2000-07-31 21:29:14 +02:00
|
|
|
#define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
|
2005-01-18 15:04:16 +01:00
|
|
|
#define f_is_geom(x) (((x) & (FIELDFLAG_GEOM | FIELDFLAG_NUMBER)) == FIELDFLAG_GEOM)
|
2000-07-31 21:29:14 +02:00
|
|
|
#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)
|
2005-02-04 21:01:30 +01:00
|
|
|
#define f_no_default(x) (x & FIELDFLAG_NO_DEFAULT)
|
2005-04-12 09:27:43 +02:00
|
|
|
#define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
|