~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

Merge Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
832
832
 
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)++;
842
838
    break;
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;
847
841
    break;
848
842
  case DRIZZLE_TYPE_ENUM:
849
 
    sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) |
850
 
      FIELDFLAG_INTERVAL;
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,
854
 
                                 sql_field->interval,
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,
 
846
                                     sql_field->interval,
 
847
                                     sql_field->charset,
 
848
                                     &dup_val_count))
856
849
      return 1;
857
850
    break;
858
851
  case DRIZZLE_TYPE_DATE:  // Rest of string types
861
854
    sql_field->pack_flag=f_settype((uint32_t) sql_field->sql_type);
862
855
    break;
863
856
  case DRIZZLE_TYPE_NEWDECIMAL:
864
 
    sql_field->pack_flag=(FIELDFLAG_NUMBER |
865
 
                          (sql_field->flags & UNSIGNED_FLAG ? 0 :
866
 
                           FIELDFLAG_DECIMAL) |
867
 
                          (sql_field->flags & DECIMAL_FLAG ?  FIELDFLAG_DECIMAL_POSITION : 0) |
868
 
                          (sql_field->decimals << FIELDFLAG_DEC_SHIFT));
 
857
    sql_field->pack_flag= 0;
869
858
    break;
870
859
  case DRIZZLE_TYPE_TIMESTAMP:
871
860
    /* We should replace old TIMESTAMP fields with their newer analogs */
885
874
    (*timestamps)++;
886
875
    /* fall-through */
887
876
  default:
888
 
    sql_field->pack_flag=(FIELDFLAG_NUMBER |
889
 
                          (sql_field->flags & UNSIGNED_FLAG ? 0 :
890
 
                           FIELDFLAG_DECIMAL) |
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));
893
879
    break;
894
880
  }
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;
899
881
  return 0;
900
882
}
901
883
 
1375
1357
      }
1376
1358
      cols2.rewind();
1377
1359
      {
1378
 
        column->length*= sql_field->charset->mbmaxlen;
 
1360
        column->length*= sql_field->charset->mbmaxlen;
1379
1361
 
1380
 
        if (f_is_blob(sql_field->pack_flag))
1381
 
        {
1382
 
          if (!(file->ha_table_flags() & HA_CAN_INDEX_BLOBS))
1383
 
          {
1384
 
            my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name.str);
1385
 
            return(true);
1386
 
          }
1387
 
          if (!column->length)
1388
 
          {
1389
 
            my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
1390
 
            return(true);
1391
 
          }
1392
 
        }
1393
 
        if (!(sql_field->flags & NOT_NULL_FLAG))
1394
 
        {
1395
 
          if (key->type == Key::PRIMARY)
1396
 
          {
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)
 
1363
        {
 
1364
          if (! (file->ha_table_flags() & HA_CAN_INDEX_BLOBS))
 
1365
          {
 
1366
            my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name.str);
 
1367
            return true;
 
1368
          }
 
1369
          if (! column->length)
 
1370
          {
 
1371
            my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
 
1372
            return true;
 
1373
          }
 
1374
        }
 
1375
        if (! (sql_field->flags & NOT_NULL_FLAG))
 
1376
        {
 
1377
          if (key->type == Key::PRIMARY)
 
1378
          {
 
1379
            /* Implicitly set primary key fields to NOT NULL for ISO conf. */
 
1380
            sql_field->flags|= NOT_NULL_FLAG;
1400
1381
            null_fields--;
1401
 
          }
1402
 
          else
 
1382
          }
 
1383
          else
1403
1384
          {
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))
1406
1387
            {
1407
1388
              my_error(ER_NULL_COLUMN_IN_INDEX, MYF(0), column->field_name.str);
1408
 
              return(true);
 
1389
              return true;
1409
1390
            }
1410
1391
          }
1411
 
        }
1412
 
        if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
1413
 
        {
1414
 
          if (column_nr == 0 || (file->ha_table_flags() & HA_AUTO_PART_KEY))
1415
 
            auto_increment--;                   // Field is used
1416
 
        }
 
1392
        }
 
1393
        if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
 
1394
        {
 
1395
          if (column_nr == 0 || (file->ha_table_flags() & HA_AUTO_PART_KEY))
 
1396
            auto_increment--;                   // Field is used
 
1397
        }
1417
1398
      }
1418
1399
 
1419
1400
      key_part_info->fieldnr= field;
1423
1404
 
1424
1405
      if (column->length)
1425
1406
      {
1426
 
        if (f_is_blob(sql_field->pack_flag))
 
1407
        if (sql_field->sql_type == DRIZZLE_TYPE_BLOB)
1427
1408
        {
1428
1409
          if ((length=column->length) > max_key_length ||
1429
1410
              length > file->max_key_part_length())
1448
1429
          }
1449
1430
        }
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)))
1456
1433
        {
1457
1434
          my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
1458
1435
          return(true);
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)))
1494
1471
      {
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;
1498
 
        else
1499
 
          key_info->flags|= HA_PACK_KEY;
 
1474
          key_info->flags|= HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
 
1475
        else
 
1476
          key_info->flags|= HA_PACK_KEY;
1500
1477
      }
1501
1478
      /* Check if the key segment is partial, set the key flag accordingly */
1502
1479
      if (length != sql_field->key_length)