1 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; version 2 of the License. 6 7 This program is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 GNU General Public License for more details. 11 12 You should have received a copy of the GNU General Public License 13 along with this program; if not, write to the Free Software 14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ 15 16 /* Support rutiner with are using with dbug */ 17 18 #include "myisamdef.h" 19 20 /* Print a key in user understandable format */ 21 22 void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, 23 const uchar *key, uint length) 24 { 25 int flag; 26 short int s_1; 27 long int l_1; 28 float f_1; 29 double d_1; 30 const uchar *end; 31 const uchar *key_end=key+length; 32 33 (void) fputs("Key: \"",stream); 34 flag=0; 35 for (; keyseg->type && key < key_end ;keyseg++) 36 { 37 if (flag++) 38 (void) putc('-',stream); 39 end= key+ keyseg->length; 40 if (keyseg->flag & HA_NULL_PART) 41 { 42 /* A NULL value is encoded by a 1-byte flag. Zero means NULL. */ 43 if (! *(key++)) 44 { 45 fprintf(stream,"NULL"); 46 continue; 47 } 48 end++; 49 } 50 51 switch (keyseg->type) { 52 case HA_KEYTYPE_BINARY: 53 if (!(keyseg->flag & HA_SPACE_PACK) && keyseg->length == 1) 54 { /* packed binary digit */ 55 (void) fprintf(stream,"%d",(uint) *key++); 56 break; 57 } 58 /* fall through */ 59 case HA_KEYTYPE_TEXT: 60 case HA_KEYTYPE_NUM: 61 if (keyseg->flag & HA_SPACE_PACK) 62 { 63 (void) fprintf(stream,"%.*s",(int) *key,key+1); 64 key+= (int) *key+1; 65 } 66 else 67 { 68 (void) fprintf(stream,"%.*s",(int) keyseg->length,key); 69 key=end; 70 } 71 break; 72 case HA_KEYTYPE_INT8: 73 (void) fprintf(stream,"%d",(int) *((signed char*) key)); 74 key=end; 75 break; 76 case HA_KEYTYPE_SHORT_INT: 77 s_1= mi_sint2korr(key); 78 (void) fprintf(stream,"%d",(int) s_1); 79 key=end; 80 break; 81 case HA_KEYTYPE_USHORT_INT: 82 { 83 ushort u_1; 84 u_1= mi_uint2korr(key); 85 (void) fprintf(stream,"%u",(uint) u_1); 86 key=end; 87 break; 88 } 89 case HA_KEYTYPE_LONG_INT: 90 l_1=mi_sint4korr(key); 91 (void) fprintf(stream,"%ld",l_1); 92 key=end; 93 break; 94 case HA_KEYTYPE_ULONG_INT: 95 l_1=mi_uint4korr(key); 96 (void) fprintf(stream,"%lu",(ulong) l_1); 97 key=end; 98 break; 99 case HA_KEYTYPE_INT24: 100 (void) fprintf(stream,"%ld",(long) mi_sint3korr(key)); 101 key=end; 102 break; 103 case HA_KEYTYPE_UINT24: 104 (void) fprintf(stream,"%lu",(ulong) mi_uint3korr(key)); 105 key=end; 106 break; 107 case HA_KEYTYPE_FLOAT: 108 mi_float4get(f_1,key); 109 (void) fprintf(stream,"%g",(double) f_1); 110 key=end; 111 break; 112 case HA_KEYTYPE_DOUBLE: 113 mi_float8get(d_1,key); 114 (void) fprintf(stream,"%g",d_1); 115 key=end; 116 break; 117 #ifdef HAVE_LONG_LONG 118 case HA_KEYTYPE_LONGLONG: 119 { 120 char buff[21]; 121 longlong10_to_str(mi_sint8korr(key),buff,-10); 122 (void) fprintf(stream,"%s",buff); 123 key=end; 124 break; 125 } 126 case HA_KEYTYPE_ULONGLONG: 127 { 128 char buff[21]; 129 longlong10_to_str(mi_sint8korr(key),buff,10); 130 (void) fprintf(stream,"%s",buff); 131 key=end; 132 break; 133 } 134 #endif 135 case HA_KEYTYPE_BIT: 136 { 137 uint i; 138 fputs("0x",stream); 139 for (i=0 ; i < keyseg->length ; i++) 140 fprintf(stream, "%02x", (uint) *key++); 141 key= end; 142 break; 143 } 144 case HA_KEYTYPE_VARTEXT1: /* VARCHAR and TEXT */ 145 case HA_KEYTYPE_VARTEXT2: /* VARCHAR and TEXT */ 146 case HA_KEYTYPE_VARBINARY1: /* VARBINARY and BLOB */ 147 case HA_KEYTYPE_VARBINARY2: /* VARBINARY and BLOB */ 148 { 149 uint tmp_length; 150 get_key_length(tmp_length,key); 151 /* 152 The following command sometimes gives a warning from valgrind. 153 Not yet sure if the bug is in valgrind, glibc or mysqld 154 */ 155 (void) fprintf(stream,"%.*s",(int) tmp_length,key); 156 key+=tmp_length; 157 break; 158 } 159 default: break; /* This never happens */ 160 } 161 } 162 (void) fputs("\"\n",stream); 163 return; 164 } /* print_key */ 165 166 167 #ifdef EXTRA_DEBUG 168 /** 169 Check if the named table is in the open list. 170 171 @param[in] name table path as in MYISAM_SHARE::unique_file_name 172 @param[in] where verbal description of caller 173 174 @retval TRUE table is in open list 175 @retval FALSE table is not in open list 176 177 @note This function takes THR_LOCK_myisam. Do not call it when 178 this mutex is locked by this thread already. 179 */ 180 181 my_bool check_table_is_closed(const char *name, const char *where) 182 { 183 char filename[FN_REFLEN]; 184 LIST *pos; 185 DBUG_ENTER("check_table_is_closed"); 186 187 (void) fn_format(filename,name,"",MI_NAME_IEXT,4+16+32); 188 mysql_mutex_lock(&THR_LOCK_myisam); 189 for (pos=myisam_open_list ; pos ; pos=pos->next) 190 { 191 MI_INFO *info=(MI_INFO*) pos->data; 192 MYISAM_SHARE *share=info->s; 193 if (!strcmp(share->unique_file_name,filename)) 194 { 195 if (share->last_version) 196 { 197 mysql_mutex_unlock(&THR_LOCK_myisam); 198 fprintf(stderr,"Warning: Table: %s is open on %s\n", name,where); 199 DBUG_PRINT("warning",("Table: %s is open on %s", name,where)); 200 DBUG_RETURN(1); 201 } 202 } 203 } 204 mysql_mutex_unlock(&THR_LOCK_myisam); 205 DBUG_RETURN(0); 206 } 207 #endif /* EXTRA_DEBUG */ 208