1/***************************************************************************** 2 3Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 5This program is free software; you can redistribute it and/or modify 6it under the terms of the GNU General Public License, version 2.0, 7as published by the Free Software Foundation. 8 9This program is also distributed with certain software (including 10but not limited to OpenSSL) that is licensed under separate terms, 11as designated in a particular file or component or in included license 12documentation. The authors of MySQL hereby grant you an additional 13permission to link the program and your derivative works with the 14separately licensed software that they have included with MySQL. 15 16This program is distributed in the hope that it will be useful, 17but WITHOUT ANY WARRANTY; without even the implied warranty of 18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19GNU General Public License, version 2.0, for more details. 20 21You should have received a copy of the GNU General Public License along with 22this program; if not, write to the Free Software Foundation, Inc., 2351 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 24 25*****************************************************************************/ 26 27/******************************************************************//** 28@file include/fts0priv.ic 29Full text search internal header file 30 31Created 2011/11/12 Sunny Bains 32***********************************************************************/ 33 34/******************************************************************//** 35Write the table id to the given buffer (including final NUL). Buffer must be 36at least FTS_AUX_MIN_TABLE_ID_LENGTH bytes long. 37@return number of bytes written */ 38UNIV_INLINE 39int 40fts_write_object_id( 41/*================*/ 42 ib_id_t id, /* in: a table/index id */ 43 char* str, /* in: buffer to write the id to */ 44 bool hex_format MY_ATTRIBUTE((unused))) 45 /* in: true for fixed hex format, 46 false for old ambiguous format */ 47{ 48 49#ifdef _WIN32 50 51 DBUG_EXECUTE_IF("innodb_test_wrong_non_windows_fts_aux_table_name", 52 return(sprintf(str, UINT64PFx, id));); 53 54 /* Use this to construct old(5.6.14 and 5.7.3) windows 55 ambiguous aux table names */ 56 DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name", 57 return(sprintf(str, "%016llu", id));); 58 59#else /* _WIN32 */ 60 61 /* Use this to construct old(5.6.14 and 5.7.3) windows 62 ambiguous aux table names */ 63 DBUG_EXECUTE_IF("innodb_test_wrong_windows_fts_aux_table_name", 64 return(sprintf(str, "%016" PRIu64, id));); 65 66 DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name", 67 return(sprintf(str, UINT64PFx, id));); 68 69#endif /* _WIN32 */ 70 71 /* As above, but this is only for those tables failing to rename. */ 72 if (!hex_format) { 73#ifdef _WIN32 74 // FIXME: Use ut_snprintf(), so does following one. 75 return(sprintf(str, "%016llu", id)); 76#else /* _WIN32 */ 77 return(sprintf(str, "%016" PRIu64, id)); 78#endif /* _WIN32 */ 79 } 80 81 return(sprintf(str, UINT64PFx, id)); 82} 83 84/******************************************************************//** 85Read the table id from the string generated by fts_write_object_id(). 86@return TRUE if parse successful */ 87UNIV_INLINE 88ibool 89fts_read_object_id( 90/*===============*/ 91 ib_id_t* id, /* out: an id */ 92 const char* str) /* in: buffer to read from */ 93{ 94 /* NOTE: this func doesn't care about whether current table 95 is set with HEX_NAME, the user of the id read here will check 96 if the id is HEX or DEC and do the right thing with it. */ 97 return(sscanf(str, UINT64PFx, id) == 1); 98} 99 100/******************************************************************//** 101Compare two fts_trx_table_t instances. 102@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */ 103UNIV_INLINE 104int 105fts_trx_table_cmp( 106/*==============*/ 107 const void* p1, /*!< in: id1 */ 108 const void* p2) /*!< in: id2 */ 109{ 110 const dict_table_t* table1 = (*(const fts_trx_table_t**) p1)->table; 111 const dict_table_t* table2 = (*(const fts_trx_table_t**) p2)->table; 112 113 return((table1->id > table2->id) 114 ? 1 115 : (table1->id == table2->id) 116 ? 0 117 : -1); 118} 119 120/******************************************************************//** 121Compare a table id with a fts_trx_table_t table id. 122@return < 0 if n1 < n2, 0 if n1 == n2,> 0 if n1 > n2 */ 123UNIV_INLINE 124int 125fts_trx_table_id_cmp( 126/*=================*/ 127 const void* p1, /*!< in: id1 */ 128 const void* p2) /*!< in: id2 */ 129{ 130 const ullint* table_id = (const ullint*) p1; 131 const dict_table_t* table2 = (*(const fts_trx_table_t**) p2)->table; 132 133 return((*table_id > table2->id) 134 ? 1 135 : (*table_id == table2->id) 136 ? 0 137 : -1); 138} 139