Drizzled Public API Documentation

mi_checksum.cc
00001 /* Copyright (C) 2000-2001, 2003-2004 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /* Calculate a checksum for a row */
00017 
00018 #include "myisam_priv.h"
00019 
00020 using namespace drizzled;
00021 
00022 internal::ha_checksum mi_checksum(MI_INFO *info, const unsigned char *buf)
00023 {
00024   uint32_t i;
00025   internal::ha_checksum crc=0;
00026   MI_COLUMNDEF *rec=info->s->rec;
00027 
00028   for (i=info->s->base.fields ; i-- ; buf+=(rec++)->length)
00029   {
00030     const unsigned char *pos;
00031     ulong length;
00032     switch (rec->type) {
00033     case FIELD_BLOB:
00034     {
00035       length=_mi_calc_blob_length(rec->length-
00036           portable_sizeof_char_ptr,
00037           buf);
00038       memcpy(&pos, buf+rec->length - portable_sizeof_char_ptr, sizeof(char*));
00039       break;
00040     }
00041     case FIELD_VARCHAR:
00042     {
00043       uint32_t pack_length= ha_varchar_packlength(rec->length-1);
00044       if (pack_length == 1)
00045         length= (ulong) *(unsigned char*) buf;
00046       else
00047         length= uint2korr(buf);
00048       pos= buf+pack_length;
00049       break;
00050     }
00051     default:
00052       length=rec->length;
00053       pos=buf;
00054       break;
00055     }
00056     crc=internal::my_checksum(crc, pos ? pos : (unsigned char*) "", length);
00057   }
00058   return crc;
00059 }
00060 
00061 
00062 internal::ha_checksum mi_static_checksum(MI_INFO *info, const unsigned char *pos)
00063 {
00064   return internal::my_checksum(0, pos, info->s->base.reclength);
00065 }