~ubuntu-branches/ubuntu/utopic/mariadb-5.5/utopic-security

« back to all changes in this revision

Viewing changes to sql/sql_table.cc

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2014-08-27 21:12:36 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140827211236-se41hwfe4xy0hpef
* d/control: Removed Provides: libmysqlclient-dev (Closes: #759309)
* d/control: Removed Provides: libmysqld-dev with same motivation
* Re-introduced tha HPPA build patch as the upstream fix wasn't complete
* Fixed all kFreeBSD build and test suite issues
* Added Italian translation (Closes: #759813)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
   Copyright (c) 2000, 2013, Oracle and/or its affiliates.
3
 
   Copyright (c) 2010, 2013, Monty Program Ab.
 
3
   Copyright (c) 2010, 2014, SkySQL Ab.
4
4
 
5
5
   This program is free software; you can redistribute it and/or modify
6
6
   it under the terms of the GNU General Public License as published by
74
74
static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *,
75
75
                                      bool, uint *, handler *, KEY **, uint *,
76
76
                                      int);
 
77
static uint blob_length_by_type(enum_field_types type);
77
78
 
78
79
/**
79
80
  @brief Helper function for explain_filename
3475
3476
    CHARSET_INFO *ft_key_charset=0;  // for FULLTEXT
3476
3477
    for (uint column_nr=0 ; (column=cols++) ; column_nr++)
3477
3478
    {
3478
 
      uint length;
3479
3479
      Key_part_spec *dup_column;
3480
3480
 
3481
3481
      it.rewind();
3552
3552
          }
3553
3553
          if (f_is_geom(sql_field->pack_flag) && sql_field->geom_type ==
3554
3554
              Field::GEOM_POINT)
3555
 
            column->length= 25;
 
3555
            column->length= MAX_LEN_GEOM_POINT_FIELD;
3556
3556
          if (!column->length)
3557
3557
          {
3558
3558
            my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
3618
3618
      key_part_info->fieldnr= field;
3619
3619
      key_part_info->offset=  (uint16) sql_field->offset;
3620
3620
      key_part_info->key_type=sql_field->pack_flag;
3621
 
      length= sql_field->key_length;
 
3621
      uint key_part_length= sql_field->key_length;
3622
3622
 
3623
3623
      if (column->length)
3624
3624
      {
3625
3625
        if (f_is_blob(sql_field->pack_flag))
3626
3626
        {
3627
 
          if ((length=column->length) > max_key_length ||
3628
 
              length > file->max_key_part_length())
 
3627
          key_part_length= min(column->length,
 
3628
                               blob_length_by_type(sql_field->sql_type)
 
3629
                               * sql_field->charset->mbmaxlen);
 
3630
          if (key_part_length > max_key_length ||
 
3631
              key_part_length > file->max_key_part_length())
3629
3632
          {
3630
 
            length=min(max_key_length, file->max_key_part_length());
 
3633
            key_part_length= min(max_key_length, file->max_key_part_length());
3631
3634
            if (key->type == Key::MULTIPLE)
3632
3635
            {
3633
3636
              /* not a critical problem */
3634
 
              char warn_buff[MYSQL_ERRMSG_SIZE];
3635
 
              my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
3636
 
                          length);
3637
 
              push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3638
 
                           ER_TOO_LONG_KEY, warn_buff);
 
3637
              push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
3638
                           ER_TOO_LONG_KEY, ER(ER_TOO_LONG_KEY),
 
3639
                           key_part_length);
3639
3640
              /* Align key length to multibyte char boundary */
3640
 
              length-= length % sql_field->charset->mbmaxlen;
 
3641
              key_part_length-= key_part_length % sql_field->charset->mbmaxlen;
3641
3642
            }
3642
3643
            else
3643
3644
            {
3644
 
              my_error(ER_TOO_LONG_KEY,MYF(0),length);
 
3645
              my_error(ER_TOO_LONG_KEY, MYF(0), key_part_length);
3645
3646
              DBUG_RETURN(TRUE);
3646
3647
            }
3647
3648
          }
3649
3650
        // Catch invalid use of partial keys 
