~vadim-tk/percona-server/percona-galera-5.1.57

« back to all changes in this revision

Viewing changes to storage/myisam/mi_dbug.c

  • Committer: root
  • Date: 2011-07-10 16:09:24 UTC
  • Revision ID: root@r815.office.percona.com-20110710160924-fyffqsbaclgu6vui
Initial port

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2005 MySQL AB
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
    }
 
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
 
 
169
my_bool check_table_is_closed(const char *name, const char *where)
 
170
{
 
171
  char filename[FN_REFLEN];
 
172
  LIST *pos;
 
173
  DBUG_ENTER("check_table_is_closed");
 
174
 
 
175
  (void) fn_format(filename,name,"",MI_NAME_IEXT,4+16+32);
 
176
  for (pos=myisam_open_list ; pos ; pos=pos->next)
 
177
  {
 
178
    MI_INFO *info=(MI_INFO*) pos->data;
 
179
    MYISAM_SHARE *share=info->s;
 
180
    if (!strcmp(share->unique_file_name,filename))
 
181
    {
 
182
      if (share->last_version)
 
183
      {
 
184
        fprintf(stderr,"Warning:  Table: %s is open on %s\n", name,where);
 
185
        DBUG_PRINT("warning",("Table: %s is open on %s", name,where));
 
186
        DBUG_RETURN(1);
 
187
      }
 
188
    }
 
189
  }
 
190
  DBUG_RETURN(0);
 
191
}
 
192
#endif /* EXTRA_DEBUG */