~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

Fixed bashism.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
 
109
109
 
110
110
/*
111
 
  Close cursor handle, but leave the table in the table cache
 
111
  Close file handle, but leave the table in the table cache
112
112
 
113
113
  SYNOPSIS
114
114
  close_handle_and_leave_table_as_lock()
149
149
    share->tmp_table= INTERNAL_TMP_TABLE;       // for intern_close_table()
150
150
  }
151
151
 
152
 
  table->cursor->close();
153
 
  table->db_stat= 0;                            // Mark cursor closed
 
152
  table->file->close();
 
153
  table->db_stat= 0;                            // Mark file closed
154
154
  TableShare::release(table->s);
155
155
  table->s= share;
156
 
  table->cursor->change_table_ptr(table, table->s);
 
156
  table->file->change_table_ptr(table, table->s);
157
157
}
158
158
 
159
159
 
240
240
void Table::intern_close_table()
241
241
{                                               // Free all structures
242
242
  free_io_cache();
243
 
  if (cursor)                              // Not true if name lock
244
 
    closefrm(true);                     // close cursor
 
243
  if (file)                              // Not true if name lock
 
244
    closefrm(true);                     // close file
245
245
}
246
246
 
247
247
/*
465
465
 
466
466
  safe_mutex_assert_owner(&LOCK_open);
467
467
  assert(table->key_read == 0);
468
 
  assert(!table->cursor || table->cursor->inited == Cursor::NONE);
 
468
  assert(!table->file || table->file->inited == Cursor::NONE);
469
469
 
470
470
  open_tables= table->next;
471
471
 
484
484
    assert(!table->open_placeholder);
485
485
 
486
486
    /* Free memory and reset for next loop */
487
 
    table->cursor->ha_reset();
 
487
    table->file->ha_reset();
488
488
    table->in_use= false;
489
489
 
490
490
    if (unused_tables)
922
922
  /*
923
923
    We want to prevent other connections from opening this table until end
924
924
    of statement as it is likely that modifications of table's metadata are
925
 
    not yet finished (for example CREATE TRIGGER have to change .TRG cursor,
 
925
    not yet finished (for example CREATE TRIGGER have to change .TRG file,
926
926
    or we might want to drop table if CREATE TABLE ... SELECT fails).
927
927
    This also allows us to assume that no other connection will sneak in
928
928
    before we will get table-level lock on this table.
1415
1415
  table Table object
1416
1416
 
1417
1417
  NOTES
1418
 
  The data cursor for the table is already closed and the share is released
 
1418
  The data file for the table is already closed and the share is released
1419
1419
  The table has a 'dummy' share that mainly contains database and table name.
1420
1420
 
1421
1421
  RETURN
1469
1469
  tmp.next=             table->next;
1470
1470
  tmp.prev=             table->prev;
1471
1471
 
1472
 
  if (table->cursor)
1473
 
    table->closefrm(true);              // close cursor, free everything
 
1472
  if (table->file)
 
1473
    table->closefrm(true);              // close file, free everything
1474
1474
 
1475
1475
  *table= tmp;
1476
1476
  table->default_column_bitmaps();
1477
 
  table->cursor->change_table_ptr(table, table->s);
 
1477
  table->file->change_table_ptr(table, table->s);
1478
1478
 
1479
1479
  assert(table->alias != 0);
1480
1480
  for (field=table->field ; *field ; field++)
1864
1864
        if (table->db_stat)
1865
1865
        {
1866
1866
          table->db_stat= 0;
1867
 
          table->cursor->close();
 
1867
          table->file->close();
1868
1868
        }
1869
1869
      }
1870
1870
      else
1909
1909
}
1910
1910
 
1911
1911
/*
1912
 
  Load a table definition from cursor and open unireg table
 
1912
  Load a table definition from file and open unireg table
1913
1913
 
1914
1914
  SYNOPSIS
1915
1915
  open_unireg_entry()
1951
1951
                                                   HA_GET_INDEX |
1952
1952
                                                   HA_TRY_READ_ONLY),
1953
1953
                                       (EXTRA_RECORD),
1954
 
                                       session->open_options, entry)))
 
1954
                                       session->open_options, entry, OTM_OPEN)))
1955
1955
  {
1956
1956
    if (error == 7)                             // Table def changed
1957
1957
    {
1993
1993
    }
1994
1994
    if (!entry->s || !entry->s->crashed)
1995
1995
      goto err;
1996
 
    // Code below is for repairing a crashed cursor
 
1996
    // Code below is for repairing a crashed file
1997
1997
    if ((error= lock_table_name(session, table_list, true)))
1998
1998
    {
1999
1999
      if (error < 0)
2013
2013
                                          HA_TRY_READ_ONLY),
2014
2014
                              EXTRA_RECORD,
2015
2015
                              ha_open_options | HA_OPEN_FOR_REPAIR,
2016
 
                              entry) || ! entry->cursor)
 
2016
                              entry, OTM_OPEN) || ! entry->file)
2017
2017
    {
2018
2018
      /* Give right error message */
2019
2019
      session->clear_error();
2020
2020
      my_error(ER_NOT_KEYFILE, MYF(0), share->table_name.str, my_errno);
2021
2021
      errmsg_printf(ERRMSG_LVL_ERROR, _("Couldn't repair table: %s.%s"), share->db.str,
2022
2022
                    share->table_name.str);
2023
 
      if (entry->cursor)
 
2023
      if (entry->file)
2024
2024
        entry->closefrm(false);
2025
2025
      error=1;
2026
2026
    }
2038
2038
    If we are here, there was no fatal error (but error may be still
2039
2039
    unitialized).
