| 1 | /* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ |
| 15 | |
| 16 | /* Calculate a checksum for a row */ |
| 17 | |
| 18 | #include "maria_def.h"cxx . . $ `<file>/storage/maria/maria_def.h`/ |
| 19 | |
| 20 | /** |
| 21 | Calculate a checksum for the record |
| 22 | |
| 23 | _ma_checksum() |
| 24 | @param info Maria handler |
| 25 | @param record Record |
| 26 | |
| 27 | @note |
| 28 | To ensure that the checksum is independent of the row format |
| 29 | we need to always calculate the checksum in the original field order. |
| 30 | |
| 31 | @return checksum |
| 32 | */ |
| 33 | |
| 34 | ha_checksumcxx . . $ ha_checksum# _ma_checksumcxx . . $ _ma_checksum(81efd6e59a238acf).(MARIA_HAcxx . . $ MARIA_HA# *info, const ucharcxx . . $ uchar# *record) |
| 35 | { |
| 36 | ha_checksumcxx . . $ ha_checksum# crc=0; |
| 37 | uintcxx . . $ uint# i,end; |
| 38 | MARIA_COLUMNDEFcxx . . $ MARIA_COLUMNDEF# *base_column= info->scxx . . $ st_maria_handler#s.->columndefcxx . . $ st_maria_share#columndef.; |
| 39 | uint16cxx . . $ uint16# *column_nr= info->scxx . . $ st_maria_handler#s.->column_nrcxx . . $ st_maria_share#column_nr.; |
| 40 | |
| 41 | if (info->scxx . . $ st_maria_handler#s.->basecxx . . $ st_maria_share#base..null_bytescxx . . $ st_ma_base_info#null_bytes.) |
| 42 | crc= my_checksumcxx . . $ my_checksum(5662e11f5663ca27).(crc, record, info->scxx . . $ st_maria_handler#s.->basecxx . . $ st_maria_share#base..null_bytescxx . . $ st_ma_base_info#null_bytes.); |
| 43 | |
| 44 | for (i= 0, end= info->scxx . . $ st_maria_handler#s.->basecxx . . $ st_maria_share#base..fieldscxx . . $ st_ma_base_info#fields. ; i < end ; i++) |
| 45 | { |
| 46 | MARIA_COLUMNDEFcxx . . $ MARIA_COLUMNDEF# *column= base_column + column_nr[i]; |
| 47 | const ucharcxx . . $ uchar# *pos; |
| 48 | ulongcxx . . $ ulong# length; |
| 49 | |
| 50 | if (record[column->null_poscxx . . $ st_maria_columndef#null_pos.] & column->null_bitcxx . . $ st_maria_columndef#null_bit.) |
| 51 | continue; /* Null field */ |
| 52 | |
| 53 | pos= record + column->offsetcxx . . $ st_maria_columndef#offset.; |
| 54 | switch (column->typecxx . . $ st_maria_columndef#type.) { |
| 55 | case FIELD_BLOBcxx . . $ FIELD_BLOB.: |
| 56 | { |
| 57 | uintcxx . . $ uint# blob_size_length= column->lengthcxx . . $ st_maria_columndef#length.- portable_sizeof_char_ptrcxx . . $ `include/my_compare.h:252:9`!; |
| 58 | length= _ma_calc_blob_lengthcxx . . $ _ma_calc_blob_length(3cbac61846b0ebe9).(blob_size_length, pos); |
| 59 | if (length) |
| 60 | { |
| 61 | memcpycxx . . $ memcpy(cc817cb175f282d).((char**) &pos, pos + blob_size_length, sizeof(char*)); |
| 62 | crc= my_checksumcxx . . $ my_checksum(5662e11f5663ca27).(crc, pos, length); |
| 63 | } |
| 64 | continue; |
| 65 | } |
| 66 | case FIELD_VARCHARcxx . . $ FIELD_VARCHAR.: |
| 67 | { |
| 68 | uintcxx . . $ uint# pack_length= column->fill_lengthcxx . . $ st_maria_columndef#fill_length.; |
| 69 | if (pack_length == 1) |
| 70 | length= (ulongcxx . . $ ulong#) *pos; |
| 71 | else |
| 72 | length= uint2korrcxx . . $ uint2korr(533a9de78501ce46).(pos); |
| 73 | pos+= pack_length; /* Skip length information */ |
| 74 | break; |
| 75 | } |
| 76 | default: |
| 77 | length= column->lengthcxx . . $ st_maria_columndef#length.; |
| 78 | break; |
| 79 | } |
| 80 | crc= my_checksumcxx . . $ my_checksum(5662e11f5663ca27).(crc, pos, length); |
| 81 | } |
| 82 | return crc; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | ha_checksumcxx . . $ ha_checksum# _ma_static_checksumcxx . . $ _ma_static_checksum(81efd6e59a238acf).(MARIA_HAcxx . . $ MARIA_HA# *info, const ucharcxx . . $ uchar# *pos) |
| 87 | { |
| 88 | return my_checksumcxx . . $ my_checksum(5662e11f5663ca27).(0, pos, info->scxx . . $ st_maria_handler#s.->basecxx . . $ st_maria_share#base..reclengthcxx . . $ st_ma_base_info#reclength.); |
| 89 | } |