~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1983
1983
  return(false);
1984
1984
}
1985
1985
 
1986
 
 
1987
 
/**
1988
 
    Check that table exists in table definition cache, on disk
1989
 
    or in some storage engine.
1990
 
 
1991
 
    @param       session     Thread context
1992
 
    @param       table   Table list element
1993
 
    @param[out]  exists  Out parameter which is set to true if table
1994
 
                         exists and to false otherwise.
1995
 
 
1996
 
    @note This function assumes that caller owns LOCK_open mutex.
1997
 
          It also assumes that the fact that there are no name-locks
1998
 
          on the table was checked beforehand.
1999
 
 
2000
 
    @note If there is no .FRM file for the table but it exists in one
2001
 
          of engines (e.g. it was created on another node of NDB cluster)
2002
 
          this function will fetch and create proper .FRM file for it.
2003
 
 
2004
 
    @retval  true   Some error occured
2005
 
    @retval  false  No error. 'exists' out parameter set accordingly.
2006
 
*/
2007
 
 
2008
 
bool check_if_table_exists(TableList *table, bool *exists)
2009
 
{
2010
 
  char path[FN_REFLEN];
2011
 
 
2012
 
  safe_mutex_assert_owner(&LOCK_open);
2013
 
 
2014
 
  *exists= true;
2015
 
 
2016
 
  if (get_cached_table_share(table->db, table->table_name))
2017
 
    return(false);
2018
 
 
2019
 
  build_table_filename(path, sizeof(path) - 1, table->db, table->table_name,
2020
 
                       reg_ext, 0);
2021
 
 
2022
 
  if (!access(path, F_OK))
2023
 
    return(false);
2024
 
 
2025
 
  *exists= false;
2026
 
  return(false);
2027
 
}
2028
 
 
2029
 
 
2030
1986
/*
2031
1987
  Open a table.
2032
1988
 
2379
2335
 
2380
2336
    if (table_list->create)
2381
2337
    {
2382
 
      bool exists;
2383
 
 
2384
 
      if (check_if_table_exists(table_list, &exists))
 
2338
      if(ha_table_exists_in_engine(session, table_list->db,
 
2339
                                   table_list->table_name)
 
2340
         == HA_ERR_TABLE_EXIST)
2385
2341
      {
2386
2342
        pthread_mutex_unlock(&LOCK_open);
2387
2343
        return(NULL);
2388
2344
      }
2389
 
 
2390
 
      if (!exists)
 
2345
      else
2391
2346
      {
2392
2347
        /*
2393
2348
          Table to be created, so we need to create placeholder in table-cache.