2040
2040
  */
2041
 
  if (unlikely(entry->cursor->implicit_emptied))
 
2041
  if (unlikely(entry->file->implicit_emptied))
2042
2042
  {
2043
2043
    ReplicationServices &replication_services= ReplicationServices::singleton();
2044
 
    entry->cursor->implicit_emptied= 0;
 
2044
    entry->file->implicit_emptied= 0;
2045
2045
    {
2046
2046
      char *query, *end;
2047
2047
      uint32_t query_buf_size= 20 + share->db.length + share->table_name.length +1;
2347
2347
*/
2348
2348
 
2349
2349
Table *Session::open_temporary_table(const char *path, const char *db_arg,
2350
 
                                     const char *table_name_arg, bool link_in_list)
 
2350
                                     const char *table_name_arg, bool link_in_list,
 
2351
                                     open_table_mode open_mode)
2351
2352
{
2352
2353
  Table *new_tmp_table;
2353
2354
  TableShare *share;
2377
2378
  */
2378
2379
  if (open_table_def(*this, share) ||
2379
2380
      open_table_from_share(this, share, table_name_arg,
 
2381
                            (open_mode == OTM_ALTER) ? 0 :
2380
2382
                            (uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
2381
2383
                                        HA_GET_INDEX),
2382
 
                            (EXTRA_RECORD),
 
2384
                            (open_mode == OTM_ALTER) ?
 
2385
                            (EXTRA_RECORD | OPEN_FRM_FILE_ONLY)
 
2386
                            : (EXTRA_RECORD),
2383
2387
                            ha_open_options,
2384
 
                            new_tmp_table))
 
2388
                            new_tmp_table, open_mode))
2385
2389
  {
2386
2390
    /* No need to lock share->mutex as this is not needed for tmp tables */
2387
2391
    share->free_table_share();
2390
2394
  }
2391
2395
 
2392
2396
  new_tmp_table->reginfo.lock_type= TL_WRITE;    // Simulate locked
2393
 
  share->tmp_table= (new_tmp_table->cursor->has_transactions() ?
2394
 
                     TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
 
2397
  if (open_mode == OTM_ALTER)
 
2398
  {
 
2399
    /*
 
2400
      Temporary table has been created with frm_only
 
2401
      and has not been created in any storage engine
 
2402
    */
 
2403
    share->tmp_table= TMP_TABLE_FRM_FILE_ONLY;
 
2404
  }
 
2405
  else
 
2406
    share->tmp_table= (new_tmp_table->file->has_transactions() ?
 
2407
                       TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
2395
2408
 
2396
2409
  if (link_in_list)
2397
2410
  {
4518
4531
 
4519
4532
bool drizzle_rm_tmp_tables()
4520
4533
{
 
4534
  char  filePath[FN_REFLEN], filePathCopy[FN_REFLEN];
4521
4535
  Session *session;
4522
4536
 
4523
4537
  assert(drizzle_tmpdir);
4527
4541
  session->thread_stack= (char*) &session;
4528
4542
  session->storeGlobals();
4529
4543
 
4530
 
  plugin::StorageEngine::removeLostTemporaryTables(*session, drizzle_tmpdir);
 
4544
  CachedDirectory dir(drizzle_tmpdir);
 
4545
 
 
4546
  if (dir.fail())
 
4547
  {
 
4548
    my_errno= dir.getError();
 
4549
    my_error(ER_CANT_READ_DIR, MYF(0), drizzle_tmpdir, my_errno);
 
4550
    return true;
 
4551
  }
 
4552
 
 
4553
  CachedDirectory::Entries files= dir.getEntries();
 
4554
  CachedDirectory::Entries::iterator fileIter= files.begin();
 
4555
 
 
4556
  /* Remove all temp tables in the tmpdir */
 
4557
  while (fileIter != files.end())
 
4558
  {
 
4559
    CachedDirectory::Entry *entry= *fileIter;
 
4560
    string prefix= entry->filename.substr(0, TMP_FILE_PREFIX_LENGTH);
 
4561
 
 
4562
    if (prefix == TMP_FILE_PREFIX)
 
4563
    {
 
4564
      char *ext= fn_ext(entry->filename.c_str());
 
4565
      uint32_t ext_len= strlen(ext);
 
4566
      uint32_t filePath_len= snprintf(filePath, sizeof(filePath),
 
4567
                                      "%s%c%s", drizzle_tmpdir, FN_LIBCHAR,
 
4568
                                      entry->filename.c_str());
 
4569
 
 
4570
      if (ext_len && !memcmp(drizzled::plugin::DEFAULT_DEFINITION_FILE_EXT.c_str(), ext, ext_len))
 
4571
      {
 
4572
        TableShare share;
 
4573
        /* We should cut file extention before deleting of table */
 
4574
        memcpy(filePathCopy, filePath, filePath_len - ext_len);
 
4575
        filePathCopy[filePath_len - ext_len]= 0;
 
4576
        share.init(NULL, filePathCopy);
 
4577
        if (!open_table_def(*session, &share))
 
4578
        {
 
4579
          share.db_type()->doDropTable(*session, filePathCopy);
 
4580
        }
 
4581
        share.free_table_share();
 
4582
      }
 
4583
      /*
 
4584
        File can be already deleted by tmp_table.file->delete_table().
 
4585
        So we hide error messages which happnes during deleting of these
 
4586
        files(MYF(0)).
 
4587
      */
 
4588
      my_delete(filePath, MYF(0));
 
4589
    }
 
4590
 
 
4591
    ++fileIter;
 
4592
  }
4531
4593
 
4532
4594
  delete session;
4533
4595