~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

merge for-brian work

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
char *fn_rext(char *name)
92
92
{
93
93
  char *res= strrchr(name, '.');
94
 
  if (res && !strcmp(res, reg_ext))
 
94
  if (res && !strcmp(res, ".dfe"))
95
95
    return res;
96
96
  return name + strlen(name);
97
97
}
364
364
    default_item= new Item_float(default_value.c_str(), default_value.length());
365
365
    break;
366
366
  case DRIZZLE_TYPE_NULL:
367
 
    return new Item_null();
368
 
    break;
 
367
    assert(false);
369
368
  case DRIZZLE_TYPE_TIMESTAMP:
370
369
  case DRIZZLE_TYPE_DATETIME:
371
370
  case DRIZZLE_TYPE_DATE:
406
405
int parse_table_proto(Session *session, drizzle::Table &table, TABLE_SHARE *share)
407
406
{
408
407
  int error= 0;
 
408
  handler *handler_file= NULL;
409
409
 
410
410
  {
411
411
    LEX_STRING engine_name= { (char*)table.engine().name().c_str(),
1104
1104
 
1105
1105
    if(default_value)
1106
1106
    {
 
1107
      enum_check_fields old_count_cuted_fields= session->count_cuted_fields;
 
1108
      session->count_cuted_fields= CHECK_FIELD_WARN;
1107
1109
      int res= default_value->save_in_field(f, 1);
1108
 
      (void)res; // TODO error handle;
 
1110
      session->count_cuted_fields= old_count_cuted_fields;
 
1111
      if (res != 0 && res != 3)
 
1112
      {
 
1113
        my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
 
1114
        error= 1;
 
1115
        goto err;
 
1116
      }
1109
1117
    }
1110
1118
    else if(f->real_type() == DRIZZLE_TYPE_ENUM &&
1111
1119
            (f->flags & NOT_NULL_FLAG))
1178
1186
  free(field_offsets);
1179
1187
  free(field_pack_length);
1180
1188
 
1181
 
  handler *handler_file;
1182
 
 
1183
1189
  if(!(handler_file= get_new_handler(share, session->mem_root,
1184
1190
                                     share->db_type())))
1185
1191
    abort(); // FIXME
1376
1382
  bitmap_init(&share->all_set, bitmaps, share->fields, false);
1377
1383
  bitmap_set_all(&share->all_set);
1378
1384
 
1379
 
  delete handler_file;
 
1385
  if(handler_file)
 
1386
    delete handler_file;
1380
1387
  return (0);
1381
1388
 
1382
1389
err:
1384
1391
  share->open_errno= my_errno;
1385
1392
  share->errarg= 0;
1386
1393
  hash_free(&share->name_hash);
1387
 
  delete handler_file;
 
1394
  if(handler_file)
 
1395
    delete handler_file;
1388
1396
  open_table_error(share, error, share->open_errno, 0);
1389
1397
  return error;
1390
1398
}
1418
1426
{
1419
1427
  int error;
1420
1428
  bool error_given;
1421
 
  string        path("");
 
1429
  string proto_path("");
1422
1430
 
1423
1431
  error= 1;
1424
1432
  error_given= 0;
1425
1433
 
1426
 
  path.reserve(FN_REFLEN);
1427
 
  path.append(share->normalized_path.str);
1428
 
  string proto_path= path;
1429
 
 
1430
 
  path.append(reg_ext);
 
1434
  proto_path.reserve(FN_REFLEN);
 
1435
  proto_path.append(share->normalized_path.str);
1431
1436
 
1432
1437
  proto_path.append(".dfe");
1433
1438
 
1450
1455
    goto err_not_open;
1451
1456
  }
1452
1457
 
1453
 
  parse_table_proto(session, table, share);
 
1458
  error= parse_table_proto(session, table, share);
1454
1459
 
1455
1460
  share->table_category= get_table_category(& share->db, & share->table_name);
1456
1461
 
2253
2258
      my_error(ER_NO_SUCH_TABLE, MYF(0), share->db.str, share->table_name.str);
2254
2259
    else
2255
2260
    {
2256
 
      sprintf(buff,"%s%s",share->normalized_path.str,reg_ext);
 
2261
      sprintf(buff,"%s",share->normalized_path.str);
2257
2262
      my_error((db_errno == EMFILE) ? ER_CANT_OPEN_FILE : ER_FILE_NOT_FOUND,
2258
2263
               errortype, buff, db_errno);
2259
2264
    }
2294
2299
    break;
2295
2300
  }
2296
2301
  case 6:
2297
 
    sprintf(buff,"%s%s",share->normalized_path.str,reg_ext);
 
2302
    sprintf(buff,"%s",share->normalized_path.str);
2298
2303
    my_printf_error(ER_NOT_FORM_FILE,
2299
2304
                    _("Table '%-.64s' was created with a different version "
2300
2305
                    "of Drizzle and cannot be read"),
2304
2309
    break;
2305
2310
  default:                              /* Better wrong error than none */
2306
2311
  case 4:
2307
 
    sprintf(buff,"%s%s",share->normalized_path.str,reg_ext);
 
2312
    sprintf(buff,"%s",share->normalized_path.str);
2308
2313
    my_error(ER_NOT_FORM_FILE, errortype, buff, 0);
2309
2314
    break;
2310
2315
  }
2461
2466
}
2462
2467
 
