~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_unique.cc

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Functions to check if a row is unique */
17
17
 
18
 
#include "myisamdef.h"
19
 
#include <mystrings/m_ctype.h>
 
18
#include "myisam_priv.h"
 
19
#include "drizzled/charset_info.h"
20
20
 
21
 
bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, uchar *record,
 
21
bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, unsigned char *record,
22
22
                        ha_checksum unique_hash, my_off_t disk_pos)
23
23
{
24
24
  my_off_t lastpos=info->lastpos;
25
25
  MI_KEYDEF *key= &info->s->keyinfo[def->key];
26
 
  uchar *key_buff=info->lastkey2;
 
26
  unsigned char *key_buff=info->lastkey2;
27
27
 
28
28
  mi_unique_store(record+key->seg->start, unique_hash);
29
29
  _mi_make_key(info,def->key,key_buff,record,0);
44
44
    if (info->lastpos != disk_pos &&
45
45
        !(*info->s->compare_unique)(info,def,record,info->lastpos))
46
46
    {
47
 
      my_errno=HA_ERR_FOUND_DUPP_UNIQUE;
 
47
      errno=HA_ERR_FOUND_DUPP_UNIQUE;
48
48
      info->errkey= (int) def->key;
49
49
      info->dupp_key_pos= info->lastpos;
50
50
      info->page_changed=1;                     /* Can't optimize read next */
71
71
    Add support for bit fields
72
72
*/
73
73
 
74
 
ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const uchar *record)
 
74
ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const unsigned char *record)
75
75
{
76
 
  const uchar *pos, *end;
 
76
  const unsigned char *pos, *end;
77
77
  ha_checksum crc= 0;
78
78
  uint32_t seed1=0, seed2= 4;
79
79
  HA_KEYSEG *keyseg;
81
81
  for (keyseg=def->seg ; keyseg < def->end ; keyseg++)
82
82
  {
83
83
    enum ha_base_keytype type=(enum ha_base_keytype) keyseg->type;
84
 
    uint length=keyseg->length;
 
84
    uint32_t length=keyseg->length;
85
85
 
86
86
    if (keyseg->null_bit)
87
87
    {
100
100
    pos= record+keyseg->start;
101
101
    if (keyseg->flag & HA_VAR_LENGTH_PART)
102
102
    {
103
 
      uint pack_length=  keyseg->bit_start;
104
 
      uint tmp_length= (pack_length == 1 ? (uint) *(uchar*) pos :
 
103
      uint32_t pack_length=  keyseg->bit_start;
 
104
      uint32_t tmp_length= (pack_length == 1 ? (uint) *(unsigned char*) pos :
105
105
                        uint2korr(pos));
106
106
      pos+= pack_length;                        /* Skip VARCHAR length */
107
107
      set_if_smaller(length,tmp_length);
108
108
    }
109
109
    else if (keyseg->flag & HA_BLOB_PART)
110
110
    {
111
 
      uint tmp_length=_mi_calc_blob_length(keyseg->bit_start,pos);
 
111
      uint32_t tmp_length=_mi_calc_blob_length(keyseg->bit_start,pos);
112
112
      memcpy(&pos,pos+keyseg->bit_start,sizeof(char*));
113
113
      if (!length || length > tmp_length)
114
114
        length=tmp_length;                      /* The whole blob */
118
118
        type == HA_KEYTYPE_VARTEXT2)
119
119
    {
120
120
      keyseg->charset->coll->hash_sort(keyseg->charset,
121
 
                                       (const uchar*) pos, length, &seed1,
 
121
                                       (const unsigned char*) pos, length, &seed1,
122
122
                                       &seed2);
123
123
      crc^= seed1;
124
124
    }
125
125
    else
126
126
      while (pos != end)
127
127
        crc=((crc << 8) +
128
 
             (((uchar)  *(uchar*) pos++))) +
 
128
             (((unsigned char)  *(unsigned char*) pos++))) +
129
129
          (crc >> (8*sizeof(ha_checksum)-8));
130
130
  }
131
131
  return crc;
143
143
    #   Rows are different
144
144
*/
145
145
 
146
 
int mi_unique_comp(MI_UNIQUEDEF *def, const uchar *a, const uchar *b,
 
146
int mi_unique_comp(MI_UNIQUEDEF *def, const unsigned char *a, const unsigned char *b,
147
147
                   bool null_are_equal)
148
148
{
149
 
  const uchar *pos_a, *pos_b, *end;
 
149
  const unsigned char *pos_a, *pos_b, *end;
150
150
  HA_KEYSEG *keyseg;
151
151
 
152
152
  for (keyseg=def->seg ; keyseg < def->end ; keyseg++)
153
153
  {
154
154
    enum ha_base_keytype type=(enum ha_base_keytype) keyseg->type;
155
 
    uint a_length, b_length;
 
155
    uint16_t a_length, b_length;
156
156
    a_length= b_length= keyseg->length;
157
157
 
158
158
    /* If part is NULL it's regarded as different */
159
159
    if (keyseg->null_bit)
160
160
    {
161
 
      uint tmp;
 
161
      uint32_t tmp;
162
162
      if ((tmp=(a[keyseg->null_pos] & keyseg->null_bit)) !=
163
163
          (uint) (b[keyseg->null_pos] & keyseg->null_bit))
164
164
        return 1;
173
173
    pos_b= b+keyseg->start;
174
174
    if (keyseg->flag & HA_VAR_LENGTH_PART)
175
175
    {
176
 
      uint pack_length= keyseg->bit_start;
 
176
      uint32_t pack_length= keyseg->bit_start;
177
177
      if (pack_length == 1)
178
178
      {
179
 
        a_length= (uint) *(uchar*) pos_a++;
180
 
        b_length= (uint) *(uchar*) pos_b++;
 
179
        a_length= (uint) *(unsigned char*) pos_a++;
 
180
        b_length= (uint) *(unsigned char*) pos_b++;
181
181
      }
182
182
      else
183
183
      {
210
210
    if (type == HA_KEYTYPE_TEXT || type == HA_KEYTYPE_VARTEXT1 ||
211
211
        type == HA_KEYTYPE_VARTEXT2)
212
212
    {
213
 
      if (ha_compare_text(keyseg->charset, (uchar *) pos_a, a_length,
214
 
                                           (uchar *) pos_b, b_length, 0, 1))
 
213
      if (ha_compare_text(keyseg->charset, (unsigned char *) pos_a, a_length,
 
214
                                           (unsigned char *) pos_b, b_length, 0, 1))
215
215
        return 1;
216
216
    }
217
217
    else