| 1 | /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ |
| 15 | |
| 16 | /* Calculate a checksum for a row */ |
| 17 | |
| 18 | #include "myisamdef.h" |
| 19 | |
| 20 | ha_checksum mi_checksum(MI_INFO *info, const uchar *buf) |
| 21 | { |
| 22 | ha_checksum crc=0; |
| 23 | const uchar *record= buf; |
| 24 | MI_COLUMNDEF *column= info->s->rec; |
| 25 | MI_COLUMNDEF *column_end= column+ info->s->base.fields; |
| 26 | my_bool skip_null_bits= MY_TEST(info->s->options & HA_OPTION_NULL_FIELDS); |
| 27 | |
| 28 | for ( ; column != column_end ; buf+= column++->length) |
| 29 | { |
| 30 | const uchar *pos; |
| 31 | ulong length; |
| 32 | |
| 33 | if ((record[column->null_pos] & column->null_bit) && |
| 34 | skip_null_bits) |
| 35 | continue; /* Null field */ |
| 36 | |
| 37 | switch (column->type) { |
| 38 | case FIELD_BLOB: |
| 39 | { |
| 40 | length=_mi_calc_blob_length(column->length- |
| 41 | portable_sizeof_char_ptr, |
| 42 | buf); |
| 43 | memcpy((void*) &pos, buf+column->length - portable_sizeof_char_ptr, |
| 44 | sizeof(char*)); |
| 45 | break; |
| 46 | } |
| 47 | case FIELD_VARCHAR: |
| 48 | { |
| 49 | uint pack_length= HA_VARCHAR_PACKLENGTH(column->length-1); |
| 50 | if (pack_length == 1) |
| 51 | length= (ulong) *(uchar*) buf; |
| 52 | else |
| 53 | length= uint2korr(buf); |
| 54 | pos= buf+pack_length; |
| 55 | break; |
| 56 | } |
| 57 | default: |
| 58 | length=column->length; |
| 59 | pos=buf; |
| 60 | break; |
| 61 | } |
| 62 | crc=my_checksum(crc, pos ? pos : (uchar*) "" , length); |
| 63 | } |
| 64 | return crc; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | ha_checksum mi_static_checksum(MI_INFO *info, const uchar *pos) |
| 69 | { |
| 70 | return my_checksum(0, pos, info->s->base.reclength); |
| 71 | } |
| 72 | |