MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mi_dbug.c
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-1301 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  if (keyseg->flag & HA_NULL_PART)
40  {
41  /* A NULL value is encoded by a 1-byte flag. Zero means NULL. */
42  if (! *(key++))
43  {
44  fprintf(stream,"NULL");
45  continue;
46  }
47  }
48  end= key + keyseg->length;
49 
50  switch (keyseg->type) {
51  case HA_KEYTYPE_BINARY:
52  if (!(keyseg->flag & HA_SPACE_PACK) && keyseg->length == 1)
53  { /* packed binary digit */
54  (void) fprintf(stream,"%d",(uint) *key++);
55  break;
56  }
57  /* fall through */
58  case HA_KEYTYPE_TEXT:
59  case HA_KEYTYPE_NUM:
60  if (keyseg->flag & HA_SPACE_PACK)
61  {
62  (void) fprintf(stream,"%.*s",(int) *key,key+1);
63  key+= (int) *key+1;
64  }
65  else
66  {
67  (void) fprintf(stream,"%.*s",(int) keyseg->length,key);
68  key=end;
69  }
70  break;
71  case HA_KEYTYPE_INT8:
72  (void) fprintf(stream,"%d",(int) *((signed char*) key));
73  key=end;
74  break;
75  case HA_KEYTYPE_SHORT_INT:
76  s_1= mi_sint2korr(key);
77  (void) fprintf(stream,"%d",(int) s_1);
78  key=end;
79  break;
80  case HA_KEYTYPE_USHORT_INT:
81  {
82  ushort u_1;
83  u_1= mi_uint2korr(key);
84  (void) fprintf(stream,"%u",(uint) u_1);
85  key=end;
86  break;
87  }
88  case HA_KEYTYPE_LONG_INT:
89  l_1=mi_sint4korr(key);
90  (void) fprintf(stream,"%ld",l_1);
91  key=end;
92  break;
93  case HA_KEYTYPE_ULONG_INT:
94  l_1=mi_sint4korr(key);
95  (void) fprintf(stream,"%lu",(ulong) l_1);
96  key=end;
97  break;
98  case HA_KEYTYPE_INT24:
99  (void) fprintf(stream,"%ld",(long) mi_sint3korr(key));
100  key=end;
101  break;
102  case HA_KEYTYPE_UINT24:
103  (void) fprintf(stream,"%lu",(ulong) mi_uint3korr(key));
104  key=end;
105  break;
106  case HA_KEYTYPE_FLOAT:
107  mi_float4get(f_1,key);
108  (void) fprintf(stream,"%g",(double) f_1);
109  key=end;
110  break;
111  case HA_KEYTYPE_DOUBLE:
112  mi_float8get(d_1,key);
113  (void) fprintf(stream,"%g",d_1);
114  key=end;
115  break;
116 #ifdef HAVE_LONG_LONG
117  case HA_KEYTYPE_LONGLONG:
118  {
119  char buff[21];
120  longlong2str(mi_sint8korr(key),buff,-10);
121  (void) fprintf(stream,"%s",buff);
122  key=end;
123  break;
124  }
125  case HA_KEYTYPE_ULONGLONG:
126  {
127  char buff[21];
128  longlong2str(mi_sint8korr(key),buff,10);
129  (void) fprintf(stream,"%s",buff);
130  key=end;
131  break;
132  }
133  case HA_KEYTYPE_BIT:
134  {
135  uint i;
136  fputs("0x",stream);
137  for (i=0 ; i < keyseg->length ; i++)
138  fprintf(stream, "%02x", (uint) *key++);
139  key= end;
140  break;
141  }
142 
143 #endif
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 
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 */