~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_checksum.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

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