~mdcallag/+junk/5.1-map

« back to all changes in this revision

Viewing changes to sql/sql_base.cc

  • Committer: sasha at sashanet
  • Date: 2001-04-12 01:09:00 UTC
  • mfrom: (669.1.1)
  • Revision ID: sp1r-sasha@mysql.sashanet.com-20010412010900-14282
Ugly merge of 3.23 changes into 4.0 - fix up needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
#define check_unused()
112
112
#endif
113
113
 
114
 
int list_open_tables(THD *thd,List<char> *tables, const char *db,
115
 
                     const char *wild)
 
114
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild)
116
115
{
117
116
  int result = 0;
118
117
  uint col_access=thd->col_access;
 
118
  OPEN_TABLE_LIST **start_list, *open_list;
119
119
  TABLE_LIST table_list;
 
120
  char name[NAME_LEN*2];
120
121
  DBUG_ENTER("list_open_tables");
 
122
 
121
123
  VOID(pthread_mutex_lock(&LOCK_open));
122
124
  bzero((char*) &table_list,sizeof(table_list));
 
125
  start_list= &open_list;
 
126
  open_list=0;
123
127
 
124
128
  for (uint idx=0 ; result == 0 && idx < open_cache.records; idx++)
125
129
  {
 
130
    OPEN_TABLE_LIST *table;
126
131
    TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
127
 
    if ((!entry->real_name) || strcmp(entry->table_cache_key,db))
128
 
      continue;
129
 
    if (wild && wild[0] && wild_compare(entry->real_name,wild))
130
 
      continue;
131
 
    if (db && !(col_access & TABLE_ACLS))
132
 
    {
133
 
      table_list.db= (char*) db;
134
 
      table_list.real_name= entry->real_name;/*real name*/
135
 
      table_list.grant.privilege=col_access;
136
 
      if (check_grant(thd,TABLE_ACLS,&table_list,1))
137
 
        continue;
138
 
    }
139
 
    /* need to check if he have't already listed it */
140
 
 
141
 
    List_iterator<char> it(*tables);
142
 
    char *table_name; 
143
 
    int check = 0;
144
 
    while (check == 0 && (table_name=it++))
145
 
    {
146
 
      if (!strcmp(table_name,entry->real_name))
147
 
        check++;
148
 
    }
149
 
    if (check)
150
 
      continue;
151
 
    
152
 
    if (tables->push_back(thd->strdup(entry->real_name)))
153
 
    {
154
 
      result = -1;
155
 
    }
 
132
 
 
133
    if ((!entry->real_name))
 
134
      continue;                                 // Shouldn't happen
 
135
    if (wild)
 
136
    {
 
137
      strxmov(name,entry->table_cache_key,".",entry->real_name,NullS);
 
138
      if (wild_compare(name,wild))
 
139
        continue;
 
140
    }
 
141
 
 
142
    /* Check if user has SELECT privilege for any column in the table */
 
143
    table_list.db= (char*) entry->table_cache_key;
 
144
    table_list.real_name= entry->real_name;
 
145
    table_list.grant.privilege=0;
 
146
    if (check_table_access(thd,SELECT_ACL | EXTRA_ACL,&table_list))
 
147
      continue;
 
148
 
 
149
    /* need to check if we haven't already listed it */
 
150
    for (table= open_list  ; table ; table=table->next)
 
151
    {
 
152
      if (!strcmp(table->table,entry->real_name) &&
 
153
          !strcmp(table->db,entry->table_cache_key))
 
154
      {
 
155
        if (entry->in_use)
 
156
          table->in_use++;
 
157
        if (entry->locked_by_name)
 
158
          table->locked++;
 
159
        break;
 
160
      }
 
161
    }
 
162
    if (table)
 
163
      continue;
 
164
    if (!(*start_list = (OPEN_TABLE_LIST *)
 
165
          sql_alloc(sizeof(OPEN_TABLE_LIST)+entry->key_length)))
 
166
    {
 
167
      open_list=0;                              // Out of memory
 
168
      break;
 
169
    }
 
170
    (*start_list)->table=(strmov((*start_list)->db=(char*) ((*start_list)+1),
 
171
                                 entry->table_cache_key)+1,
 
172
                          entry->real_name);
 
173
    (*start_list)->in_use= entry->in_use ? 1 : 0;
 
174
    (*start_list)->locked= entry->locked_by_name ? 1 : 0;
 
175
    start_list= &(*start_list)->next;
156
176
  }
157
 
  
158
177
  VOID(pthread_mutex_unlock(&LOCK_open));
159
 
  DBUG_RETURN(result);  
160
 
}
161
 
 
162
 
char*
163
 
query_table_status(THD *thd,const char *db,const char *table_name)
164
 
{
165
 
  int cached = 0, in_use = 0;
166
 
  char info[256];
167
 
 
168
 
  for (uint idx=0 ; idx < open_cache.records; idx++)
169
 
  {
170
 
    TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
171
 
    if (strcmp(entry->table_cache_key,db) ||
172
 
        strcmp(entry->real_name,table_name))
173
 
      continue;
174
 
 
175
 
    cached++;
176
 
    if (entry->in_use)
177
 
      in_use++;
178
 
  }
179
 
 
180
 
  sprintf(info, "cached=%d, in_use=%d", cached, in_use);
181
 
  return thd->strdup(info);
 
178
  DBUG_RETURN(open_list);
182
179
}
183
180
 
184
181
 
258
255
    if (my_net_write(&thd->net, (char*) packet->ptr(),packet->length()))
259
256
      break;                                    /* purecov: inspected */
260
257
  }
261
 
  send_eof(&thd->net,(test_flags & TEST_MIT_THREAD) ? 0: 1);
 
258
  send_eof(&thd->net);
262
259
  return 0;
263
260
 err:
264
261
  send_error(&thd->net,ER_OUT_OF_RESOURCES);    /* purecov: inspected */