1/***************************************************************************** 2 3Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved. 4Copyright (c) 2020, MariaDB Corporation. 5 6This program is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free Software 8Foundation; version 2 of the License. 9 10This program is distributed in the hope that it will be useful, but WITHOUT 11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 14You should have received a copy of the GNU General Public License along with 15this program; if not, write to the Free Software Foundation, Inc., 1651 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA 17 18*****************************************************************************/ 19 20/*******************************************************************//** 21@file include/rem0cmp.ic 22Comparison services for records 23 24Created 7/1/1994 Heikki Tuuri 25************************************************************************/ 26 27#include <mysql_com.h> 28#include <my_sys.h> 29 30/** Compare two data fields. 31@param[in] dfield1 data field; must have type field set 32@param[in] dfield2 data field 33@return the comparison result of dfield1 and dfield2 34@retval 0 if dfield1 is equal to dfield2 35@retval negative if dfield1 is less than dfield2 36@retval positive if dfield1 is greater than dfield2 */ 37UNIV_INLINE 38int 39cmp_dfield_dfield( 40 const dfield_t* dfield1, 41 const dfield_t* dfield2) 42{ 43 const dtype_t* type; 44 45 ut_ad(dfield_check_typed(dfield1)); 46 47 type = dfield_get_type(dfield1); 48 49 return(cmp_data_data(type->mtype, type->prtype, 50 (const byte*) dfield_get_data(dfield1), 51 dfield_get_len(dfield1), 52 (const byte*) dfield_get_data(dfield2), 53 dfield_get_len(dfield2))); 54} 55 56/** Compare two data fields. 57@param[in] dfield1 data field 58@param[in] dfield2 data field 59@return the comparison result of dfield1 and dfield2 60@retval 0 if dfield1 is equal to dfield2, or a prefix of dfield1 61@retval negative if dfield1 is less than dfield2 62@retval positive if dfield1 is greater than dfield2 */ 63UNIV_INLINE 64int 65cmp_dfield_dfield_like_prefix( 66 const dfield_t* dfield1, 67 const dfield_t* dfield2) 68{ 69 const dtype_t* type; 70 71 ut_ad(dfield_check_typed(dfield1)); 72 ut_ad(dfield_check_typed(dfield2)); 73 74 type = dfield_get_type(dfield1); 75 76#ifdef UNIV_DEBUG 77 switch (type->prtype & DATA_MYSQL_TYPE_MASK) { 78 case MYSQL_TYPE_BIT: 79 case MYSQL_TYPE_STRING: 80 case MYSQL_TYPE_VAR_STRING: 81 case MYSQL_TYPE_TINY_BLOB: 82 case MYSQL_TYPE_MEDIUM_BLOB: 83 case MYSQL_TYPE_BLOB: 84 case MYSQL_TYPE_LONG_BLOB: 85 case MYSQL_TYPE_VARCHAR: 86 break; 87 default: 88 ut_error; 89 } 90#endif /* UNIV_DEBUG */ 91 92 uint cs_num = (uint) dtype_get_charset_coll(type->prtype); 93 94 if (CHARSET_INFO* cs = get_charset(cs_num, MYF(MY_WME))) { 95 return(cs->strnncoll( 96 static_cast<const uchar*>( 97 dfield_get_data(dfield1)), 98 dfield_get_len(dfield1), 99 static_cast<const uchar*>( 100 dfield_get_data(dfield2)), 101 dfield_get_len(dfield2), 102 1)); 103 } 104 105 ib::fatal() << "Unable to find charset-collation " << cs_num; 106 return(0); 107} 108