~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_dbug.c

  • Committer: Stewart Smith
  • Date: 2008-07-25 03:48:54 UTC
  • mfrom: (207.1.1 drizzle)
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080725034854-p34pdb0lhpoc159d
merge mainline and update md5 and crc32 plugins to new interface

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
 
    case HA_KEYTYPE_LONGLONG:
117
 
    {
118
 
      char buff[21];
119
 
      longlong2str(mi_sint8korr(key),buff,-10);
120
 
      VOID(fprintf(stream,"%s",buff));
121
 
      key=end;
122
 
      break;
123
 
    }
124
 
    case HA_KEYTYPE_ULONGLONG:
125
 
    {
126
 
      char buff[21];
127
 
      longlong2str(mi_sint8korr(key),buff,10);
128
 
      VOID(fprintf(stream,"%s",buff));
129
 
      key=end;
130
 
      break;
131
 
    }
132
 
    case HA_KEYTYPE_BIT:
133
 
    {
134
 
      uint i;
135
 
      fputs("0x",stream);
136
 
      for (i=0 ; i < keyseg->length ; i++)
137
 
        fprintf(stream, "%02x", (uint) *key++);
138
 
      key= end;
139
 
      break;
140
 
    }
141
 
 
142
 
    case HA_KEYTYPE_VARTEXT1:                   /* VARCHAR and TEXT */
143
 
    case HA_KEYTYPE_VARTEXT2:                   /* VARCHAR and TEXT */
144
 
    case HA_KEYTYPE_VARBINARY1:                 /* VARBINARY and BLOB */
145
 
    case HA_KEYTYPE_VARBINARY2:                 /* VARBINARY and BLOB */
146
 
    {
147
 
      uint tmp_length;
148
 
      get_key_length(tmp_length,key);
149
 
      /*
150
 
        The following command sometimes gives a warning from valgrind.
151
 
        Not yet sure if the bug is in valgrind, glibc or mysqld
152
 
      */
153
 
      VOID(fprintf(stream,"%.*s",(int) tmp_length,key));
154
 
      key+=tmp_length;
155
 
      break;
156
 
    }
157
 
    default: break;                     /* This never happens */
158
 
    }
159
 
  }
160
 
  VOID(fputs("\"\n",stream));
161
 
  return;
162
 
} /* print_key */
163
 
 
164
 
 
165
 
#ifdef EXTRA_DEBUG 
166
 
 
167
 
my_bool check_table_is_closed(const char *name, const char *where)
168
 
{
169
 
  char filename[FN_REFLEN];
170
 
  LIST *pos;
171
 
  DBUG_ENTER("check_table_is_closed");
172
 
 
173
 
  pthread_mutex_lock(&THR_LOCK_myisam);
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
 
        pthread_mutex_unlock(&THR_LOCK_myisam);
187
 
        DBUG_RETURN(1);
188
 
      }
189
 
    }
190
 
  }
191
 
  pthread_mutex_unlock(&THR_LOCK_myisam);
192
 
  DBUG_RETURN(0);
193
 
}
194
 
#endif /* EXTRA_DEBUG */