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 */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Functions to create a unireg form-file from a FIELD and a fieldname-fieldinfo
|
|
|
|
struct.
|
2001-09-12 22:53:31 +02:00
|
|
|
In the following functions FIELD * is an ordinary field-structure with
|
2000-07-31 21:29:14 +02:00
|
|
|
the following exeptions:
|
2001-09-27 20:45:48 +02:00
|
|
|
sc_length,typepos,row,kol,dtype,regnr and field need not to be set.
|
2000-07-31 21:29:14 +02:00
|
|
|
str is a (long) to record position where 0 is the first position.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include <m_ctype.h>
|
2005-05-14 16:08:43 +02:00
|
|
|
#include <assert.h>
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-02-07 14:47:24 +01:00
|
|
|
#define FCOMP 17 /* Bytes for a packed field */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
static uchar * pack_screens(List<Create_field> &create_fields,
|
2000-07-31 21:29:14 +02:00
|
|
|
uint *info_length, uint *screens, bool small_file);
|
2005-05-13 10:11:50 +02:00
|
|
|
static uint pack_keys(uchar *keybuff,uint key_count, KEY *key_info,
|
|
|
|
ulong data_offset);
|
2005-12-21 19:18:40 +01:00
|
|
|
static bool pack_header(uchar *forminfo,enum legacy_db_type table_type,
|
2007-06-10 12:43:57 +02:00
|
|
|
List<Create_field> &create_fields,
|
2000-07-31 21:29:14 +02:00
|
|
|
uint info_length, uint screens, uint table_options,
|
2005-05-13 10:11:50 +02:00
|
|
|
ulong data_offset, handler *file);
|
2009-05-04 22:33:23 +02:00
|
|
|
static uint get_interval_id(uint *,List<Create_field> &, Create_field *);
|
2007-06-10 12:43:57 +02:00
|
|
|
static bool pack_fields(File file, List<Create_field> &create_fields,
|
2005-05-13 10:11:50 +02:00
|
|
|
ulong data_offset);
|
2005-12-21 19:18:40 +01:00
|
|
|
static bool make_empty_rec(THD *thd, int file, enum legacy_db_type table_type,
|
2000-07-31 21:29:14 +02:00
|
|
|
uint table_options,
|
2007-06-10 12:43:57 +02:00
|
|
|
List<Create_field> &create_fields,
|
2005-07-18 13:31:02 +02:00
|
|
|
uint reclength, ulong data_offset,
|
|
|
|
handler *handler);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-11-01 16:06:46 +01:00
|
|
|
/**
|
|
|
|
An interceptor to hijack ER_TOO_MANY_FIELDS error from
|
|
|
|
pack_screens and retry again without UNIREG screens.
|
|
|
|
|
|
|
|
XXX: what is a UNIREG screen?
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct Pack_header_error_handler: public Internal_error_handler
|
|
|
|
{
|
|
|
|
virtual bool handle_error(uint sql_errno,
|
|
|
|
const char *message,
|
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
|
|
|
THD *thd);
|
|
|
|
bool is_handled;
|
|
|
|
Pack_header_error_handler() :is_handled(FALSE) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
Pack_header_error_handler::
|
|
|
|
handle_error(uint sql_errno,
|
|
|
|
const char * /* message */,
|
|
|
|
MYSQL_ERROR::enum_warning_level /* level */,
|
|
|
|
THD * /* thd */)
|
|
|
|
{
|
|
|
|
is_handled= (sql_errno == ER_TOO_MANY_FIELDS);
|
|
|
|
return is_handled;
|
|
|
|
}
|
|
|
|
|
2004-04-08 16:56:45 +02:00
|
|
|
/*
|
|
|
|
Create a frm (table definition) file
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
mysql_create_frm()
|
|
|
|
thd Thread handler
|
2005-11-23 21:45:02 +01:00
|
|
|
file_name Path for file (including database and .frm)
|
2005-07-22 05:08:54 +02:00
|
|
|
db Name of database
|
2005-07-27 12:05:30 +02:00
|
|
|
table Name of table
|
2004-04-08 16:56:45 +02:00
|
|
|
create_info create info parameters
|
|
|
|
create_fields Fields to create
|
|
|
|
keys number of keys to create
|
|
|
|
key_info Keys to create
|
|
|
|
db_file Handler to use. May be zero, in which case we use
|
2006-01-28 19:21:40 +01:00
|
|
|
create_info->db_type
|
2004-04-08 16:56:45 +02:00
|
|
|
RETURN
|
2009-01-14 17:10:36 +01:00
|
|
|
false ok
|
|
|
|
true error
|
2004-04-08 16:56:45 +02:00
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
bool mysql_create_frm(THD *thd, const char *file_name,
|
2005-07-27 12:05:30 +02:00
|
|
|
const char *db, const char *table,
|
2004-04-08 16:56:45 +02:00
|
|
|
HA_CREATE_INFO *create_info,
|
2007-06-10 12:43:57 +02:00
|
|
|
List<Create_field> &create_fields,
|
2004-04-08 16:56:45 +02:00
|
|
|
uint keys, KEY *key_info,
|
|
|
|
handler *db_file)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-10-10 20:01:45 +02:00
|
|
|
LEX_STRING str_db_type;
|
2006-07-18 15:43:55 +02:00
|
|
|
uint reclength, info_length, screens, key_info_length, maxlength, tmp_len, i;
|
2005-05-25 17:33:32 +02:00
|
|
|
ulong key_buff_length;
|
2000-07-31 21:29:14 +02:00
|
|
|
File file;
|
2005-05-13 10:11:50 +02:00
|
|
|
ulong filepos, data_offset;
|
2000-07-31 21:29:14 +02:00
|
|
|
uchar fileinfo[64],forminfo[288],*keybuff;
|
|
|
|
uchar *screen_buff;
|
2006-12-14 23:51:37 +01:00
|
|
|
char buff[128];
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
2006-03-18 15:48:21 +01:00
|
|
|
partition_info *part_info= thd->work_part_info;
|
2005-07-18 13:31:02 +02:00
|
|
|
#endif
|
2007-11-01 16:06:46 +01:00
|
|
|
Pack_header_error_handler pack_header_error_handler;
|
|
|
|
int error;
|
2004-07-29 10:33:33 +02:00
|
|
|
DBUG_ENTER("mysql_create_frm");
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-12-31 06:01:26 +01:00
|
|
|
DBUG_ASSERT(*fn_rext((char*)file_name)); // Check .frm extension
|
2010-06-10 22:16:43 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,0)))
|
|
|
|
DBUG_RETURN(1);
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_ASSERT(db_file != NULL);
|
2005-05-13 10:11:50 +02:00
|
|
|
|
|
|
|
/* If fixed row records, we need one bit to check for deleted rows */
|
|
|
|
if (!(create_info->table_options & HA_OPTION_PACK_RECORD))
|
|
|
|
create_info->null_bits++;
|
|
|
|
data_offset= (create_info->null_bits + 7) / 8;
|
|
|
|
|
2007-11-01 16:06:46 +01:00
|
|
|
thd->push_internal_handler(&pack_header_error_handler);
|
|
|
|
|
|
|
|
error= pack_header(forminfo, ha_legacy_type(create_info->db_type),
|
|
|
|
create_fields,info_length,
|
|
|
|
screens, create_info->table_options,
|
|
|
|
data_offset, db_file);
|
|
|
|
|
|
|
|
thd->pop_internal_handler();
|
|
|
|
|
|
|
|
if (error)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_free(screen_buff, MYF(0));
|
2007-11-01 16:06:46 +01:00
|
|
|
if (! pack_header_error_handler.is_handled)
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
// Try again without UNIREG screens (to get more columns)
|
|
|
|
if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,1)))
|
|
|
|
DBUG_RETURN(1);
|
2005-12-21 19:18:40 +01:00
|
|
|
if (pack_header(forminfo, ha_legacy_type(create_info->db_type),
|
|
|
|
create_fields,info_length,
|
2005-05-13 10:11:50 +02:00
|
|
|
screens, create_info->table_options, data_offset, db_file))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_free(screen_buff, MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reclength=uint2korr(forminfo+266);
|
|
|
|
|
2005-10-10 20:01:45 +02:00
|
|
|
/* Calculate extra data segment length */
|
2005-12-21 19:18:40 +01:00
|
|
|
str_db_type.str= (char *) ha_resolve_storage_engine_name(create_info->db_type);
|
2005-10-10 20:01:45 +02:00
|
|
|
str_db_type.length= strlen(str_db_type.str);
|
2005-11-05 12:20:35 +01:00
|
|
|
/* str_db_type */
|
2005-10-13 18:40:46 +02:00
|
|
|
create_info->extra_size= (2 + str_db_type.length +
|
|
|
|
2 + create_info->connect_string.length);
|
2006-05-10 18:53:40 +02:00
|
|
|
/*
|
|
|
|
Partition:
|
|
|
|
Length of partition info = 4 byte
|
|
|
|
Potential NULL byte at end of partition info string = 1 byte
|
|
|
|
Indicator if auto-partitioned table = 1 byte
|
|
|
|
=> Total 6 byte
|
|
|
|
*/
|
|
|
|
create_info->extra_size+= 6;
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
2005-11-05 12:20:35 +01:00
|
|
|
if (part_info)
|
2006-01-17 08:40:00 +01:00
|
|
|
{
|
2005-11-05 12:20:35 +01:00
|
|
|
create_info->extra_size+= part_info->part_info_len;
|
2006-01-17 08:40:00 +01:00
|
|
|
}
|
2005-11-05 12:20:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i= 0; i < keys; i++)
|
|
|
|
{
|
|
|
|
if (key_info[i].parser_name)
|
|
|
|
create_info->extra_size+= key_info[i].parser_name->length + 1;
|
|
|
|
}
|
2005-10-10 20:01:45 +02:00
|
|
|
|
2005-07-28 16:09:54 +02:00
|
|
|
if ((file=create_frm(thd, file_name, db, table, reclength, fileinfo,
|
2000-07-31 21:29:14 +02:00
|
|
|
create_info, keys)) < 0)
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_free(screen_buff, MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
2005-05-25 17:33:32 +02:00
|
|
|
key_buff_length= uint4korr(fileinfo+47);
|
2003-10-21 00:13:17 +02:00
|
|
|
keybuff=(uchar*) my_malloc(key_buff_length, MYF(0));
|
2005-05-13 10:11:50 +02:00
|
|
|
key_info_length= pack_keys(keybuff, keys, key_info, data_offset);
|
2010-06-10 22:16:43 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Ensure that there are no forms in this newly created form file.
|
|
|
|
Even if the form file exists, create_frm must truncate it to
|
|
|
|
ensure one form per form file.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(uint2korr(fileinfo+8) == 0);
|
|
|
|
|
|
|
|
if (!(filepos= make_new_entry(file, fileinfo, NULL, "")))
|
2000-07-31 21:29:14 +02:00
|
|
|
goto err;
|
|
|
|
maxlength=(uint) next_io_size((ulong) (uint2korr(forminfo)+1000));
|
|
|
|
int2store(forminfo+2,maxlength);
|
2003-10-30 19:17:57 +01:00
|
|
|
int4store(fileinfo+10,(ulong) (filepos+maxlength));
|
2000-07-31 21:29:14 +02:00
|
|
|
fileinfo[26]= (uchar) test((create_info->max_rows == 1) &&
|
|
|
|
(create_info->min_rows == 1) && (keys == 0));
|
|
|
|
int2store(fileinfo+28,key_info_length);
|
|
|
|
|
2008-11-20 15:39:39 +01:00
|
|
|
/*
|
|
|
|
This gives us the byte-position of the character at
|
|
|
|
(character-position, not byte-position) TABLE_COMMENT_MAXLEN.
|
|
|
|
The trick here is that character-positions start at 0, so the last
|
|
|
|
character in a maximum-allowed length string would be at char-pos
|
|
|
|
MAXLEN-1; charpos MAXLEN will be the position of the terminator.
|
|
|
|
Consequently, bytepos(charpos(MAXLEN)) should be equal to
|
|
|
|
comment[length] (which should also be the terminator, or at least
|
|
|
|
the first byte after the payload in the strict sense). If this is
|
|
|
|
not so (bytepos(charpos(MAXLEN)) comes /before/ the end of the
|
|
|
|
string), the string is too long.
|
|
|
|
|
|
|
|
For additional credit, realise that UTF-8 has 1-3 bytes before 6.0,
|
|
|
|
and 1-4 bytes in 6.0 (6.0 also has UTF-32). This means that the
|
|
|
|
inlined COMMENT supposedly does not exceed 60 character plus
|
|
|
|
terminator, vulgo, 181 bytes.
|
|
|
|
*/
|
|
|
|
|
2006-06-29 15:39:34 +02:00
|
|
|
tmp_len= system_charset_info->cset->charpos(system_charset_info,
|
|
|
|
create_info->comment.str,
|
|
|
|
create_info->comment.str +
|
|
|
|
create_info->comment.length, 60);
|
|
|
|
if (tmp_len < create_info->comment.length)
|
|
|
|
{
|
|
|
|
if ((thd->variables.sql_mode &
|
|
|
|
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
|
|
|
|
{
|
2009-03-05 12:20:01 +01:00
|
|
|
my_error(ER_TOO_LONG_TABLE_COMMENT, MYF(0), table, tmp_len);
|
2006-06-29 15:39:34 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
2009-03-05 12:20:01 +01:00
|
|
|
ER_TOO_LONG_TABLE_COMMENT,
|
|
|
|
ER(ER_TOO_LONG_TABLE_COMMENT),
|
|
|
|
table, tmp_len);
|
2006-06-29 15:39:34 +02:00
|
|
|
create_info->comment.length= tmp_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
strmake((char*) forminfo+47, create_info->comment.str ?
|
|
|
|
create_info->comment.str : "", create_info->comment.length);
|
|
|
|
forminfo[46]=(uchar) create_info->comment.length;
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
2005-07-18 13:31:02 +02:00
|
|
|
if (part_info)
|
2006-01-17 08:40:00 +01:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
fileinfo[61]= (uchar) ha_legacy_type(part_info->default_engine_type);
|
2006-01-17 08:40:00 +01:00
|
|
|
DBUG_PRINT("info", ("part_db_type = %d", fileinfo[61]));
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
#endif
|
|
|
|
int2store(fileinfo+59,db_file->extra_rec_buf_length());
|
2006-07-18 15:43:55 +02:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_pwrite(file, fileinfo, 64, 0L, MYF_RW) ||
|
|
|
|
my_pwrite(file, keybuff, key_info_length,
|
2000-07-31 21:29:14 +02:00
|
|
|
(ulong) uint2korr(fileinfo+6),MYF_RW))
|
|
|
|
goto err;
|
|
|
|
VOID(my_seek(file,
|
|
|
|
(ulong) uint2korr(fileinfo+6)+ (ulong) key_buff_length,
|
|
|
|
MY_SEEK_SET,MYF(0)));
|
2005-12-21 19:18:40 +01:00
|
|
|
if (make_empty_rec(thd,file,ha_legacy_type(create_info->db_type),
|
|
|
|
create_info->table_options,
|
2005-07-18 13:31:02 +02:00
|
|
|
create_fields,reclength, data_offset, db_file))
|
2000-07-31 21:29:14 +02:00
|
|
|
goto err;
|
2005-10-10 20:01:45 +02:00
|
|
|
|
2005-10-10 20:53:53 +02:00
|
|
|
int2store(buff, create_info->connect_string.length);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, (const uchar*)buff, 2, MYF(MY_NABP)) ||
|
|
|
|
my_write(file, (const uchar*)create_info->connect_string.str,
|
2005-10-10 20:53:53 +02:00
|
|
|
create_info->connect_string.length, MYF(MY_NABP)))
|
2005-09-13 03:02:17 +02:00
|
|
|
goto err;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-10-10 20:01:45 +02:00
|
|
|
int2store(buff, str_db_type.length);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, (const uchar*)buff, 2, MYF(MY_NABP)) ||
|
|
|
|
my_write(file, (const uchar*)str_db_type.str,
|
2005-10-10 20:01:45 +02:00
|
|
|
str_db_type.length, MYF(MY_NABP)))
|
|
|
|
goto err;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
2005-07-18 13:31:02 +02:00
|
|
|
if (part_info)
|
|
|
|
{
|
2006-05-10 18:53:40 +02:00
|
|
|
char auto_partitioned= part_info->is_auto_partitioned ? 1 : 0;
|
2005-11-05 12:20:35 +01:00
|
|
|
int4store(buff, part_info->part_info_len);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, (const uchar*)buff, 4, MYF_RW) ||
|
|
|
|
my_write(file, (const uchar*)part_info->part_info_string,
|
2006-05-10 18:53:40 +02:00
|
|
|
part_info->part_info_len + 1, MYF_RW) ||
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_write(file, (const uchar*)&auto_partitioned, 1, MYF_RW))
|
2005-07-18 13:31:02 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2005-11-05 12:20:35 +01:00
|
|
|
else
|
2005-07-18 13:31:02 +02:00
|
|
|
#endif
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
bzero((uchar*) buff, 6);
|
|
|
|
if (my_write(file, (uchar*) buff, 6, MYF_RW))
|
2005-11-05 12:20:35 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
for (i= 0; i < keys; i++)
|
|
|
|
{
|
|
|
|
if (key_info[i].parser_name)
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, (const uchar*)key_info[i].parser_name->str,
|
2005-11-05 12:20:35 +01:00
|
|
|
key_info[i].parser_name->length + 1, MYF(MY_NABP)))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2006-01-28 19:21:40 +01:00
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0)));
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, forminfo, 288, MYF_RW) ||
|
|
|
|
my_write(file, screen_buff, info_length, MYF_RW) ||
|
2005-11-05 12:20:35 +01:00
|
|
|
pack_fields(file, create_fields, data_offset))
|
|
|
|
goto err;
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#ifdef HAVE_CRYPTED_FRM
|
|
|
|
if (create_info->password)
|
|
|
|
{
|
|
|
|
char tmp=2,*disk_buff=0;
|
|
|
|
SQL_CRYPT *crypted=new SQL_CRYPT(create_info->password);
|
|
|
|
if (!crypted || my_pwrite(file,&tmp,1,26,MYF_RW)) // Mark crypted
|
|
|
|
goto err;
|
|
|
|
uint read_length=uint2korr(forminfo)-256;
|
|
|
|
VOID(my_seek(file,filepos+256,MY_SEEK_SET,MYF(0)));
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (read_string(file,(uchar**) &disk_buff,read_length))
|
2000-07-31 21:29:14 +02:00
|
|
|
goto err;
|
|
|
|
crypted->encode(disk_buff,read_length);
|
|
|
|
delete crypted;
|
|
|
|
if (my_pwrite(file,disk_buff,read_length,filepos+256,MYF_RW))
|
|
|
|
{
|
|
|
|
my_free(disk_buff,MYF(0));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
my_free(disk_buff,MYF(0));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_free(screen_buff,MYF(0));
|
|
|
|
my_free(keybuff, MYF(0));
|
2004-02-19 18:36:53 +01:00
|
|
|
|
|
|
|
if (opt_sync_frm && !(create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
|
2007-10-11 17:07:40 +02:00
|
|
|
(my_sync(file, MYF(MY_WME)) ||
|
|
|
|
my_sync_dir_by_file(file_name, MYF(MY_WME))))
|
|
|
|
goto err2;
|
|
|
|
|
2004-03-30 19:22:14 +02:00
|
|
|
if (my_close(file,MYF(MY_WME)))
|
2003-11-02 14:55:02 +01:00
|
|
|
goto err3;
|
2004-12-21 14:12:27 +01:00
|
|
|
|
|
|
|
{
|
2006-09-20 18:46:12 +02:00
|
|
|
/*
|
|
|
|
Restore all UCS2 intervals.
|
|
|
|
HEX representation of them is not needed anymore.
|
|
|
|
*/
|
2007-06-10 12:43:57 +02:00
|
|
|
List_iterator<Create_field> it(create_fields);
|
|
|
|
Create_field *field;
|
2004-12-21 14:12:27 +01:00
|
|
|
while ((field=it++))
|
|
|
|
{
|
2006-09-20 18:46:12 +02:00
|
|
|
if (field->save_interval)
|
|
|
|
{
|
|
|
|
field->interval= field->save_interval;
|
|
|
|
field->save_interval= 0;
|
|
|
|
}
|
2004-12-21 14:12:27 +01:00
|
|
|
}
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
err:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_free(screen_buff, MYF(0));
|
|
|
|
my_free(keybuff, MYF(0));
|
2003-11-02 14:55:02 +01:00
|
|
|
err2:
|
2000-07-31 21:29:14 +02:00
|
|
|
VOID(my_close(file,MYF(MY_WME)));
|
2003-11-02 14:55:02 +01:00
|
|
|
err3:
|
2004-04-08 16:56:45 +02:00
|
|
|
my_delete(file_name,MYF(0));
|
2004-03-30 19:22:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
} /* mysql_create_frm */
|
|
|
|
|
2004-04-08 16:56:45 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Create a frm (table definition) file and the tables
|
|
|
|
|
|
|
|
SYNOPSIS
|
2005-07-18 13:31:02 +02:00
|
|
|
rea_create_table()
|
2004-04-08 16:56:45 +02:00
|
|
|
thd Thread handler
|
2005-12-31 06:01:26 +01:00
|
|
|
path Name of file (including database, without .frm)
|
2005-11-23 21:45:02 +01:00
|
|
|
db Data base name
|
|
|
|
table_name Table name
|
2004-04-08 16:56:45 +02:00
|
|
|
create_info create info parameters
|
|
|
|
create_fields Fields to create
|
|
|
|
keys number of keys to create
|
|
|
|
key_info Keys to create
|
2005-11-23 21:45:02 +01:00
|
|
|
file Handler to use
|
|
|
|
|
2004-04-08 16:56:45 +02:00
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 error
|
|
|
|
*/
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
int rea_create_table(THD *thd, const char *path,
|
|
|
|
const char *db, const char *table_name,
|
|
|
|
HA_CREATE_INFO *create_info,
|
2007-06-10 12:43:57 +02:00
|
|
|
List<Create_field> &create_fields,
|
2005-11-23 21:45:02 +01:00
|
|
|
uint keys, KEY *key_info, handler *file)
|
2004-03-30 19:22:14 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("rea_create_table");
|
|
|
|
|
2005-12-31 06:01:26 +01:00
|
|
|
char frm_name[FN_REFLEN];
|
|
|
|
strxmov(frm_name, path, reg_ext, NullS);
|
|
|
|
if (mysql_create_frm(thd, frm_name, db, table_name, create_info,
|
2005-07-18 13:31:02 +02:00
|
|
|
create_fields, keys, key_info, file))
|
2005-12-31 06:01:26 +01:00
|
|
|
|
2004-04-08 16:56:45 +02:00
|
|
|
DBUG_RETURN(1);
|
2005-12-31 06:01:26 +01:00
|
|
|
|
|
|
|
// Make sure mysql_create_frm din't remove extension
|
|
|
|
DBUG_ASSERT(*fn_rext(frm_name));
|
2007-07-11 09:49:54 +02:00
|
|
|
if (thd->variables.keep_files_on_create)
|
|
|
|
create_info->options|= HA_CREATE_KEEP_FILES;
|
2009-09-02 13:19:28 +02:00
|
|
|
if (!create_info->frm_only &&
|
|
|
|
(file->ha_create_handler_files(path, NULL, CHF_CREATE_FLAG,
|
|
|
|
create_info) ||
|
|
|
|
ha_create_table(thd, path, db, table_name, create_info, 0)))
|
2005-07-18 13:31:02 +02:00
|
|
|
goto err_handler;
|
2004-03-30 19:22:14 +02:00
|
|
|
DBUG_RETURN(0);
|
2005-11-23 21:45:02 +01:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
err_handler:
|
2007-12-20 19:16:55 +01:00
|
|
|
VOID(file->ha_create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info));
|
2005-12-31 06:01:26 +01:00
|
|
|
my_delete(frm_name, MYF(0));
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(1);
|
2000-07-31 21:29:14 +02:00
|
|
|
} /* rea_create_table */
|
|
|
|
|
|
|
|
|
|
|
|
/* Pack screens to a screen for save in a form-file */
|
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
static uchar *pack_screens(List<Create_field> &create_fields,
|
2006-05-03 14:59:17 +02:00
|
|
|
uint *info_length, uint *screens,
|
|
|
|
bool small_file)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
reg1 uint i;
|
|
|
|
uint row,start_row,end_row,fields_on_screen;
|
|
|
|
uint length,cols;
|
|
|
|
uchar *info,*pos,*start_screen;
|
|
|
|
uint fields=create_fields.elements;
|
2007-06-10 12:43:57 +02:00
|
|
|
List_iterator<Create_field> it(create_fields);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("pack_screens");
|
|
|
|
|
|
|
|
start_row=4; end_row=22; cols=80; fields_on_screen=end_row+1-start_row;
|
|
|
|
|
|
|
|
*screens=(fields-1)/fields_on_screen+1;
|
|
|
|
length= (*screens) * (SC_INFO_LENGTH+ (cols>> 1)+4);
|
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
Create_field *field;
|
2000-07-31 21:29:14 +02:00
|
|
|
while ((field=it++))
|
2000-08-21 23:18:32 +02:00
|
|
|
length+=(uint) strlen(field->field_name)+1+TE_INFO_LENGTH+cols/2;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if (!(info=(uchar*) my_malloc(length,MYF(MY_WME))))
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
start_screen=0;
|
|
|
|
row=end_row;
|
|
|
|
pos=info;
|
|
|
|
it.rewind();
|
|
|
|
for (i=0 ; i < fields ; i++)
|
|
|
|
{
|
2007-06-10 12:43:57 +02:00
|
|
|
Create_field *cfield=it++;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (row++ == end_row)
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
length=(uint) (pos-start_screen);
|
|
|
|
int2store(start_screen,length);
|
|
|
|
start_screen[2]=(uchar) (fields_on_screen+1);
|
|
|
|
start_screen[3]=(uchar) (fields_on_screen);
|
|
|
|
}
|
|
|
|
row=start_row;
|
|
|
|
start_screen=pos;
|
|
|
|
pos+=4;
|
|
|
|
pos[0]= (uchar) start_row-2; /* Header string */
|
|
|
|
pos[1]= (uchar) (cols >> 2);
|
|
|
|
pos[2]= (uchar) (cols >> 1) +1;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
strfill((char *) pos+3,(uint) (cols >> 1),' ');
|
2000-07-31 21:29:14 +02:00
|
|
|
pos+=(cols >> 1)+4;
|
|
|
|
}
|
2000-08-21 23:18:32 +02:00
|
|
|
length=(uint) strlen(cfield->field_name);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (length > cols-3)
|
|
|
|
length=cols-3;
|
|
|
|
|
|
|
|
if (!small_file)
|
|
|
|
{
|
|
|
|
pos[0]=(uchar) row;
|
|
|
|
pos[1]=0;
|
|
|
|
pos[2]=(uchar) (length+1);
|
|
|
|
pos=(uchar*) strmake((char*) pos+3,cfield->field_name,length)+1;
|
|
|
|
}
|
|
|
|
cfield->row=(uint8) row;
|
|
|
|
cfield->col=(uint8) (length+1);
|
|
|
|
cfield->sc_length=(uint8) min(cfield->length,cols-(length+2));
|
|
|
|
}
|
|
|
|
length=(uint) (pos-start_screen);
|
|
|
|
int2store(start_screen,length);
|
|
|
|
start_screen[2]=(uchar) (row-start_row+2);
|
|
|
|
start_screen[3]=(uchar) (row-start_row+1);
|
|
|
|
|
|
|
|
*info_length=(uint) (pos-info);
|
|
|
|
DBUG_RETURN(info);
|
|
|
|
} /* pack_screens */
|
|
|
|
|
|
|
|
|
|
|
|
/* Pack keyinfo and keynames to keybuff for save in form-file. */
|
|
|
|
|
2005-05-13 10:11:50 +02:00
|
|
|
static uint pack_keys(uchar *keybuff, uint key_count, KEY *keyinfo,
|
|
|
|
ulong data_offset)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
uint key_parts,length;
|
2002-06-04 07:23:57 +02:00
|
|
|
uchar *pos, *keyname_pos;
|
2000-07-31 21:29:14 +02:00
|
|
|
KEY *key,*end;
|
|
|
|
KEY_PART_INFO *key_part,*key_part_end;
|
|
|
|
DBUG_ENTER("pack_keys");
|
|
|
|
|
|
|
|
pos=keybuff+6;
|
|
|
|
key_parts=0;
|
|
|
|
for (key=keyinfo,end=keyinfo+key_count ; key != end ; key++)
|
|
|
|
{
|
2002-06-02 20:22:20 +02:00
|
|
|
int2store(pos, (key->flags ^ HA_NOSAME));
|
|
|
|
int2store(pos+2,key->key_length);
|
|
|
|
pos[4]= (uchar) key->key_parts;
|
|
|
|
pos[5]= (uchar) key->algorithm;
|
2006-05-03 14:59:17 +02:00
|
|
|
int2store(pos+6, key->block_size);
|
2002-06-02 20:22:20 +02:00
|
|
|
pos+=8;
|
2000-07-31 21:29:14 +02:00
|
|
|
key_parts+=key->key_parts;
|
2007-11-10 18:39:30 +01:00
|
|
|
DBUG_PRINT("loop", ("flags: %lu key_parts: %d at 0x%lx",
|
2006-11-20 21:42:06 +01:00
|
|
|
key->flags, key->key_parts,
|
|
|
|
(long) key->key_part));
|
2000-07-31 21:29:14 +02:00
|
|
|
for (key_part=key->key_part,key_part_end=key_part+key->key_parts ;
|
|
|
|
key_part != key_part_end ;
|
|
|
|
key_part++)
|
|
|
|
|
|
|
|
{
|
2005-05-13 10:11:50 +02:00
|
|
|
uint offset;
|
2006-11-20 21:42:06 +01:00
|
|
|
DBUG_PRINT("loop",("field: %d startpos: %lu length: %d",
|
2005-05-13 10:11:50 +02:00
|
|
|
key_part->fieldnr, key_part->offset + data_offset,
|
|
|
|
key_part->length));
|
2000-07-31 21:29:14 +02:00
|
|
|
int2store(pos,key_part->fieldnr+1+FIELD_NAME_USED);
|
2005-05-13 10:11:50 +02:00
|
|
|
offset= (uint) (key_part->offset+data_offset+1);
|
|
|
|
int2store(pos+2, offset);
|
2000-07-31 21:29:14 +02:00
|
|
|
pos[4]=0; // Sort order
|
|
|
|
int2store(pos+5,key_part->key_type);
|
|
|
|
int2store(pos+7,key_part->length);
|
|
|
|
pos+=9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Save keynames */
|
|
|
|
keyname_pos=pos;
|
2000-11-17 01:36:46 +01:00
|
|
|
*pos++=(uchar) NAMES_SEP_CHAR;
|
2000-07-31 21:29:14 +02:00
|
|
|
for (key=keyinfo ; key != end ; key++)
|
|
|
|
{
|
|
|
|
uchar *tmp=(uchar*) strmov((char*) pos,key->name);
|
2000-11-17 01:36:46 +01:00
|
|
|
*tmp++= (uchar) NAMES_SEP_CHAR;
|
2000-07-31 21:29:14 +02:00
|
|
|
*tmp=0;
|
|
|
|
pos=tmp;
|
|
|
|
}
|
|
|
|
*(pos++)=0;
|
|
|
|
|
2003-10-21 00:13:17 +02:00
|
|
|
if (key_count > 127 || key_parts > 127)
|
|
|
|
{
|
2003-10-30 19:17:57 +01:00
|
|
|
keybuff[0]= (key_count & 0x7f) | 0x80;
|
|
|
|
keybuff[1]= key_count >> 7;
|
2003-10-21 00:13:17 +02:00
|
|
|
int2store(keybuff+2,key_parts);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
keybuff[0]=(uchar) key_count;
|
|
|
|
keybuff[1]=(uchar) key_parts;
|
2003-11-04 13:09:03 +01:00
|
|
|
keybuff[2]= keybuff[3]= 0;
|
2003-10-21 00:13:17 +02:00
|
|
|
}
|
2002-06-04 07:23:57 +02:00
|
|
|
length=(uint) (pos-keyname_pos);
|
2000-07-31 21:29:14 +02:00
|
|
|
int2store(keybuff+4,length);
|
|
|
|
DBUG_RETURN((uint) (pos-keybuff));
|
|
|
|
} /* pack_keys */
|
|
|
|
|
|
|
|
|
|
|
|
/* Make formheader */
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static bool pack_header(uchar *forminfo, enum legacy_db_type table_type,
|
2007-06-10 12:43:57 +02:00
|
|
|
List<Create_field> &create_fields,
|
2005-05-13 10:11:50 +02:00
|
|
|
uint info_length, uint screens, uint table_options,
|
|
|
|
ulong data_offset, handler *file)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-06-02 20:22:20 +02:00
|
|
|
uint length,int_count,int_length,no_empty, int_parts;
|
2002-06-04 07:23:57 +02:00
|
|
|
uint time_stamp_pos,null_fields;
|
|
|
|
ulong reclength, totlength, n_length, com_length;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("pack_header");
|
|
|
|
|
|
|
|
if (create_fields.elements > MAX_FIELDS)
|
|
|
|
{
|
2004-11-12 13:34:00 +01:00
|
|
|
my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
2005-05-25 17:33:32 +02:00
|
|
|
totlength= 0L;
|
|
|
|
reclength= data_offset;
|
2002-06-02 20:22:20 +02:00
|
|
|
no_empty=int_count=int_parts=int_length=time_stamp_pos=null_fields=
|
|
|
|
com_length=0;
|
2000-07-31 21:29:14 +02:00
|
|
|
n_length=2L;
|
|
|
|
|
|
|
|
/* Check fields */
|
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
List_iterator<Create_field> it(create_fields);
|
|
|
|
Create_field *field;
|
2000-07-31 21:29:14 +02:00
|
|
|
while ((field=it++))
|
|
|
|
{
|
2006-06-29 15:39:34 +02:00
|
|
|
uint tmp_len= system_charset_info->cset->charpos(system_charset_info,
|
|
|
|
field->comment.str,
|
|
|
|
field->comment.str +
|
2006-12-14 23:51:37 +01:00
|
|
|
field->comment.length,
|
|
|
|
255);
|
2006-06-29 15:39:34 +02:00
|
|
|
if (tmp_len < field->comment.length)
|
|
|
|
{
|
|
|
|
if ((current_thd->variables.sql_mode &
|
|
|
|
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
|
|
|
|
{
|
2009-03-05 12:20:01 +01:00
|
|
|
my_error(ER_TOO_LONG_FIELD_COMMENT, MYF(0), field->field_name, tmp_len);
|
2006-06-29 15:39:34 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
2009-03-05 12:20:01 +01:00
|
|
|
ER_TOO_LONG_FIELD_COMMENT,
|
|
|
|
ER(ER_TOO_LONG_FIELD_COMMENT),
|
|
|
|
field->field_name, tmp_len);
|
2006-06-29 15:39:34 +02:00
|
|
|
field->comment.length= tmp_len;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
totlength+= field->length;
|
2002-06-02 20:22:20 +02:00
|
|
|
com_length+= field->comment.length;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (MTYP_TYPENR(field->unireg_check) == Field::NOEMPTY ||
|
|
|
|
field->unireg_check & MTYP_NOEMPTY_BIT)
|
|
|
|
{
|
|
|
|
field->unireg_check= (Field::utype) ((uint) field->unireg_check |
|
|
|
|
MTYP_NOEMPTY_BIT);
|
|
|
|
no_empty++;
|
|
|
|
}
|
2004-04-02 08:12:53 +02:00
|
|
|
/*
|
|
|
|
We mark first TIMESTAMP field with NOW() in DEFAULT or ON UPDATE
|
|
|
|
as auto-update field.
|
|
|
|
*/
|
2006-12-02 02:26:52 +01:00
|
|
|
if (field->sql_type == MYSQL_TYPE_TIMESTAMP &&
|
2004-04-02 08:12:53 +02:00
|
|
|
MTYP_TYPENR(field->unireg_check) != Field::NONE &&
|
2000-07-31 21:29:14 +02:00
|
|
|
!time_stamp_pos)
|
2005-05-13 10:11:50 +02:00
|
|
|
time_stamp_pos= (uint) field->offset+ (uint) data_offset + 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
length=field->pack_length;
|
2005-05-25 17:33:32 +02:00
|
|
|
/* Ensure we don't have any bugs when generating offsets */
|
|
|
|
DBUG_ASSERT(reclength == field->offset + data_offset);
|
2005-05-13 10:11:50 +02:00
|
|
|
if ((uint) field->offset+ (uint) data_offset+ length > reclength)
|
|
|
|
reclength=(uint) (field->offset+ data_offset + length);
|
2000-07-31 21:29:14 +02:00
|
|
|
n_length+= (ulong) strlen(field->field_name)+1;
|
|
|
|
field->interval_id=0;
|
2006-09-20 18:46:12 +02:00
|
|
|
field->save_interval= 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (field->interval)
|
|
|
|
{
|
|
|
|
uint old_int_count=int_count;
|
2004-12-06 17:45:32 +01:00
|
|
|
|
|
|
|
if (field->charset->mbminlen > 1)
|
|
|
|
{
|
2006-09-20 18:46:12 +02:00
|
|
|
/*
|
|
|
|
Escape UCS2 intervals using HEX notation to avoid
|
|
|
|
problems with delimiters between enum elements.
|
|
|
|
As the original representation is still needed in
|
|
|
|
the function make_empty_rec to create a record of
|
|
|
|
filled with default values it is saved in save_interval
|
|
|
|
The HEX representation is created from this copy.
|
|
|
|
*/
|
|
|
|
field->save_interval= field->interval;
|
|
|
|
field->interval= (TYPELIB*) sql_alloc(sizeof(TYPELIB));
|
|
|
|
*field->interval= *field->save_interval;
|
|
|
|
field->interval->type_names=
|
|
|
|
(const char **) sql_alloc(sizeof(char*) *
|
|
|
|
(field->interval->count+1));
|
|
|
|
field->interval->type_names[field->interval->count]= 0;
|
|
|
|
field->interval->type_lengths=
|
|
|
|
(uint *) sql_alloc(sizeof(uint) * field->interval->count);
|
|
|
|
|
2004-12-06 17:45:32 +01:00
|
|
|
for (uint pos= 0; pos < field->interval->count; pos++)
|
|
|
|
{
|
|
|
|
char *dst;
|
2006-09-20 18:46:12 +02:00
|
|
|
const char *src= field->save_interval->type_names[pos];
|
2006-12-14 23:51:37 +01:00
|
|
|
uint hex_length;
|
|
|
|
length= field->save_interval->type_lengths[pos];
|
2004-12-06 17:45:32 +01:00
|
|
|
hex_length= length * 2;
|
|
|
|
field->interval->type_lengths[pos]= hex_length;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
field->interval->type_names[pos]= dst= (char*) sql_alloc(hex_length +
|
|
|
|
1);
|
2005-10-11 23:58:22 +02:00
|
|
|
octet2hex(dst, src, length);
|
2004-12-06 17:45:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
field->interval_id=get_interval_id(&int_count,create_fields,field);
|
|
|
|
if (old_int_count != int_count)
|
|
|
|
{
|
|
|
|
for (const char **pos=field->interval->type_names ; *pos ; pos++)
|
2000-08-21 23:18:32 +02:00
|
|
|
int_length+=(uint) strlen(*pos)+1; // field + suffix prefix
|
2000-07-31 21:29:14 +02:00
|
|
|
int_parts+=field->interval->count+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (f_maybe_null(field->pack_flag))
|
|
|
|
null_fields++;
|
|
|
|
}
|
|
|
|
int_length+=int_count*2; // 255 prefix + 0 suffix
|
|
|
|
|
|
|
|
/* Save values in forminfo */
|
|
|
|
|
|
|
|
if (reclength > (ulong) file->max_record_length())
|
|
|
|
{
|
|
|
|
my_error(ER_TOO_BIG_ROWSIZE, MYF(0), (uint) file->max_record_length());
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
/* Hack to avoid bugs with small static rows in MySQL */
|
|
|
|
reclength=max(file->min_record_length(table_options),reclength);
|
|
|
|
if (info_length+(ulong) create_fields.elements*FCOMP+288+
|
2002-06-02 20:22:20 +02:00
|
|
|
n_length+int_length+com_length > 65535L || int_count > 255)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-11-12 13:34:00 +01:00
|
|
|
my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero((char*)forminfo,288);
|
2002-06-02 20:22:20 +02:00
|
|
|
length=(info_length+create_fields.elements*FCOMP+288+n_length+int_length+
|
|
|
|
com_length);
|
2000-07-31 21:29:14 +02:00
|
|
|
int2store(forminfo,length);
|
|
|
|
forminfo[256] = (uint8) screens;
|
|
|
|
int2store(forminfo+258,create_fields.elements);
|
|
|
|
int2store(forminfo+260,info_length);
|
|
|
|
int2store(forminfo+262,totlength);
|
|
|
|
int2store(forminfo+264,no_empty);
|
|
|
|
int2store(forminfo+266,reclength);
|
|
|
|
int2store(forminfo+268,n_length);
|
|
|
|
int2store(forminfo+270,int_count);
|
|
|
|
int2store(forminfo+272,int_parts);
|
|
|
|
int2store(forminfo+274,int_length);
|
|
|
|
int2store(forminfo+276,time_stamp_pos);
|
2001-09-27 20:45:48 +02:00
|
|
|
int2store(forminfo+278,80); /* Columns needed */
|
|
|
|
int2store(forminfo+280,22); /* Rows needed */
|
2000-07-31 21:29:14 +02:00
|
|
|
int2store(forminfo+282,null_fields);
|
2002-06-02 20:22:20 +02:00
|
|
|
int2store(forminfo+284,com_length);
|
2005-05-06 10:39:30 +02:00
|
|
|
/* Up to forminfo+288 is free to use for additional information */
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
} /* pack_header */
|
|
|
|
|
|
|
|
|
|
|
|
/* get each unique interval each own id */
|
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
static uint get_interval_id(uint *int_count,List<Create_field> &create_fields,
|
|
|
|
Create_field *last_field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2007-06-10 12:43:57 +02:00
|
|
|
List_iterator<Create_field> it(create_fields);
|
|
|
|
Create_field *field;
|
2000-07-31 21:29:14 +02:00
|
|
|
TYPELIB *interval=last_field->interval;
|
|
|
|
|
|
|
|
while ((field=it++) != last_field)
|
|
|
|
{
|
|
|
|
if (field->interval_id && field->interval->count == interval->count)
|
|
|
|
{
|
|
|
|
const char **a,**b;
|
|
|
|
for (a=field->interval->type_names, b=interval->type_names ;
|
|
|
|
*a && !strcmp(*a,*b);
|
|
|
|
a++,b++) ;
|
|
|
|
|
|
|
|
if (! *a)
|
|
|
|
{
|
|
|
|
return field->interval_id; // Re-use last interval
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ++*int_count; // New unique interval
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Save fields, fieldnames and intervals */
|
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
static bool pack_fields(File file, List<Create_field> &create_fields,
|
2005-05-13 10:11:50 +02:00
|
|
|
ulong data_offset)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
reg2 uint i;
|
2002-06-02 20:22:20 +02:00
|
|
|
uint int_count, comment_length=0;
|
2000-07-31 21:29:14 +02:00
|
|
|
uchar buff[MAX_FIELD_WIDTH];
|
2007-06-10 12:43:57 +02:00
|
|
|
Create_field *field;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("pack_fields");
|
|
|
|
|
|
|
|
/* Write field info */
|
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
List_iterator<Create_field> it(create_fields);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
int_count=0;
|
|
|
|
while ((field=it++))
|
|
|
|
{
|
2005-05-13 10:11:50 +02:00
|
|
|
uint recpos;
|
2000-07-31 21:29:14 +02:00
|
|
|
buff[0]= (uchar) field->row;
|
|
|
|
buff[1]= (uchar) field->col;
|
|
|
|
buff[2]= (uchar) field->sc_length;
|
2003-02-07 14:47:24 +01:00
|
|
|
int2store(buff+3, field->length);
|
2005-05-13 10:11:50 +02:00
|
|
|
/* The +1 is here becasue the col offset in .frm file have offset 1 */
|
|
|
|
recpos= field->offset+1 + (uint) data_offset;
|
2003-02-07 14:47:24 +01:00
|
|
|
int3store(buff+5,recpos);
|
|
|
|
int2store(buff+8,field->pack_flag);
|
|
|
|
int2store(buff+10,field->unireg_check);
|
|
|
|
buff[12]= (uchar) field->interval_id;
|
|
|
|
buff[13]= (uchar) field->sql_type;
|
2006-12-02 02:26:52 +01:00
|
|
|
if (field->sql_type == MYSQL_TYPE_GEOMETRY)
|
2004-01-15 18:06:22 +01:00
|
|
|
{
|
2003-03-27 10:09:09 +01:00
|
|
|
buff[14]= (uchar) field->geom_type;
|
2004-01-15 18:06:22 +01:00
|
|
|
#ifndef HAVE_SPATIAL
|
|
|
|
DBUG_ASSERT(0); // Should newer happen
|
|
|
|
#endif
|
|
|
|
}
|
2003-06-30 12:23:54 +02:00
|
|
|
else if (field->charset)
|
2003-03-27 10:09:09 +01:00
|
|
|
buff[14]= (uchar) field->charset->number;
|
2003-06-30 12:23:54 +02:00
|
|
|
else
|
|
|
|
buff[14]= 0; // Numerical
|
2003-02-07 14:47:24 +01:00
|
|
|
int2store(buff+15, field->comment.length);
|
2002-06-02 20:22:20 +02:00
|
|
|
comment_length+= field->comment.length;
|
2000-07-31 21:29:14 +02:00
|
|
|
set_if_bigger(int_count,field->interval_id);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, buff, FCOMP, MYF_RW))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write fieldnames */
|
2000-11-17 01:36:46 +01:00
|
|
|
buff[0]=(uchar) NAMES_SEP_CHAR;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, buff, 1, MYF_RW))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
i=0;
|
|
|
|
it.rewind();
|
|
|
|
while ((field=it++))
|
|
|
|
{
|
|
|
|
char *pos= strmov((char*) buff,field->field_name);
|
|
|
|
*pos++=NAMES_SEP_CHAR;
|
|
|
|
if (i == create_fields.elements-1)
|
|
|
|
*pos++=0;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, buff, (size_t) (pos-(char*) buff),MYF_RW))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write intervals */
|
|
|
|
if (int_count)
|
|
|
|
{
|
2003-03-07 10:39:53 +01:00
|
|
|
String tmp((char*) buff,sizeof(buff), &my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
tmp.length(0);
|
|
|
|
it.rewind();
|
|
|
|
int_count=0;
|
|
|
|
while ((field=it++))
|
|
|
|
{
|
|
|
|
if (field->interval_id > int_count)
|
|
|
|
{
|
2007-01-12 11:06:38 +01:00
|
|
|
unsigned char sep= 0;
|
|
|
|
unsigned char occ[256];
|
|
|
|
uint i;
|
|
|
|
unsigned char *val= NULL;
|
|
|
|
|
|
|
|
bzero(occ, sizeof(occ));
|
|
|
|
|
|
|
|
for (i=0; (val= (unsigned char*) field->interval->type_names[i]); i++)
|
|
|
|
for (uint j = 0; j < field->interval->type_lengths[i]; j++)
|
|
|
|
occ[(unsigned int) (val[j])]= 1;
|
|
|
|
|
|
|
|
if (!occ[(unsigned char)NAMES_SEP_CHAR])
|
|
|
|
sep= (unsigned char) NAMES_SEP_CHAR;
|
|
|
|
else if (!occ[(unsigned int)','])
|
|
|
|
sep= ',';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (uint i=1; i<256; i++)
|
|
|
|
{
|
|
|
|
if(!occ[i])
|
|
|
|
{
|
|
|
|
sep= i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!sep) /* disaster, enum uses all characters, none left as separator */
|
2006-09-11 11:50:46 +02:00
|
|
|
{
|
2007-01-12 11:06:38 +01:00
|
|
|
my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS),
|
|
|
|
MYF(0));
|
|
|
|
DBUG_RETURN(1);
|
2006-09-11 11:50:46 +02:00
|
|
|
}
|
2007-01-12 11:06:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int_count= field->interval_id;
|
|
|
|
tmp.append(sep);
|
|
|
|
for (const char **pos=field->interval->type_names ; *pos ; pos++)
|
|
|
|
{
|
|
|
|
tmp.append(*pos);
|
|
|
|
tmp.append(sep);
|
|
|
|
}
|
|
|
|
tmp.append('\0'); // End of intervall
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file,(uchar*) tmp.ptr(),tmp.length(),MYF_RW))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2002-06-02 20:22:20 +02:00
|
|
|
if (comment_length)
|
|
|
|
{
|
|
|
|
it.rewind();
|
|
|
|
int_count=0;
|
|
|
|
while ((field=it++))
|
|
|
|
{
|
|
|
|
if (field->comment.length)
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_write(file, (uchar*) field->comment.str, field->comment.length,
|
2002-06-02 20:22:20 +02:00
|
|
|
MYF_RW))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-12 22:53:31 +02:00
|
|
|
/* save an empty record on start of formfile */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static bool make_empty_rec(THD *thd, File file,enum legacy_db_type table_type,
|
2000-07-31 21:29:14 +02:00
|
|
|
uint table_options,
|
2007-06-10 12:43:57 +02:00
|
|
|
List<Create_field> &create_fields,
|
2005-05-16 14:21:35 +02:00
|
|
|
uint reclength,
|
2005-07-18 13:31:02 +02:00
|
|
|
ulong data_offset,
|
|
|
|
handler *handler)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-11-23 21:45:02 +01:00
|
|
|
int error= 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
Field::utype type;
|
2005-06-06 15:23:04 +02:00
|
|
|
uint null_count;
|
2000-07-31 21:29:14 +02:00
|
|
|
uchar *buff,*null_pos;
|
|
|
|
TABLE table;
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE share;
|
2007-06-10 12:43:57 +02:00
|
|
|
Create_field *field;
|
2005-04-01 14:04:50 +02:00
|
|
|
enum_check_fields old_count_cuted_fields= thd->count_cuted_fields;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("make_empty_rec");
|
|
|
|
|
|
|
|
/* We need a table to generate columns for default values */
|
2005-11-23 21:45:02 +01:00
|
|
|
bzero((char*) &table, sizeof(table));
|
|
|
|
bzero((char*) &share, sizeof(share));
|
|
|
|
table.s= &share;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!(buff=(uchar*) my_malloc((size_t) reclength,MYF(MY_WME | MY_ZEROFILL))))
|
2001-12-13 18:06:14 +01:00
|
|
|
{
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
2001-12-13 18:06:14 +01:00
|
|
|
}
|
|
|
|
|
2005-04-01 14:04:50 +02:00
|
|
|
table.in_use= thd;
|
2005-01-06 12:00:13 +01:00
|
|
|
table.s->db_low_byte_first= handler->low_byte_first();
|
|
|
|
table.s->blob_ptr_size= portable_sizeof_char_ptr;
|
2001-12-13 18:06:14 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
null_count=0;
|
|
|
|
if (!(table_options & HA_OPTION_PACK_RECORD))
|
|
|
|
{
|
2005-05-13 10:11:50 +02:00
|
|
|
null_count++; // Need one bit for delete mark
|
2005-05-05 14:17:55 +02:00
|
|
|
*buff|= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2005-05-05 14:17:55 +02:00
|
|
|
null_pos= buff;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-06-10 12:43:57 +02:00
|
|
|
List_iterator<Create_field> it(create_fields);
|
2005-04-01 14:04:50 +02:00
|
|
|
thd->count_cuted_fields= CHECK_FIELD_WARN; // To find wrong default values
|
2000-07-31 21:29:14 +02:00
|
|
|
while ((field=it++))
|
|
|
|
{
|
2005-04-30 02:14:42 +02:00
|
|
|
/*
|
|
|
|
regfield don't have to be deleted as it's allocated with sql_alloc()
|
|
|
|
*/
|
2005-11-23 21:45:02 +01:00
|
|
|
Field *regfield= make_field(&share,
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
buff+field->offset + data_offset,
|
2005-11-23 21:45:02 +01:00
|
|
|
field->length,
|
|
|
|
null_pos + null_count / 8,
|
|
|
|
null_count & 7,
|
|
|
|
field->pack_flag,
|
|
|
|
field->sql_type,
|
|
|
|
field->charset,
|
|
|
|
field->geom_type,
|
|
|
|
field->unireg_check,
|
2006-09-30 02:04:34 +02:00
|
|
|
field->save_interval ? field->save_interval :
|
|
|
|
field->interval,
|
2005-11-23 21:45:02 +01:00
|
|
|
field->field_name);
|
2005-04-30 02:14:42 +02:00
|
|
|
if (!regfield)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
error= 1;
|
2005-04-30 02:14:42 +02:00
|
|
|
goto err; // End of memory
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2002-05-17 13:29:52 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
/* save_in_field() will access regfield->table->in_use */
|
|
|
|
regfield->init(&table);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(field->flags & NOT_NULL_FLAG))
|
2005-05-05 14:17:55 +02:00
|
|
|
{
|
|
|
|
*regfield->null_ptr|= regfield->null_bit;
|
2000-07-31 21:29:14 +02:00
|
|
|
null_count++;
|
2005-05-05 14:17:55 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-12-02 02:26:52 +01:00
|
|
|
if (field->sql_type == MYSQL_TYPE_BIT && !f_bit_as_char(field->pack_flag))
|
2005-05-05 14:17:55 +02:00
|
|
|
null_count+= field->length & 7;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
type= (Field::utype) MTYP_TYPENR(field->unireg_check);
|
|
|
|
|
2008-03-22 09:32:24 +01:00
|
|
|
if (field->def)
|
2005-04-01 14:04:50 +02:00
|
|
|
{
|
2007-03-23 21:08:31 +01:00
|
|
|
int res= field->def->save_in_field(regfield, 1);
|
|
|
|
/* If not ok or warning of level 'note' */
|
|
|
|
if (res != 0 && res != 3)
|
2005-04-01 14:04:50 +02:00
|
|
|
{
|
|
|
|
my_error(ER_INVALID_DEFAULT, MYF(0), regfield->field_name);
|
|
|
|
error= 1;
|
2005-04-28 14:45:27 +02:00
|
|
|
delete regfield; //To avoid memory leak
|
2005-04-01 14:04:50 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2006-12-02 02:26:52 +01:00
|
|
|
else if (regfield->real_type() == MYSQL_TYPE_ENUM &&
|
2000-07-31 21:29:14 +02:00
|
|
|
(field->flags & NOT_NULL_FLAG))
|
|
|
|
{
|
|
|
|
regfield->set_notnull();
|
2005-09-14 00:41:44 +02:00
|
|
|
regfield->store((longlong) 1, TRUE);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else if (type == Field::YES) // Old unireg type
|
2003-03-07 10:39:53 +01:00
|
|
|
regfield->store(ER(ER_YES),(uint) strlen(ER(ER_YES)),system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
else if (type == Field::NO) // Old unireg type
|
2003-03-07 10:39:53 +01:00
|
|
|
regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO)),system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
regfield->reset();
|
|
|
|
}
|
2005-05-16 14:21:35 +02:00
|
|
|
DBUG_ASSERT(data_offset == ((null_count + 7) / 8));
|
2001-12-13 18:06:14 +01:00
|
|
|
|
2005-05-25 17:54:36 +02:00
|
|
|
/*
|
|
|
|
We need to set the unused bits to 1. If the number of bits is a multiple
|
|
|
|
of 8 there are no unused bits.
|
|
|
|
*/
|
|
|
|
if (null_count & 7)
|
2005-05-05 14:17:55 +02:00
|
|
|
*(null_pos + null_count / 8)|= ~(((uchar) 1 << (null_count & 7)) - 1);
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
error= my_write(file, buff, (size_t) reclength,MYF_RW) != 0;
|
2005-04-01 14:04:50 +02:00
|
|
|
|
|
|
|
err:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_free(buff, MYF(MY_FAE));
|
2005-04-01 14:04:50 +02:00
|
|
|
thd->count_cuted_fields= old_count_cuted_fields;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
} /* make_empty_rec */
|