~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_delete.cc

  • Committer: Eric Day
  • Date: 2009-10-31 21:53:33 UTC
  • mfrom: (1200 staging)
  • mto: This revision was merged to the branch mainline in revision 1202.
  • Revision ID: eday@oddments.org-20091031215333-j94bjoanwmi68p6f
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
410
410
  - If we want to have a name lock on the table on exit without errors.
411
411
*/
412
412
 
413
 
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok)
 
413
bool mysql_truncate(Session& session, TableList *table_list, bool dont_send_ok)
414
414
{
415
415
  HA_CREATE_INFO create_info;
416
416
  char path[FN_REFLEN];
417
417
  Table *table;
418
418
  bool error;
419
419
  uint32_t path_length;
 
420
  message::Table tmp_table;
420
421
 
421
422
 
422
423
  memset(&create_info, 0, sizeof(create_info));
423
424
  /* If it is a temporary table, close and regenerate it */
424
 
  if (!dont_send_ok && (table= session->find_temporary_table(table_list)))
 
425
  if (!dont_send_ok && (table= session.find_temporary_table(table_list)))
425
426
  {
 
427
    message::Table::StorageEngine *engine= tmp_table.mutable_engine();
426
428
    plugin::StorageEngine *table_type= table->s->db_type();
427
429
    TableShare *share= table->s;
428
430
 
431
433
 
432
434
    table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
433
435
 
434
 
    session->close_temporary_table(table, false, false);    // Don't free share
 
436
    /*
 
437
      Because we bypass "all" of what it takes to create a Table we are on shakey ground in this
 
438
      execution path. Not everything will be properly created in order to use the table
 
439
      we create here. 
 
440
 
 
441
      Painful.
 
442
    */
 
443
    assert(share->storage_engine);
 
444
    session.close_temporary_table(table, false, false);    // Don't free share
 
445
    assert(share->storage_engine);
 
446
    engine->set_name(share->db_type()->getName());
435
447
    plugin::StorageEngine::createTable(session, share->normalized_path.str,
436
 
                                       share->db.str, share->table_name.str, &create_info,
437
 
                                       true, NULL);
 
448
                                       share->db.str, share->table_name.str, create_info, 
 
449
                                       true, tmp_table, false);
438
450
    // We don't need to call invalidate() because this table is not in cache
439
 
    if ((error= (int) !(session->open_temporary_table(share->path.str,
 
451
    if ((error= (int) !(session.open_temporary_table(share->path.str,
440
452
                                                      share->db.str,
441
453
                                                      share->table_name.str, 1,
442
454
                                                      OTM_OPEN))))
443
 
      (void) session->rm_temporary_table(table_type, path);
 
455
      (void) session.rm_temporary_table(table_type, path);
444
456
    share->free_table_share();
445
457
    free((char*) table);
446
458
    /*
458
470
 
459
471
  pthread_mutex_lock(&LOCK_open); /* Recreate table for truncate */
460
472
  error= plugin::StorageEngine::createTable(session, path, table_list->db, table_list->table_name,
461
 
                                            &create_info, true, NULL);
 
473
                                            create_info, true, tmp_table, false);
462
474
  pthread_mutex_unlock(&LOCK_open);
463
475
 
464
476
end:
470
482
        TRUNCATE must always be statement-based binlogged (not row-based) so
471
483
        we don't test current_stmt_binlog_row_based.
472
484
      */
473
 
      write_bin_log(session, session->query, session->query_length);
474
 
      session->my_ok();         // This should return record count
 
485
      write_bin_log(&session, session.query, session.query_length);
 
486
      session.my_ok();          // This should return record count
475
487
    }
476
488
    pthread_mutex_lock(&LOCK_open); /* For truncate delete from hash when finished */
477
489
    unlock_table_name(table_list);
487
499
 
488
500
trunc_by_del:
489
501
  /* Probably InnoDB table */
490
 
  uint64_t save_options= session->options;
 
502
  uint64_t save_options= session.options;
491
503
  table_list->lock_type= TL_WRITE;
492
 
  session->options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
493
 
  ha_enable_transaction(session, false);
494
 
  mysql_init_select(session->lex);
495
 
  error= mysql_delete(session, table_list, (COND*) 0, (SQL_LIST*) 0,
 
504
  session.options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
 
505
  ha_enable_transaction(&session, false);
 
506
  mysql_init_select(session.lex);
 
507
  error= mysql_delete(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
496
508
                      HA_POS_ERROR, 0L, true);
497
 
  ha_enable_transaction(session, true);
 
509
  ha_enable_transaction(&session, true);
498
510
  /*
499
511
    Safety, in case the engine ignored ha_enable_transaction(false)
500
512
    above. Also clears session->transaction.*.
501
513
  */
502
 
  error= ha_autocommit_or_rollback(session, error);
503
 
  ha_commit(session);
504
 
  session->options= save_options;
 
514
  error= ha_autocommit_or_rollback(&session, error);
 
515
  ha_commit(&session);
 
516
  session.options= save_options;
 
517
 
505
518
  return(error);
506
519
}