~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_delete.cc

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

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,
437
 
                                       &create_info, 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
    /*
457
469
    goto trunc_by_del;
458
470
 
459
471
  pthread_mutex_lock(&LOCK_open); /* Recreate table for truncate */
460
 
  error= plugin::StorageEngine::createTable(session, path, table_list->db,
461
 
                                            table_list->table_name,
462
 
                                            &create_info, true, NULL);
 
472
  error= plugin::StorageEngine::createTable(session, path, table_list->db, table_list->table_name,
 
473
                                            create_info, true, tmp_table, false);
463
474
  pthread_mutex_unlock(&LOCK_open);
464
475
 
465
476
end:
471
482
        TRUNCATE must always be statement-based binlogged (not row-based) so
472
483
        we don't test current_stmt_binlog_row_based.
473
484
      */
474
 
      write_bin_log(session, session->query, session->query_length);
475
 
      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
476
487
    }
477
488
    pthread_mutex_lock(&LOCK_open); /* For truncate delete from hash when finished */
478
489
    unlock_table_name(table_list);
488
499
 
489
500
trunc_by_del:
490
501
  /* Probably InnoDB table */
491
 
  uint64_t save_options= session->options;
 
502
  uint64_t save_options= session.options;
492
503
  table_list->lock_type= TL_WRITE;
493
 
  session->options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
494
 
  ha_enable_transaction(session, false);
495
 
  mysql_init_select(session->lex);
496
 
  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,
497
508
                      HA_POS_ERROR, 0L, true);
498
 
  ha_enable_transaction(session, true);
 
509
  ha_enable_transaction(&session, true);
499
510
  /*
500
511
    Safety, in case the engine ignored ha_enable_transaction(false)
501
512
    above. Also clears session->transaction.*.
502
513
  */
503
 
  error= ha_autocommit_or_rollback(session, error);
504
 
  ha_commit(session);
505
 
  session->options= save_options;
 
514
  error= ha_autocommit_or_rollback(&session, error);
 
515
  ha_commit(&session);
 
516
  session.options= save_options;
 
517
 
506
518
  return(error);
507
519
}