home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win-source.exe / myisam / mi_dbug.c < prev    next >
C/C++ Source or Header  |  2000-08-31  |  4KB  |  173 lines

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
  6.    (at your option) any later version.
  7.    
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.    
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  16.  
  17. /* Support rutiner with are using with dbug */
  18.  
  19. #include "myisamdef.h"
  20.  
  21.     /* Print a key in user understandable format */
  22.  
  23. void _mi_print_key(FILE *stream, register MI_KEYSEG *keyseg,
  24.            const uchar *key, uint length)
  25. {
  26.   int flag;
  27.   short int s_1;
  28.   long    int l_1;
  29.   float f_1;
  30.   double d_1;
  31.   const uchar *end;
  32.   const uchar *key_end=key+length;
  33.  
  34.   VOID(fputs("Key: \"",stream));
  35.   flag=0;
  36.   for (; keyseg->type && key < key_end ;keyseg++)
  37.   {
  38.     if (flag++)
  39.       VOID(putc('-',stream));
  40.     end= key+ keyseg->length;
  41.     if (keyseg->flag & HA_NULL_PART)
  42.     {
  43.       if (!*key)
  44.       {
  45.     fprintf(stream,"NULL");
  46.     continue;
  47.       }
  48.       key++;
  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_sint4korr(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.       longlong2str(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.       longlong2str(mi_sint8korr(key),buff,10);
  130.       VOID(fprintf(stream,"%s",buff));
  131.       key=end;
  132.       break;
  133.     }
  134. #endif
  135.     case HA_KEYTYPE_VARTEXT:            /* VARCHAR and TEXT */
  136.     case HA_KEYTYPE_VARBINARY:            /* VARBINARY and BLOB */
  137.     {
  138.       uint tmp_length;
  139.       get_key_length(tmp_length,key);
  140.       VOID(fprintf(stream,"%.*s",(int) tmp_length,key));
  141.       key+=tmp_length;
  142.       break;
  143.     }
  144.     default: break;            /* This never happens */
  145.     }
  146.   }
  147.   VOID(fputs("\"\n",stream));
  148.   return;
  149. } /* print_key */
  150.  
  151.  
  152. #ifdef EXTRA_DEBUG 
  153.  
  154. my_bool check_table_is_closed(const char *name, const char *where)
  155. {
  156.   char filename[FN_REFLEN];
  157.   LIST *pos;
  158.  
  159.   (void) fn_format(filename,name,"",MI_NAME_IEXT,4+16+32);
  160.   for (pos=myisam_open_list ; pos ; pos=pos->next)
  161.   {
  162.     MI_INFO *info=(MI_INFO*) pos->data;
  163.     MYISAM_SHARE *share=info->s;
  164.     if (!strcmp(share->filename,filename))
  165.     {
  166.       fprintf(stderr,"Warning:  Table: %s is open on %s\n", name,where);
  167.       return 1;
  168.     }
  169.   }
  170.   return 0;
  171. }
  172. #endif /* EXTRA_DEBUG */
  173.