2463
2468
 
2464
 
        /* Create a .frm file */
2465
 
 
2466
 
File create_frm(Session *session, const char *name, const char *db,
2467
 
                const char *table, uint32_t reclength, unsigned char *fileinfo,
2468
 
                HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info)
2469
 
{
2470
 
  register File file;
2471
 
  ulong length;
2472
 
  unsigned char fill[IO_SIZE];
2473
 
  int create_flags= O_RDWR | O_TRUNC;
2474
 
  ulong key_comment_total_bytes= 0;
2475
 
  uint32_t i;
2476
 
 
2477
 
  if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
2478
 
    create_flags|= O_EXCL;
2479
 
 
2480
 
  /* Fix this when we have new .frm files;  Current limit is 4G rows (QQ) */
2481
 
  if (create_info->max_rows > UINT32_MAX)
2482
 
    create_info->max_rows= UINT32_MAX;
2483
 
  if (create_info->min_rows > UINT32_MAX)
2484
 
    create_info->min_rows= UINT32_MAX;
2485
 
 
2486
 
  if ((file= my_create(name, CREATE_MODE, create_flags, MYF(0))) >= 0)
2487
 
  {
2488
 
    uint32_t key_length, tmp_key_length;
2489
 
    uint32_t tmp;
2490
 
    memset(fileinfo, 0, 64);
2491
 
    /* header */
2492
 
    fileinfo[0]=(unsigned char) 254;
2493
 
    fileinfo[1]= 1;
2494
 
    fileinfo[2]= FRM_VER+3+ test(create_info->varchar);
2495
 
 
2496
 
    fileinfo[3]= (unsigned char) ha_legacy_type(
2497
 
          ha_checktype(session,ha_legacy_type(create_info->db_type),0,0));
2498
 
    fileinfo[4]=1;
2499
 
    int2store(fileinfo+6,IO_SIZE);              /* Next block starts here */
2500
 
    for (i= 0; i < keys; i++)
2501
 
    {
2502
 
      assert(test(key_info[i].flags & HA_USES_COMMENT) ==
2503
 
                 (key_info[i].comment.length > 0));
2504
 
      if (key_info[i].flags & HA_USES_COMMENT)
2505
 
        key_comment_total_bytes += 2 + key_info[i].comment.length;
2506
 
    }
2507
 
    /*
2508
 
      Keep in sync with pack_keys() in unireg.cc
2509
 
      For each key:
2510
 
      8 bytes for the key header
2511
 
      9 bytes for each key-part (MAX_REF_PARTS)
2512
 
      NAME_LEN bytes for the name
2513
 
      1 byte for the NAMES_SEP_CHAR (before the name)
2514
 
      For all keys:
2515
 
      6 bytes for the header
2516
 
      1 byte for the NAMES_SEP_CHAR (after the last name)
2517
 
      9 extra bytes (padding for safety? alignment?)
2518
 
      comments
2519
 
    */
2520
 
    key_length= (keys * (8 + MAX_REF_PARTS * 9 + NAME_LEN + 1) + 16 +
2521
 
                 key_comment_total_bytes);
2522
 
    length= next_io_size((ulong) (IO_SIZE+key_length+reclength+
2523
 
                                  create_info->extra_size));
2524
 
    int4store(fileinfo+10,length);
2525
 
    tmp_key_length= (key_length < 0xffff) ? key_length : 0xffff;
2526
 
    int2store(fileinfo+14,tmp_key_length);
2527
 
    int2store(fileinfo+16,reclength);
2528
 
    int4store(fileinfo+18,create_info->max_rows);
2529
 
    int4store(fileinfo+22,create_info->min_rows);
2530
 
    /* fileinfo[26] is set in mysql_create_frm() */
2531
 
    fileinfo[27]=2;                             // Use long pack-fields
2532
 
    /* fileinfo[28 & 29] is set to key_info_length in mysql_create_frm() */
2533
 
    create_info->table_options|=HA_OPTION_LONG_BLOB_PTR; // Use portable blob pointers
2534
 
    int2store(fileinfo+30,create_info->table_options);
2535
 
    fileinfo[32]=0;                             // No filename anymore
2536
 
    fileinfo[33]=5;                             // Mark for 5.0 frm file
2537
 
    int4store(fileinfo+34,create_info->avg_row_length);
2538
 
    fileinfo[38]= (create_info->default_table_charset ?
2539
 
                   create_info->default_table_charset->number : 0);
2540
 
    fileinfo[39]= (unsigned char) create_info->page_checksum;
2541
 
    fileinfo[40]= (unsigned char) create_info->row_type;
2542
 
    /* Next few bytes were for RAID support */
2543
 
    fileinfo[41]= 0;
2544
 
    fileinfo[42]= 0;
2545
 
    int4store(fileinfo+43,create_info->block_size);
2546
 
 
2547
 
    fileinfo[44]= 0;
2548
 
    fileinfo[45]= 0;
2549
 
    fileinfo[46]= 0;
2550
 
    int4store(fileinfo+47, key_length);
2551
 
    tmp= DRIZZLE_VERSION_ID;          // Store to avoid warning from int4store
2552
 
    int4store(fileinfo+51, tmp);
2553
 
    int4store(fileinfo+55, create_info->extra_size);
2554
 
    /*
2555
 
      59-60 is reserved for extra_rec_buf_length (always 0),
2556
 
      61 for default_part_db_type
2557
 
    */
2558
 
    int2store(fileinfo+62, create_info->key_block_size);
2559
 
    memset(fill, 0, IO_SIZE);
2560
 
    for (; length > IO_SIZE ; length-= IO_SIZE)
2561
 
    {
2562
 
      if (my_write(file,fill, IO_SIZE, MYF(MY_WME | MY_NABP)))
2563
 
      {
2564
 
        my_close(file,MYF(0));
2565
 
        my_delete(name,MYF(0));
2566
 
        return(-1);
2567
 
      }
2568
 
    }
2569
 
  }
2570
 
  else
2571
 
  {
2572
 
    if (my_errno == ENOENT)
2573
 
      my_error(ER_BAD_DB_ERROR,MYF(0),db);
2574
 
    else
2575
 
      my_error(ER_CANT_CREATE_TABLE,MYF(0),table,my_errno);
2576
 
  }
2577
 
  return (file);
2578
 
} /* create_frm */
2579
 
 
2580
2469
/*
2581
2470
  Set up column usage bitmaps for a temporary table
2582
2471