3650
3651
        else if (!f_is_geom(sql_field->pack_flag) &&
3651
3652
                 // is the key partial? 
3652
 
                 column->length != length &&
 
3653
                 column->length != key_part_length &&
3653
3654
                 // is prefix length bigger than field length? 
3654
 
                 (column->length > length ||
 
3655
                 (column->length > key_part_length ||
3655
3656
                  // can the field have a partial key? 
3656
3657
                  !Field::type_can_have_key_part (sql_field->sql_type) ||
3657
3658
                  // a packed field can't be used in a partial key
3660
3661
                  ((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
3661
3662
                   // and is this a 'unique' key?
3662
3663
                   (key_info->flags & HA_NOSAME))))
3663
 
        {         
 
3664
        {
3664
3665
          my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
3665
3666
          DBUG_RETURN(TRUE);
3666
3667
        }
3667
3668
        else if (!(file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS))
3668
 
          length=column->length;
 
3669
          key_part_length= column->length;
3669
3670
      }
3670
 
      else if (length == 0 && (sql_field->flags & NOT_NULL_FLAG))
 
3671
      else if (key_part_length == 0 && (sql_field->flags & NOT_NULL_FLAG))
3671
3672
      {
3672
3673
        my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name.str);
3673
3674
          DBUG_RETURN(TRUE);
3674
3675
      }
3675
 
      if (length > file->max_key_part_length() && key->type != Key::FULLTEXT)
 
3676
      if (key_part_length > file->max_key_part_length() &&
 
3677
          key->type != Key::FULLTEXT)
3676
3678
      {
3677
 
        length= file->max_key_part_length();
 
3679
        key_part_length= file->max_key_part_length();
3678
3680
        if (key->type == Key::MULTIPLE)
3679
3681
        {
3680
3682
          /* not a critical problem */
3681
 
          char warn_buff[MYSQL_ERRMSG_SIZE];
3682
 
          my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
3683
 
                      length);
3684
 
          push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3685
 
                       ER_TOO_LONG_KEY, warn_buff);
 
3683
          push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
3684
                       ER_TOO_LONG_KEY, ER(ER_TOO_LONG_KEY),
 
3685
                       key_part_length);
3686
3686
          /* Align key length to multibyte char boundary */
3687
 
          length-= length % sql_field->charset->mbmaxlen;
 
3687
          key_part_length-= key_part_length % sql_field->charset->mbmaxlen;
3688
3688
        }
3689
3689
        else
3690
3690
        {
3691
 
          my_error(ER_TOO_LONG_KEY,MYF(0),length);
 
3691
          my_error(ER_TOO_LONG_KEY, MYF(0), key_part_length);
3692
3692
          DBUG_RETURN(TRUE);
3693
3693
        }
3694
3694
      }
3695
 
      key_part_info->length=(uint16) length;
 
3695
      key_part_info->length= (uint16) key_part_length;
3696
3696
      /* Use packed keys for long strings on the first column */
3697
3697
      if (!((*db_options) & HA_OPTION_NO_PACK_KEYS) &&
3698
3698
          !((create_info->table_options & HA_OPTION_NO_PACK_KEYS)) &&
3699
 
          (length >= KEY_DEFAULT_PACK_LENGTH &&
 
3699
          (key_part_length >= KEY_DEFAULT_PACK_LENGTH &&
3700
3700
           (sql_field->sql_type == MYSQL_TYPE_STRING ||
3701
3701
            sql_field->sql_type == MYSQL_TYPE_VARCHAR ||
3702
3702
            sql_field->pack_flag & FIELDFLAG_BLOB)))
3708
3708
          key_info->flags|= HA_PACK_KEY;
3709
3709
      }
3710
3710
      /* Check if the key segment is partial, set the key flag accordingly */
3711
 
      if (length != sql_field->key_length)
 
3711
      if (key_part_length != sql_field->key_length)
3712
3712
        key_info->flags|= HA_KEY_HAS_PART_KEY_SEG;
3713
3713
 
3714
 
      key_length+=length;
 
3714
      key_length+= key_part_length;
3715
3715
      key_part_info++;
3716
3716
 
3717
3717
      /* Create the key name based on the first column (if not given) */