~jaypipes/drizzle/bug534806

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2010-02-27 01:53:04 UTC
  • mfrom: (1309.1.17 fix_is)
  • Revision ID: brian@gaz-20100227015304-xxruqg8c4snj32u3
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
}
162
162
 
163
163
 
164
 
 
165
 
/*
166
 
  Create a list for all open tables matching SQL expression
167
 
 
168
 
  SYNOPSIS
169
 
  list_open_tables()
170
 
  wild          SQL like expression
171
 
 
172
 
  NOTES
173
 
  One gets only a list of tables for which one has any kind of privilege.
174
 
  db and table names are allocated in result struct, so one doesn't need
175
 
  a lock on LOCK_open when traversing the return list.
176
 
 
177
 
  RETURN VALUES
178
 
  true  Error 
179
 
*/
180
 
 
181
 
bool list_open_tables(const char *db, 
182
 
                      const char *wild, 
183
 
                      bool(*func)(Table *table, 
184
 
                                  open_table_list_st& open_list,
185
 
                                  plugin::InfoSchemaTable *schema_table), 
186
 
                      Table *display,
187
 
                      plugin::InfoSchemaTable *schema_table)
188
 
{
189
 
  vector<open_table_list_st> open_list;
190
 
  vector<open_table_list_st>::iterator it;
191
 
  open_table_list_st table;
192
 
 
193
 
  /* What we really need is an optimization for knowing unique tables */
194
 
  if (db && wild)
195
 
    open_list.reserve(sizeof(open_table_list_st) * (open_cache.records % 2));
196
 
  else
197
 
    open_list.reserve(sizeof(open_table_list_st) * open_cache.records);
198
 
 
199
 
  pthread_mutex_lock(&LOCK_open); /* List all open tables */
200
 
 
201
 
  for (uint32_t idx= 0; idx < open_cache.records; idx++)
202
 
  {
203
 
    bool found= false;
204
 
    Table *entry=(Table*) hash_element(&open_cache,idx);
205
 
 
206
 
    if (db && my_strcasecmp(system_charset_info, db, entry->s->db.str))
207
 
      continue;
208
 
    if (wild && internal::wild_compare(entry->s->table_name.str, wild, 0))
209
 
      continue;
210
 
 
211
 
    for (it= open_list.begin(); it < open_list.end(); it++)
212
 
    {
213
 
      if (!(*it).table.compare(entry->s->table_name.str) &&
214
 
          !(*it).db.compare(entry->s->db.str))
215
 
      {
216
 
        if (entry->in_use)
217
 
          (*it).in_use++;
218
 
        if (entry->locked_by_name)
219
 
          (*it).locked++;
220
 
 
221
 
        found= true;
222
 
 
223
 
        break;
224
 
      }
225
 
    }
226
 
 
227
 
    if (found)
228
 
      continue;
229
 
 
230
 
    table.db= entry->s->db.str;
231
 
    table.table= entry->s->table_name.str;
232
 
    open_list.push_back(table);
233
 
  }
234
 
  pthread_mutex_unlock(&LOCK_open);
235
 
 
236
 
  for (it= open_list.begin(); it < open_list.end(); it++)
237
 
  {
238
 
    if (func(display, *it, schema_table))
239
 
      return true;
240
 
  }
241
 
 
242
 
  return false;
243
 
}
244
 
 
245
164
/*****************************************************************************
246
165
 *       Functions to free open table cache
247
166
 ****************************************************************************/
4457
4376
and afterwards delete those marked unused.
4458
4377
*/
4459
4378
 
4460
 
void remove_db_from_cache(const char *db)
 
4379
void remove_db_from_cache(const std::string schema_name)
4461
4380
{
4462
4381
  safe_mutex_assert_owner(&LOCK_open);
4463
4382
 
4464
4383
  for (uint32_t idx=0 ; idx < open_cache.records ; idx++)
4465
4384
  {
4466
4385
    Table *table=(Table*) hash_element(&open_cache,idx);
4467
 
    if (not strcmp(table->s->db.str, db))
 
4386
    if (not strcmp(table->s->db.str, schema_name.c_str()))
4468
4387
    {
4469
4388
      table->s->version= 0L;                    /* Free when thread is ready */
4470
4389
      if (not table->in_use)