summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
authorunknown <tim@cane.mysql.fi>2000-12-18 23:22:20 +0200
committerunknown <tim@cane.mysql.fi>2000-12-18 23:22:20 +0200
commit7cdb2b2d1d1efef069a305d130abf57d099c790e (patch)
tree6c7a3e5744b99f5ca62385fc84624366492f5c0b /sql/sql_base.cc
parent4c5b71f311965afc2ea81972652644eff80d0770 (diff)
downloadmariadb-git-7cdb2b2d1d1efef069a305d130abf57d099c790e.tar.gz
Added SHOW OPEN TABLES. Thanks to Antony T Curtis <antony@abacus.co.uk>
for the code. Docs/manual.texi: - added SHOW OPEN TABLES sql/gen_lex_hash.cc: - added SHOW OPEN TABLES sql/lex.h: - added SHOW OPEN TABLES sql/mysql_priv.h: - added SHOW OPEN TABLES sql/sql_base.cc: - added SHOW OPEN TABLES sql/sql_lex.h: - added SHOW OPEN TABLES sql/sql_parse.cc: - added SHOW OPEN TABLES sql/sql_show.cc: - added SHOW OPEN TABLES sql/sql_yacc.yy: - added SHOW OPEN TABLES
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r--sql/sql_base.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 623ed5dc0b6..74e8dccd4d7 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -112,6 +112,74 @@ static void check_unused(void)
#define check_unused()
#endif
+int list_open_tables(THD *thd,List<char> *tables, const char *db,const char *wild)
+{
+ int result = 0;
+ uint col_access=thd->col_access;
+ TABLE_LIST table_list;
+ DBUG_ENTER("list_open_tables");
+ VOID(pthread_mutex_lock(&LOCK_open));
+ bzero((char*) &table_list,sizeof(table_list));
+
+ for (uint idx=0 ; result == 0 && idx < open_cache.records; idx++)
+ {
+ TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
+ if ((!entry->real_name) || strcmp(entry->table_cache_key,db))
+ continue;
+ if (wild && wild[0] && wild_compare(entry->real_name,wild))
+ continue;
+ if (db && !(col_access & TABLE_ACLS))
+ {
+ table_list.db= (char*) db;
+ table_list.real_name= entry->real_name;/*real name*/
+ table_list.grant.privilege=col_access;
+ if (check_grant(thd,TABLE_ACLS,&table_list,1))
+ continue;
+ }
+ /* need to check if he have't already listed it */
+
+ List_iterator<char> it(*tables);
+ char *table_name;
+ int check = 0;
+ while (check == 0 && (table_name=it++))
+ {
+ if (!strcmp(table_name,entry->real_name))
+ check++;
+ }
+ if (check)
+ continue;
+
+ if (tables->push_back(thd->strdup(entry->real_name)))
+ {
+ result = -1;
+ }
+ }
+
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_RETURN(result);
+}
+
+char*
+query_table_status(THD *thd,const char *db,const char *table_name)
+{
+ int cached = 0, in_use = 0;
+ char info[256];
+
+ for (uint idx=0 ; idx < open_cache.records; idx++)
+ {
+ TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
+ if (strcmp(entry->table_cache_key,db) ||
+ strcmp(entry->real_name,table_name))
+ continue;
+
+ cached++;
+ if (entry->in_use)
+ in_use++;
+ }
+
+ sprintf(info, "cached=%d, in_use=%d", cached, in_use);
+ return thd->strdup(info);
+}
/******************************************************************************