You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

846 lines
24 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
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
19 years ago
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
19 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
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
19 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
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
19 years ago
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
19 years ago
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
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
19 years ago
26 years ago
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
21 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. /* Copyright (C) 2000-2003 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /**
  13. @file
  14. @brief
  15. Functions to copy data to or from fields
  16. This could be done with a single short function but opencoding this
  17. gives much more speed.
  18. */
  19. #include "sql_priv.h"
  20. #include "sql_class.h" // THD
  21. #include <m_ctype.h>
  22. static void do_field_eq(Copy_field *copy)
  23. {
  24. memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
  25. }
  26. static void do_field_1(Copy_field *copy)
  27. {
  28. copy->to_ptr[0]=copy->from_ptr[0];
  29. }
  30. static void do_field_2(Copy_field *copy)
  31. {
  32. copy->to_ptr[0]=copy->from_ptr[0];
  33. copy->to_ptr[1]=copy->from_ptr[1];
  34. }
  35. static void do_field_3(Copy_field *copy)
  36. {
  37. copy->to_ptr[0]=copy->from_ptr[0];
  38. copy->to_ptr[1]=copy->from_ptr[1];
  39. copy->to_ptr[2]=copy->from_ptr[2];
  40. }
  41. static void do_field_4(Copy_field *copy)
  42. {
  43. copy->to_ptr[0]=copy->from_ptr[0];
  44. copy->to_ptr[1]=copy->from_ptr[1];
  45. copy->to_ptr[2]=copy->from_ptr[2];
  46. copy->to_ptr[3]=copy->from_ptr[3];
  47. }
  48. static void do_field_6(Copy_field *copy)
  49. { // For blob field
  50. copy->to_ptr[0]=copy->from_ptr[0];
  51. copy->to_ptr[1]=copy->from_ptr[1];
  52. copy->to_ptr[2]=copy->from_ptr[2];
  53. copy->to_ptr[3]=copy->from_ptr[3];
  54. copy->to_ptr[4]=copy->from_ptr[4];
  55. copy->to_ptr[5]=copy->from_ptr[5];
  56. }
  57. static void do_field_8(Copy_field *copy)
  58. {
  59. copy->to_ptr[0]=copy->from_ptr[0];
  60. copy->to_ptr[1]=copy->from_ptr[1];
  61. copy->to_ptr[2]=copy->from_ptr[2];
  62. copy->to_ptr[3]=copy->from_ptr[3];
  63. copy->to_ptr[4]=copy->from_ptr[4];
  64. copy->to_ptr[5]=copy->from_ptr[5];
  65. copy->to_ptr[6]=copy->from_ptr[6];
  66. copy->to_ptr[7]=copy->from_ptr[7];
  67. }
  68. static void do_field_to_null_str(Copy_field *copy)
  69. {
  70. if (*copy->from_null_ptr & copy->from_bit)
  71. {
  72. bzero(copy->to_ptr,copy->from_length);
  73. copy->to_null_ptr[0]=1; // Always bit 1
  74. }
  75. else
  76. {
  77. copy->to_null_ptr[0]=0;
  78. memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
  79. }
  80. }
  81. static void do_outer_field_to_null_str(Copy_field *copy)
  82. {
  83. if (*copy->null_row ||
  84. (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
  85. {
  86. bzero(copy->to_ptr,copy->from_length);
  87. copy->to_null_ptr[0]=1; // Always bit 1
  88. }
  89. else
  90. {
  91. copy->to_null_ptr[0]=0;
  92. memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
  93. }
  94. }
  95. int
  96. set_field_to_null(Field *field)
  97. {
  98. if (field->real_maybe_null())
  99. {
  100. field->set_null();
  101. field->reset();
  102. return 0;
  103. }
  104. field->reset();
  105. switch (field->table->in_use->count_cuted_fields) {
  106. case CHECK_FIELD_WARN:
  107. field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
  108. /* fall through */
  109. case CHECK_FIELD_IGNORE:
  110. return 0;
  111. case CHECK_FIELD_ERROR_FOR_NULL:
  112. if (!field->table->in_use->no_errors)
  113. my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
  114. return -1;
  115. }
  116. DBUG_ASSERT(0); // impossible
  117. return -1;
  118. }
  119. /**
  120. Set field to NULL or TIMESTAMP or to next auto_increment number.
  121. @param field Field to update
  122. @param no_conversions Set to 1 if we should return 1 if field can't
  123. take null values.
  124. If set to 0 we will do store the 'default value'
  125. if the field is a special field. If not we will
  126. give an error.
  127. @retval
  128. 0 Field could take 0 or an automatic conversion was used
  129. @retval
  130. -1 Field could not take NULL and no conversion was used.
  131. If no_conversion was not set, an error message is printed
  132. */
  133. int
  134. set_field_to_null_with_conversions(Field *field, bool no_conversions)
  135. {
  136. if (field->real_maybe_null())
  137. {
  138. field->set_null();
  139. field->reset();
  140. return 0;
  141. }
  142. if (no_conversions)
  143. return -1;
  144. /*
  145. Check if this is a special type, which will get a special walue
  146. when set to NULL (TIMESTAMP fields which allow setting to NULL
  147. are handled by first check).
  148. */
  149. if (field->type() == MYSQL_TYPE_TIMESTAMP)
  150. {
  151. ((Field_timestamp*) field)->set_time();
  152. return 0; // Ok to set time to NULL
  153. }
  154. field->reset();
  155. if (field == field->table->next_number_field)
  156. {
  157. field->table->auto_increment_field_not_null= FALSE;
  158. return 0; // field is set in fill_record()
  159. }
  160. switch (field->table->in_use->count_cuted_fields) {
  161. case CHECK_FIELD_WARN:
  162. field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
  163. /* fall through */
  164. case CHECK_FIELD_IGNORE:
  165. return 0;
  166. case CHECK_FIELD_ERROR_FOR_NULL:
  167. if (!field->table->in_use->no_errors)
  168. my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
  169. return -1;
  170. }
  171. DBUG_ASSERT(0); // impossible
  172. return -1;
  173. }
  174. static void do_skip(Copy_field *copy __attribute__((unused)))
  175. {
  176. }
  177. static void do_copy_null(Copy_field *copy)
  178. {
  179. if (*copy->from_null_ptr & copy->from_bit)
  180. {
  181. *copy->to_null_ptr|=copy->to_bit;
  182. copy->to_field->reset();
  183. }
  184. else
  185. {
  186. *copy->to_null_ptr&= ~copy->to_bit;
  187. (copy->do_copy2)(copy);
  188. }
  189. }
  190. static void do_outer_field_null(Copy_field *copy)
  191. {
  192. if (*copy->null_row ||
  193. (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
  194. {
  195. *copy->to_null_ptr|=copy->to_bit;
  196. copy->to_field->reset();
  197. }
  198. else
  199. {
  200. *copy->to_null_ptr&= ~copy->to_bit;
  201. (copy->do_copy2)(copy);
  202. }
  203. }
  204. static void do_copy_not_null(Copy_field *copy)
  205. {
  206. if (*copy->from_null_ptr & copy->from_bit)
  207. {
  208. copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
  209. WARN_DATA_TRUNCATED, 1);
  210. copy->to_field->reset();
  211. }
  212. else
  213. (copy->do_copy2)(copy);
  214. }
  215. static void do_copy_maybe_null(Copy_field *copy)
  216. {
  217. *copy->to_null_ptr&= ~copy->to_bit;
  218. (copy->do_copy2)(copy);
  219. }
  220. /* timestamp and next_number has special handling in case of NULL values */
  221. static void do_copy_timestamp(Copy_field *copy)
  222. {
  223. if (*copy->from_null_ptr & copy->from_bit)
  224. {
  225. /* Same as in set_field_to_null_with_conversions() */
  226. ((Field_timestamp*) copy->to_field)->set_time();
  227. }
  228. else
  229. (copy->do_copy2)(copy);
  230. }
  231. static void do_copy_next_number(Copy_field *copy)
  232. {
  233. if (*copy->from_null_ptr & copy->from_bit)
  234. {
  235. /* Same as in set_field_to_null_with_conversions() */
  236. copy->to_field->table->auto_increment_field_not_null= FALSE;
  237. copy->to_field->reset();
  238. }
  239. else
  240. (copy->do_copy2)(copy);
  241. }
  242. static void do_copy_blob(Copy_field *copy)
  243. {
  244. ulong length=((Field_blob*) copy->from_field)->get_length();
  245. ((Field_blob*) copy->to_field)->store_length(length);
  246. memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*));
  247. }
  248. static void do_conv_blob(Copy_field *copy)
  249. {
  250. copy->from_field->val_str(&copy->tmp);
  251. ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
  252. copy->tmp.length(),
  253. copy->tmp.charset());
  254. }
  255. /** Save blob in copy->tmp for GROUP BY. */
  256. static void do_save_blob(Copy_field *copy)
  257. {
  258. char buff[MAX_FIELD_WIDTH];
  259. String res(buff,sizeof(buff),copy->tmp.charset());
  260. copy->from_field->val_str(&res);
  261. copy->tmp.copy(res);
  262. ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
  263. copy->tmp.length(),
  264. copy->tmp.charset());
  265. }
  266. static void do_field_string(Copy_field *copy)
  267. {
  268. char buff[MAX_FIELD_WIDTH];
  269. copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
  270. copy->from_field->val_str(&copy->tmp);
  271. copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(),
  272. copy->tmp.charset());
  273. }
  274. static void do_field_enum(Copy_field *copy)
  275. {
  276. if (copy->from_field->val_int() == 0)
  277. ((Field_enum *) copy->to_field)->store_type((ulonglong) 0);
  278. else
  279. do_field_string(copy);
  280. }
  281. static void do_field_varbinary_pre50(Copy_field *copy)
  282. {
  283. char buff[MAX_FIELD_WIDTH];
  284. copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
  285. copy->from_field->val_str(&copy->tmp);
  286. /* Use the same function as in 4.1 to trim trailing spaces */
  287. uint length= my_lengthsp_8bit(&my_charset_bin, copy->tmp.c_ptr_quick(),
  288. copy->from_field->field_length);
  289. copy->to_field->store(copy->tmp.c_ptr_quick(), length,
  290. copy->tmp.charset());
  291. }
  292. static void do_field_int(Copy_field *copy)
  293. {
  294. longlong value= copy->from_field->val_int();
  295. copy->to_field->store(value,
  296. test(copy->from_field->flags & UNSIGNED_FLAG));
  297. }
  298. static void do_field_real(Copy_field *copy)
  299. {
  300. double value=copy->from_field->val_real();
  301. copy->to_field->store(value);
  302. }
  303. static void do_field_decimal(Copy_field *copy)
  304. {
  305. my_decimal value;
  306. copy->to_field->store_decimal(copy->from_field->val_decimal(&value));
  307. }
  308. /**
  309. string copy for single byte characters set when to string is shorter than
  310. from string.
  311. */
  312. static void do_cut_string(Copy_field *copy)
  313. {
  314. CHARSET_INFO *cs= copy->from_field->charset();
  315. memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
  316. /* Check if we loosed any important characters */
  317. if (cs->cset->scan(cs,
  318. (char*) copy->from_ptr + copy->to_length,
  319. (char*) copy->from_ptr + copy->from_length,
  320. MY_SEQ_SPACES) < copy->from_length - copy->to_length)
  321. {
  322. copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
  323. WARN_DATA_TRUNCATED, 1);
  324. }
  325. }
  326. /**
  327. string copy for multi byte characters set when to string is shorter than
  328. from string.
  329. */
  330. static void do_cut_string_complex(Copy_field *copy)
  331. { // Shorter string field
  332. int well_formed_error;
  333. CHARSET_INFO *cs= copy->from_field->charset();
  334. const uchar *from_end= copy->from_ptr + copy->from_length;
  335. uint copy_length= cs->cset->well_formed_len(cs,
  336. (char*) copy->from_ptr,
  337. (char*) from_end,
  338. copy->to_length / cs->mbmaxlen,
  339. &well_formed_error);
  340. if (copy->to_length < copy_length)
  341. copy_length= copy->to_length;
  342. memcpy(copy->to_ptr, copy->from_ptr, copy_length);
  343. /* Check if we lost any important characters */
  344. if (well_formed_error ||
  345. cs->cset->scan(cs, (char*) copy->from_ptr + copy_length,
  346. (char*) from_end,
  347. MY_SEQ_SPACES) < (copy->from_length - copy_length))
  348. {
  349. copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
  350. WARN_DATA_TRUNCATED, 1);
  351. }
  352. if (copy_length < copy->to_length)
  353. cs->cset->fill(cs, (char*) copy->to_ptr + copy_length,
  354. copy->to_length - copy_length, ' ');
  355. }
  356. static void do_expand_binary(Copy_field *copy)
  357. {
  358. CHARSET_INFO *cs= copy->from_field->charset();
  359. memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
  360. cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
  361. copy->to_length-copy->from_length, '\0');
  362. }
  363. static void do_expand_string(Copy_field *copy)
  364. {
  365. CHARSET_INFO *cs= copy->from_field->charset();
  366. memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
  367. cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
  368. copy->to_length-copy->from_length, ' ');
  369. }
  370. static void do_varstring1(Copy_field *copy)
  371. {
  372. uint length= (uint) *(uchar*) copy->from_ptr;
  373. if (length > copy->to_length- 1)
  374. {
  375. length=copy->to_length - 1;
  376. if (copy->from_field->table->in_use->count_cuted_fields)
  377. copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
  378. WARN_DATA_TRUNCATED, 1);
  379. }
  380. *(uchar*) copy->to_ptr= (uchar) length;
  381. memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
  382. }
  383. static void do_varstring1_mb(Copy_field *copy)
  384. {
  385. int well_formed_error;
  386. CHARSET_INFO *cs= copy->from_field->charset();
  387. uint from_length= (uint) *(uchar*) copy->from_ptr;
  388. const uchar *from_ptr= copy->from_ptr + 1;
  389. uint to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
  390. uint length= cs->cset->well_formed_len(cs, (char*) from_ptr,
  391. (char*) from_ptr + from_length,
  392. to_char_length, &well_formed_error);
  393. if (length < from_length)
  394. {
  395. if (current_thd->count_cuted_fields)
  396. copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
  397. WARN_DATA_TRUNCATED, 1);
  398. }
  399. *copy->to_ptr= (uchar) length;
  400. memcpy(copy->to_ptr + 1, from_ptr, length);
  401. }
  402. static void do_varstring2(Copy_field *copy)
  403. {
  404. uint length=uint2korr(copy->from_ptr);
  405. if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
  406. {
  407. length=copy->to_length-HA_KEY_BLOB_LENGTH;
  408. if (copy->from_field->table->in_use->count_cuted_fields)
  409. copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
  410. WARN_DATA_TRUNCATED, 1);
  411. }
  412. int2store(copy->to_ptr,length);
  413. memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, copy->from_ptr + HA_KEY_BLOB_LENGTH,
  414. length);
  415. }
  416. static void do_varstring2_mb(Copy_field *copy)
  417. {
  418. int well_formed_error;
  419. CHARSET_INFO *cs= copy->from_field->charset();
  420. uint char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
  421. uint from_length= uint2korr(copy->from_ptr);
  422. const uchar *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
  423. uint length= cs->cset->well_formed_len(cs, (char*) from_beg,
  424. (char*) from_beg + from_length,
  425. char_length, &well_formed_error);
  426. if (length < from_length)
  427. {
  428. if (current_thd->count_cuted_fields)
  429. copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
  430. WARN_DATA_TRUNCATED, 1);
  431. }
  432. int2store(copy->to_ptr, length);
  433. memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
  434. }
  435. /***************************************************************************
  436. ** The different functions that fills in a Copy_field class
  437. ***************************************************************************/
  438. /**
  439. copy of field to maybe null string.
  440. If field is null then the all bytes are set to 0.
  441. if field is not null then the first byte is set to 1 and the rest of the
  442. string is the field value.
  443. The 'to' buffer should have a size of field->pack_length()+1
  444. */
  445. void Copy_field::set(uchar *to,Field *from)
  446. {
  447. from_ptr=from->ptr;
  448. to_ptr=to;
  449. from_length=from->pack_length();
  450. if (from->maybe_null())
  451. {
  452. from_null_ptr=from->null_ptr;
  453. from_bit= from->null_bit;
  454. to_ptr[0]= 1; // Null as default value
  455. to_null_ptr= (uchar*) to_ptr++;
  456. to_bit= 1;
  457. if (from->table->maybe_null)
  458. {
  459. null_row= &from->table->null_row;
  460. do_copy= do_outer_field_to_null_str;
  461. }
  462. else
  463. do_copy= do_field_to_null_str;
  464. }
  465. else
  466. {
  467. to_null_ptr= 0; // For easy debugging
  468. do_copy= do_field_eq;
  469. }
  470. }
  471. /*
  472. To do:
  473. If 'save\ is set to true and the 'from' is a blob field, do_copy is set to
  474. do_save_blob rather than do_conv_blob. The only differences between them
  475. appears to be:
  476. - do_save_blob allocates and uses an intermediate buffer before calling
  477. Field_blob::store. Is this in order to trigger the call to
  478. well_formed_copy_nchars, by changing the pointer copy->tmp.ptr()?
  479. That call will take place anyway in all known cases.
  480. - The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
  481. effect? Truncation is handled by well_formed_copy_nchars anyway.
  482. */
  483. void Copy_field::set(Field *to,Field *from,bool save)
  484. {
  485. if (to->type() == MYSQL_TYPE_NULL)
  486. {
  487. to_null_ptr=0; // For easy debugging
  488. to_ptr=0;
  489. do_copy=do_skip;
  490. return;
  491. }
  492. from_field=from;
  493. to_field=to;
  494. from_ptr=from->ptr;
  495. from_length=from->pack_length();
  496. to_ptr= to->ptr;
  497. to_length=to_field->pack_length();
  498. // set up null handling
  499. from_null_ptr=to_null_ptr=0;
  500. if (from->maybe_null())
  501. {
  502. from_null_ptr= from->null_ptr;
  503. from_bit= from->null_bit;
  504. if (to_field->real_maybe_null())
  505. {
  506. to_null_ptr= to->null_ptr;
  507. to_bit= to->null_bit;
  508. if (from_null_ptr)
  509. do_copy= do_copy_null;
  510. else
  511. {
  512. null_row= &from->table->null_row;
  513. do_copy= do_outer_field_null;
  514. }
  515. }
  516. else
  517. {
  518. if (to_field->type() == MYSQL_TYPE_TIMESTAMP)
  519. do_copy= do_copy_timestamp; // Automatic timestamp
  520. else if (to_field == to_field->table->next_number_field)
  521. do_copy= do_copy_next_number;
  522. else
  523. do_copy= do_copy_not_null;
  524. }
  525. }
  526. else if (to_field->real_maybe_null())
  527. {
  528. to_null_ptr= to->null_ptr;
  529. to_bit= to->null_bit;
  530. do_copy= do_copy_maybe_null;
  531. }
  532. else
  533. do_copy=0;
  534. if ((to->flags & BLOB_FLAG) && save)
  535. do_copy2= do_save_blob;
  536. else
  537. do_copy2= get_copy_func(to,from);
  538. if (!do_copy) // Not null
  539. do_copy=do_copy2;
  540. }
  541. Copy_field::Copy_func *
  542. Copy_field::get_copy_func(Field *to,Field *from)
  543. {
  544. bool compatible_db_low_byte_first= (to->table->s->db_low_byte_first ==
  545. from->table->s->db_low_byte_first);
  546. if (to->flags & BLOB_FLAG)
  547. {
  548. if (!(from->flags & BLOB_FLAG) || from->charset() != to->charset())
  549. return do_conv_blob;
  550. if (from_length != to_length || !compatible_db_low_byte_first)
  551. {
  552. // Correct pointer to point at char pointer
  553. to_ptr+= to_length - to->table->s->blob_ptr_size;
  554. from_ptr+= from_length- from->table->s->blob_ptr_size;
  555. return do_copy_blob;
  556. }
  557. }
  558. else
  559. {
  560. if (to->real_type() == MYSQL_TYPE_BIT ||
  561. from->real_type() == MYSQL_TYPE_BIT)
  562. return do_field_int;
  563. if (to->result_type() == DECIMAL_RESULT)
  564. return do_field_decimal;
  565. // Check if identical fields
  566. if (from->result_type() == STRING_RESULT)
  567. {
  568. /*
  569. Detect copy from pre 5.0 varbinary to varbinary as of 5.0 and
  570. use special copy function that removes trailing spaces and thus
  571. repairs data.
  572. */
  573. if (from->type() == MYSQL_TYPE_VAR_STRING && !from->has_charset() &&
  574. to->type() == MYSQL_TYPE_VARCHAR && !to->has_charset())
  575. return do_field_varbinary_pre50;
  576. /*
  577. If we are copying date or datetime's we have to check the dates
  578. if we don't allow 'all' dates.
  579. */
  580. if (to->real_type() != from->real_type() ||
  581. !compatible_db_low_byte_first ||
  582. (((to->table->in_use->variables.sql_mode &
  583. (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) &&
  584. to->type() == MYSQL_TYPE_DATE) ||
  585. to->type() == MYSQL_TYPE_DATETIME))
  586. {
  587. if (from->real_type() == MYSQL_TYPE_ENUM ||
  588. from->real_type() == MYSQL_TYPE_SET)
  589. if (to->result_type() != STRING_RESULT)
  590. return do_field_int; // Convert SET to number
  591. return do_field_string;
  592. }
  593. if (to->real_type() == MYSQL_TYPE_ENUM ||
  594. to->real_type() == MYSQL_TYPE_SET)
  595. {
  596. if (!to->eq_def(from))
  597. {
  598. if (from->real_type() == MYSQL_TYPE_ENUM &&
  599. to->real_type() == MYSQL_TYPE_ENUM)
  600. return do_field_enum;
  601. else
  602. return do_field_string;
  603. }
  604. }
  605. else if (to->charset() != from->charset())
  606. return do_field_string;
  607. else if (to->real_type() == MYSQL_TYPE_VARCHAR)
  608. {
  609. if (((Field_varstring*) to)->length_bytes !=
  610. ((Field_varstring*) from)->length_bytes)
  611. return do_field_string;
  612. if (to_length != from_length)
  613. return (((Field_varstring*) to)->length_bytes == 1 ?
  614. (from->charset()->mbmaxlen == 1 ? do_varstring1 :
  615. do_varstring1_mb) :
  616. (from->charset()->mbmaxlen == 1 ? do_varstring2 :
  617. do_varstring2_mb));
  618. }
  619. else if (to_length < from_length)
  620. return (from->charset()->mbmaxlen == 1 ?
  621. do_cut_string : do_cut_string_complex);
  622. else if (to_length > from_length)
  623. {
  624. if (to->charset() == &my_charset_bin)
  625. return do_expand_binary;
  626. else
  627. return do_expand_string;
  628. }
  629. }
  630. else if (to->real_type() != from->real_type() ||
  631. to_length != from_length ||
  632. !compatible_db_low_byte_first)
  633. {
  634. if (to->real_type() == MYSQL_TYPE_DECIMAL ||
  635. to->result_type() == STRING_RESULT)
  636. return do_field_string;
  637. if (to->result_type() == INT_RESULT)
  638. return do_field_int;
  639. return do_field_real;
  640. }
  641. else
  642. {
  643. if (!to->eq_def(from) || !compatible_db_low_byte_first)
  644. {
  645. if (to->real_type() == MYSQL_TYPE_DECIMAL)
  646. return do_field_string;
  647. if (to->result_type() == INT_RESULT)
  648. return do_field_int;
  649. else
  650. return do_field_real;
  651. }
  652. }
  653. }
  654. /* Eq fields */
  655. switch (to_length) {
  656. case 1: return do_field_1;
  657. case 2: return do_field_2;
  658. case 3: return do_field_3;
  659. case 4: return do_field_4;
  660. case 6: return do_field_6;
  661. case 8: return do_field_8;
  662. }
  663. return do_field_eq;
  664. }
  665. /** Simple quick field convert that is called on insert. */
  666. int field_conv(Field *to,Field *from)
  667. {
  668. if (to->real_type() == from->real_type() &&
  669. !(to->type() == MYSQL_TYPE_BLOB && to->table->copy_blobs))
  670. {
  671. if (to->pack_length() == from->pack_length() &&
  672. !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
  673. to->real_type() != MYSQL_TYPE_ENUM &&
  674. to->real_type() != MYSQL_TYPE_SET &&
  675. to->real_type() != MYSQL_TYPE_BIT &&
  676. (to->real_type() != MYSQL_TYPE_NEWDECIMAL ||
  677. (to->field_length == from->field_length &&
  678. (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
  679. from->charset() == to->charset() &&
  680. to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
  681. (!(to->table->in_use->variables.sql_mode &
  682. (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) ||
  683. (to->type() != MYSQL_TYPE_DATE &&
  684. to->type() != MYSQL_TYPE_DATETIME)) &&
  685. (from->real_type() != MYSQL_TYPE_VARCHAR ||
  686. ((Field_varstring*)from)->length_bytes ==
  687. ((Field_varstring*)to)->length_bytes))
  688. { // Identical fields
  689. #ifdef HAVE_purify
  690. /* This may happen if one does 'UPDATE ... SET x=x' */
  691. if (to->ptr != from->ptr)
  692. #endif
  693. memcpy(to->ptr,from->ptr,to->pack_length());
  694. return 0;
  695. }
  696. }
  697. if (to->type() == MYSQL_TYPE_BLOB)
  698. { // Be sure the value is stored
  699. Field_blob *blob=(Field_blob*) to;
  700. from->val_str(&blob->value);
  701. /*
  702. Copy value if copy_blobs is set, or source is not a string and
  703. we have a pointer to its internal string conversion buffer.
  704. */
  705. if (to->table->copy_blobs ||
  706. (!blob->value.is_alloced() &&
  707. from->real_type() != MYSQL_TYPE_STRING &&
  708. from->real_type() != MYSQL_TYPE_VARCHAR))
  709. blob->value.copy();
  710. return blob->store(blob->value.ptr(),blob->value.length(),from->charset());
  711. }
  712. if (from->real_type() == MYSQL_TYPE_ENUM &&
  713. to->real_type() == MYSQL_TYPE_ENUM &&
  714. from->val_int() == 0)
  715. {
  716. ((Field_enum *)(to))->store_type(0);
  717. return 0;
  718. }
  719. else if ((from->result_type() == STRING_RESULT &&
  720. (to->result_type() == STRING_RESULT ||
  721. (from->real_type() != MYSQL_TYPE_ENUM &&
  722. from->real_type() != MYSQL_TYPE_SET))) ||
  723. to->type() == MYSQL_TYPE_DECIMAL)
  724. {
  725. char buff[MAX_FIELD_WIDTH];
  726. String result(buff,sizeof(buff),from->charset());
  727. from->val_str(&result);
  728. /*
  729. We use c_ptr_quick() here to make it easier if to is a float/double
  730. as the conversion routines will do a copy of the result doesn't
  731. end with \0. Can be replaced with .ptr() when we have our own
  732. string->double conversion.
  733. */
  734. return to->store(result.c_ptr_quick(),result.length(),from->charset());
  735. }
  736. else if (from->result_type() == REAL_RESULT)
  737. return to->store(from->val_real());
  738. else if (from->result_type() == DECIMAL_RESULT)
  739. {
  740. my_decimal buff;
  741. return to->store_decimal(from->val_decimal(&buff));
  742. }
  743. else
  744. return to->store(from->val_int(), test(from->flags & UNSIGNED_FLAG));
  745. }