~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_checksum.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2001, 2003-2004 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
/* Calculate a checksum for a row */
 
17
 
 
18
#include "myisam_priv.h"
 
19
 
 
20
using namespace drizzled;
 
21
 
 
22
internal::ha_checksum mi_checksum(MI_INFO *info, const unsigned char *buf)
 
23
{
 
24
  uint32_t i;
 
25
  internal::ha_checksum crc=0;
 
26
  MI_COLUMNDEF *rec=info->s->rec;
 
27
 
 
28
  for (i=info->s->base.fields ; i-- ; buf+=(rec++)->length)
 
29
  {
 
30
    const unsigned char *pos;
 
31
    ulong length;
 
32
    switch (rec->type) {
 
33
    case FIELD_BLOB:
 
34
    {
 
35
      length=_mi_calc_blob_length(rec->length-
 
36
                                        portable_sizeof_char_ptr,
 
37
                                        buf);
 
38
      memcpy(&pos, buf+rec->length - portable_sizeof_char_ptr, sizeof(char*));
 
39
      break;
 
40
    }
 
41
    case FIELD_VARCHAR:
 
42
    {
 
43
      uint32_t pack_length= HA_VARCHAR_PACKLENGTH(rec->length-1);
 
44
      if (pack_length == 1)
 
45
        length= (ulong) *(unsigned char*) buf;
 
46
      else
 
47
        length= uint2korr(buf);
 
48
      pos= buf+pack_length;
 
49
      break;
 
50
    }
 
51
    default:
 
52
      length=rec->length;
 
53
      pos=buf;
 
54
      break;
 
55
    }
 
56
    crc=internal::my_checksum(crc, pos ? pos : (unsigned char*) "", length);
 
57
  }
 
58
  return crc;
 
59
}
 
60
 
 
61
 
 
62
internal::ha_checksum mi_static_checksum(MI_INFO *info, const unsigned char *pos)
 
63
{
 
64
  return internal::my_checksum(0, pos, info->s->base.reclength);
 
65
}