833
833
switch (sql_field->sql_type) {
834
834
case DRIZZLE_TYPE_BLOB:
835
sql_field->pack_flag=FIELDFLAG_BLOB |
836
pack_length_to_packflag(sql_field->pack_length -
837
portable_sizeof_char_ptr);
838
if (sql_field->charset->state & MY_CS_BINSORT)
839
sql_field->pack_flag|=FIELDFLAG_BINARY;
840
sql_field->length=8; // Unireg field length
835
sql_field->pack_flag= pack_length_to_packflag(sql_field->pack_length - portable_sizeof_char_ptr);
836
sql_field->length= 8; // Unireg field length
841
837
(*blob_columns)++;
843
839
case DRIZZLE_TYPE_VARCHAR:
844
840
sql_field->pack_flag=0;
845
if (sql_field->charset->state & MY_CS_BINSORT)
846
sql_field->pack_flag|=FIELDFLAG_BINARY;
848
842
case DRIZZLE_TYPE_ENUM:
849
sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) |
851
if (sql_field->charset->state & MY_CS_BINSORT)
852
sql_field->pack_flag|=FIELDFLAG_BINARY;
853
if (check_duplicates_in_interval("ENUM",sql_field->field_name,
855
sql_field->charset, &dup_val_count))
843
sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length);
844
if (check_duplicates_in_interval("ENUM",
845
sql_field->field_name,
858
851
case DRIZZLE_TYPE_DATE: // Rest of string types
861
854
sql_field->pack_flag=f_settype((uint32_t) sql_field->sql_type);
863
856
case DRIZZLE_TYPE_NEWDECIMAL:
864
sql_field->pack_flag=(FIELDFLAG_NUMBER |
865
(sql_field->flags & UNSIGNED_FLAG ? 0 :
867
(sql_field->flags & DECIMAL_FLAG ? FIELDFLAG_DECIMAL_POSITION : 0) |
868
(sql_field->decimals << FIELDFLAG_DEC_SHIFT));
857
sql_field->pack_flag= 0;
870
859
case DRIZZLE_TYPE_TIMESTAMP:
871
860
/* We should replace old TIMESTAMP fields with their newer analogs */
886
875
/* fall-through */
888
sql_field->pack_flag=(FIELDFLAG_NUMBER |
889
(sql_field->flags & UNSIGNED_FLAG ? 0 :
891
f_settype((uint32_t) sql_field->sql_type) |
892
(sql_field->decimals << FIELDFLAG_DEC_SHIFT));
877
sql_field->pack_flag=(0 |
878
f_settype((uint32_t) sql_field->sql_type));
895
if (!(sql_field->flags & NOT_NULL_FLAG))
896
sql_field->pack_flag|= FIELDFLAG_MAYBE_NULL;
897
if (sql_field->flags & NO_DEFAULT_VALUE_FLAG)
898
sql_field->pack_flag|= FIELDFLAG_NO_DEFAULT;
1376
1358
cols2.rewind();
1378
column->length*= sql_field->charset->mbmaxlen;
1360
column->length*= sql_field->charset->mbmaxlen;
1380
if (f_is_blob(sql_field->pack_flag))
1382
if (!(file->ha_table_flags() & HA_CAN_INDEX_BLOBS))
1384
my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name.str);
1387
if (!column->length)
1389
my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
1393
if (!(sql_field->flags & NOT_NULL_FLAG))
1395
if (key->type == Key::PRIMARY)
1397
/* Implicitly set primary key fields to NOT NULL for ISO conf. */
1398
sql_field->flags|= NOT_NULL_FLAG;
1399
sql_field->pack_flag&= ~FIELDFLAG_MAYBE_NULL;
1362
if (sql_field->sql_type == DRIZZLE_TYPE_BLOB)
1364
if (! (file->ha_table_flags() & HA_CAN_INDEX_BLOBS))
1366
my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name.str);
1369
if (! column->length)
1371
my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
1375
if (! (sql_field->flags & NOT_NULL_FLAG))
1377
if (key->type == Key::PRIMARY)
1379
/* Implicitly set primary key fields to NOT NULL for ISO conf. */
1380
sql_field->flags|= NOT_NULL_FLAG;
1404
1385
key_info->flags|= HA_NULL_PART_KEY;
1405
if (!(file->ha_table_flags() & HA_NULL_IN_KEY))
1386
if (! (file->ha_table_flags() & HA_NULL_IN_KEY))
1407
1388
my_error(ER_NULL_COLUMN_IN_INDEX, MYF(0), column->field_name.str);
1412
if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
1414
if (column_nr == 0 || (file->ha_table_flags() & HA_AUTO_PART_KEY))
1415
auto_increment--; // Field is used
1393
if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
1395
if (column_nr == 0 || (file->ha_table_flags() & HA_AUTO_PART_KEY))
1396
auto_increment--; // Field is used
1419
1400
key_part_info->fieldnr= field;
1450
1431
else if ((column->length > length ||
1451
!Field::type_can_have_key_part (sql_field->sql_type) ||
1452
((f_is_packed(sql_field->pack_flag) ||
1453
((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
1454
(key_info->flags & HA_NOSAME))) &&
1455
column->length != length)))
1432
! Field::type_can_have_key_part(sql_field->sql_type)))
1457
1434
my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
1490
1467
if (!((*db_options) & HA_OPTION_NO_PACK_KEYS) &&
1491
1468
(length >= KEY_DEFAULT_PACK_LENGTH &&
1492
1469
(sql_field->sql_type == DRIZZLE_TYPE_VARCHAR ||
1493
sql_field->pack_flag & FIELDFLAG_BLOB)))
1470
sql_field->sql_type == DRIZZLE_TYPE_BLOB)))
1495
if ((column_nr == 0 && (sql_field->pack_flag & FIELDFLAG_BLOB)) ||
1472
if ((column_nr == 0 && sql_field->sql_type == DRIZZLE_TYPE_BLOB) ||
1496
1473
sql_field->sql_type == DRIZZLE_TYPE_VARCHAR)
1497
key_info->flags|= HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
1499
key_info->flags|= HA_PACK_KEY;
1474
key_info->flags|= HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
1476
key_info->flags|= HA_PACK_KEY;
1501
1478
/* Check if the key segment is partial, set the key flag accordingly */
1502
1479
if (length != sql_field->key_length)