00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "myisam_priv.h"
00019 #include <zlib.h>
00020
00021 using namespace drizzled;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 static ha_checksum my_checksum(ha_checksum crc, const unsigned char *pos, size_t length)
00034 {
00035 return ha_checksum(crc32((uint32_t)crc, pos, uInt(length)));
00036 }
00037
00038 ha_checksum mi_checksum(MI_INFO *info, const unsigned char *buf)
00039 {
00040 uint32_t i;
00041 ha_checksum crc=0;
00042 MI_COLUMNDEF *rec=info->s->rec;
00043
00044 for (i=info->s->base.fields ; i-- ; buf+=(rec++)->length)
00045 {
00046 const unsigned char *pos;
00047 ulong length;
00048 switch (rec->type) {
00049 case FIELD_BLOB:
00050 {
00051 length=_mi_calc_blob_length(rec->length-
00052 portable_sizeof_char_ptr,
00053 buf);
00054 memcpy(&pos, buf+rec->length - portable_sizeof_char_ptr, sizeof(char*));
00055 break;
00056 }
00057 case FIELD_VARCHAR:
00058 {
00059 uint32_t pack_length= ha_varchar_packlength(rec->length-1);
00060 if (pack_length == 1)
00061 length= (ulong) *(unsigned char*) buf;
00062 else
00063 length= uint2korr(buf);
00064 pos= buf+pack_length;
00065 break;
00066 }
00067 default:
00068 length=rec->length;
00069 pos=buf;
00070 break;
00071 }
00072 crc=my_checksum(crc, pos ? pos : (unsigned char*) "", length);
00073 }
00074 return crc;
00075 }
00076
00077
00078 ha_checksum mi_static_checksum(MI_INFO *info, const unsigned char *pos)
00079 {
00080 return my_checksum(0, pos, info->s->base.reclength);
00081 }