2004-10-07 10:50:13 +03:00
|
|
|
/* Copyright (C) 2000-2004 MySQL AB
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
|
|
|
|
/* Function with list databases, tables or fields */
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
2000-09-01 15:24:36 +04:00
|
|
|
#include "sql_select.h" // For select_describe
|
2001-10-10 15:36:35 -06:00
|
|
|
#include "repl_failsafe.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#include <my_dir.h>
|
2000-11-29 05:09:28 +02:00
|
|
|
|
2000-12-15 13:18:52 +02:00
|
|
|
#ifdef HAVE_BERKELEY_DB
|
|
|
|
#include "ha_berkeley.h" // For berkeley_show_logs
|
|
|
|
#endif
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
static const char *grant_names[]={
|
|
|
|
"select","insert","update","delete","create","drop","reload","shutdown",
|
|
|
|
"process","file","grant","references","index","alter"};
|
|
|
|
|
2004-04-05 13:56:05 +03:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2000-07-31 21:29:14 +02:00
|
|
|
static TYPELIB grant_types = { sizeof(grant_names)/sizeof(char **),
|
2000-09-01 15:24:36 +04:00
|
|
|
"grant_types",
|
2004-10-25 17:51:26 +05:00
|
|
|
grant_names, NULL};
|
2004-04-05 13:56:05 +03:00
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
static int
|
2000-10-10 21:31:00 +02:00
|
|
|
store_create_info(THD *thd, TABLE *table, String *packet);
|
|
|
|
|
2001-08-27 03:34:52 +08:00
|
|
|
|
2003-06-27 16:29:10 +03:00
|
|
|
/*
|
|
|
|
Report list of databases
|
|
|
|
A database is a directory in the mysql_data_home directory
|
|
|
|
*/
|
2003-01-15 12:11:44 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int
|
|
|
|
mysqld_show_dbs(THD *thd,const char *wild)
|
|
|
|
{
|
2003-02-26 14:54:57 +04:00
|
|
|
Item_string *field=new Item_string("",0,thd->charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
List<Item> field_list;
|
|
|
|
char *end;
|
|
|
|
List<char> files;
|
|
|
|
char *file_name;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_show_dbs");
|
|
|
|
|
2000-08-22 00:18:32 +03:00
|
|
|
field->name=(char*) thd->alloc(20+ (wild ? (uint) strlen(wild)+4: 0));
|
2000-07-31 21:29:14 +02:00
|
|
|
field->max_length=NAME_LEN;
|
|
|
|
end=strmov(field->name,"Database");
|
|
|
|
if (wild && wild[0])
|
|
|
|
strxmov(end," (",wild,")",NullS);
|
|
|
|
field_list.push_back(field);
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
if (mysql_find_files(thd,&files,NullS,mysql_data_home,wild,1))
|
|
|
|
DBUG_RETURN(1);
|
2001-08-02 06:29:50 +03:00
|
|
|
List_iterator_fast<char> it(files);
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
while ((file_name=it++))
|
|
|
|
{
|
2003-09-26 15:33:13 +05:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2002-06-12 15:04:18 +03:00
|
|
|
if (thd->master_access & (DB_ACLS | SHOW_DB_ACL) ||
|
2003-10-24 23:27:21 +02:00
|
|
|
acl_get(thd->host, thd->ip, thd->priv_user, file_name,0) ||
|
2000-12-26 17:34:04 +02:00
|
|
|
(grant_option && !check_grant_db(thd, file_name)))
|
2003-09-26 15:33:13 +05:00
|
|
|
#endif
|
2002-06-12 15:04:18 +03:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(file_name, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2000-12-26 17:34:04 +02:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2000-12-18 23:22:20 +02:00
|
|
|
/***************************************************************************
|
2002-10-02 13:33:08 +03:00
|
|
|
List all open tables in a database
|
2000-12-18 23:22:20 +02:00
|
|
|
***************************************************************************/
|
|
|
|
|
2001-07-11 10:36:22 +03:00
|
|
|
int mysqld_show_open_tables(THD *thd,const char *wild)
|
2000-12-18 23:22:20 +02:00
|
|
|
{
|
|
|
|
List<Item> field_list;
|
2001-07-11 10:36:22 +03:00
|
|
|
OPEN_TABLE_LIST *open_list;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2000-12-18 23:22:20 +02:00
|
|
|
DBUG_ENTER("mysqld_show_open_tables");
|
|
|
|
|
2001-07-11 10:36:22 +03:00
|
|
|
field_list.push_back(new Item_empty_string("Database",NAME_LEN));
|
|
|
|
field_list.push_back(new Item_empty_string("Table",NAME_LEN));
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(new Item_return_int("In_use", 1, MYSQL_TYPE_TINY));
|
|
|
|
field_list.push_back(new Item_return_int("Name_locked", 4, MYSQL_TYPE_TINY));
|
2000-12-18 23:22:20 +02:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-12-18 23:22:20 +02:00
|
|
|
DBUG_RETURN(1);
|
2000-12-22 12:25:49 +01:00
|
|
|
|
2003-01-30 22:15:44 +02:00
|
|
|
if (!(open_list=list_open_tables(thd,wild)) && thd->is_fatal_error)
|
2000-12-18 23:22:20 +02:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
|
2002-06-11 11:20:31 +03:00
|
|
|
for (; open_list ; open_list=open_list->next)
|
2000-12-18 23:22:20 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(open_list->db, system_charset_info);
|
|
|
|
protocol->store(open_list->table, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_tiny((longlong) open_list->in_use);
|
|
|
|
protocol->store_tiny((longlong) open_list->locked);
|
|
|
|
if (protocol->write())
|
2002-08-05 18:50:38 +03:00
|
|
|
{
|
2000-12-18 23:22:20 +02:00
|
|
|
DBUG_RETURN(-1);
|
2002-08-05 18:50:38 +03:00
|
|
|
}
|
2000-12-18 23:22:20 +02:00
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-12-18 23:22:20 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-08-05 18:50:38 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/***************************************************************************
|
|
|
|
** List all tables in a database (fast version)
|
|
|
|
** A table is a .frm file in the current databasedir
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
int mysqld_show_tables(THD *thd,const char *db,const char *wild)
|
|
|
|
{
|
2003-02-26 14:54:57 +04:00
|
|
|
Item_string *field=new Item_string("",0,thd->charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
List<Item> field_list;
|
|
|
|
char path[FN_LEN],*end;
|
|
|
|
List<char> files;
|
|
|
|
char *file_name;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_show_tables");
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
field->name=(char*) thd->alloc(20+(uint) strlen(db)+
|
|
|
|
(wild ? (uint) strlen(wild)+4:0));
|
2000-07-31 21:29:14 +02:00
|
|
|
end=strxmov(field->name,"Tables_in_",db,NullS);
|
|
|
|
if (wild && wild[0])
|
|
|
|
strxmov(end," (",wild,")",NullS);
|
|
|
|
field->max_length=NAME_LEN;
|
|
|
|
(void) sprintf(path,"%s/%s",mysql_data_home,db);
|
|
|
|
(void) unpack_dirname(path,path);
|
|
|
|
field_list.push_back(field);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
if (mysql_find_files(thd,&files,db,path,wild,0))
|
|
|
|
DBUG_RETURN(-1);
|
2001-08-02 06:29:50 +03:00
|
|
|
List_iterator_fast<char> it(files);
|
2000-07-31 21:29:14 +02:00
|
|
|
while ((file_name=it++))
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(file_name, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
/***************************************************************************
|
|
|
|
** List all table types supported
|
|
|
|
***************************************************************************/
|
|
|
|
|
2003-12-17 22:52:03 +00:00
|
|
|
int mysqld_show_storage_engines(THD *thd)
|
2002-06-12 14:13:12 -07:00
|
|
|
{
|
|
|
|
List<Item> field_list;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2003-12-17 22:52:03 +00:00
|
|
|
DBUG_ENTER("mysqld_show_storage_engines");
|
2002-06-12 14:13:12 -07:00
|
|
|
|
2004-04-27 15:33:40 +03:00
|
|
|
field_list.push_back(new Item_empty_string("Engine",10));
|
2002-06-12 14:13:12 -07:00
|
|
|
field_list.push_back(new Item_empty_string("Support",10));
|
2002-10-02 13:33:08 +03:00
|
|
|
field_list.push_back(new Item_empty_string("Comment",80));
|
2002-06-12 14:13:12 -07:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2003-12-02 20:23:13 +00:00
|
|
|
const char *default_type_name=
|
2003-12-17 22:52:03 +00:00
|
|
|
ha_get_storage_engine((enum db_type)thd->variables.table_type);
|
2002-06-12 14:13:12 -07:00
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
show_table_type_st *types;
|
|
|
|
for (types= sys_table_types; types->type; types++)
|
2002-06-12 14:13:12 -07:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(types->type, system_charset_info);
|
2002-10-02 13:33:08 +03:00
|
|
|
const char *option_name= show_comp_option_name[(int) *types->value];
|
|
|
|
|
|
|
|
if (*types->value == SHOW_OPTION_YES &&
|
2002-10-08 22:28:24 +03:00
|
|
|
!my_strcasecmp(system_charset_info, default_type_name, types->type))
|
2002-10-02 13:33:08 +03:00
|
|
|
option_name= "DEFAULT";
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(option_name, system_charset_info);
|
|
|
|
protocol->store(types->comment, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
/***************************************************************************
|
2002-10-02 13:33:08 +03:00
|
|
|
List all privileges supported
|
2002-06-12 14:13:12 -07:00
|
|
|
***************************************************************************/
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
struct show_privileges_st {
|
|
|
|
const char *privilege;
|
|
|
|
const char *context;
|
|
|
|
const char *comment;
|
2002-06-12 14:13:12 -07:00
|
|
|
};
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
static struct show_privileges_st sys_privileges[]=
|
|
|
|
{
|
2004-03-24 14:44:31 +01:00
|
|
|
{"Alter", "Tables", "To alter the table"},
|
|
|
|
{"Create temporary tables","Databases","To use CREATE TEMPORARY TABLE"},
|
2002-10-02 13:33:08 +03:00
|
|
|
{"Create", "Databases,Tables,Indexes", "To create new databases and tables"},
|
2004-03-24 14:44:31 +01:00
|
|
|
{"Delete", "Tables", "To delete existing rows"},
|
|
|
|
{"Drop", "Databases,Tables", "To drop databases and tables"},
|
|
|
|
{"File", "File access on server", "To read and write files on the server"},
|
|
|
|
{"Grant option", "Databases,Tables", "To give to other users those privileges you possess"},
|
|
|
|
{"Index", "Tables", "To create or drop indexes"},
|
|
|
|
{"Insert", "Tables", "To insert data into tables"},
|
|
|
|
{"Lock tables","Databases","To use LOCK TABLES (together with SELECT privilege)"},
|
|
|
|
{"Process", "Server Admin", "To view the plain text of currently executing queries"},
|
2002-10-02 13:33:08 +03:00
|
|
|
{"References", "Databases,Tables", "To have references on tables"},
|
2004-03-24 14:44:31 +01:00
|
|
|
{"Reload", "Server Admin", "To reload or refresh tables, logs and privileges"},
|
|
|
|
{"Replication client","Server Admin","To ask where the slave or master servers are"},
|
|
|
|
{"Replication slave","Server Admin","To read binary log events from the master"},
|
|
|
|
{"Select", "Tables", "To retrieve rows from table"},
|
|
|
|
{"Show databases","Server Admin","To see all databases with SHOW DATABASES"},
|
2002-10-02 13:33:08 +03:00
|
|
|
{"Shutdown","Server Admin", "To shutdown the server"},
|
2004-03-24 14:44:31 +01:00
|
|
|
{"Super","Server Admin","To use KILL thread, SET GLOBAL, CHANGE MASTER, etc."},
|
|
|
|
{"Update", "Tables", "To update existing rows"},
|
|
|
|
{"Usage","Server Admin","No privileges - allow connect only"},
|
2002-10-02 13:33:08 +03:00
|
|
|
{NullS, NullS, NullS}
|
|
|
|
};
|
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
int mysqld_show_privileges(THD *thd)
|
|
|
|
{
|
|
|
|
List<Item> field_list;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_ENTER("mysqld_show_privileges");
|
|
|
|
|
|
|
|
field_list.push_back(new Item_empty_string("Privilege",10));
|
|
|
|
field_list.push_back(new Item_empty_string("Context",15));
|
|
|
|
field_list.push_back(new Item_empty_string("Comment",NAME_LEN));
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
show_privileges_st *privilege= sys_privileges;
|
|
|
|
for (privilege= sys_privileges; privilege->privilege ; privilege++)
|
2002-06-12 14:13:12 -07:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(privilege->privilege, system_charset_info);
|
|
|
|
protocol->store(privilege->context, system_charset_info);
|
|
|
|
protocol->store(privilege->comment, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2002-10-02 13:33:08 +03:00
|
|
|
List all column types
|
2002-06-12 14:13:12 -07:00
|
|
|
***************************************************************************/
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
struct show_column_type_st
|
|
|
|
{
|
2002-06-12 14:13:12 -07:00
|
|
|
const char *type;
|
|
|
|
uint size;
|
2002-10-02 13:33:08 +03:00
|
|
|
const char *min_value;
|
|
|
|
const char *max_value;
|
|
|
|
uint precision;
|
|
|
|
uint scale;
|
|
|
|
const char *nullable;
|
|
|
|
const char *auto_increment;
|
|
|
|
const char *unsigned_attr;
|
|
|
|
const char *zerofill;
|
|
|
|
const char *searchable;
|
|
|
|
const char *case_sensitivity;
|
|
|
|
const char *default_value;
|
|
|
|
const char *comment;
|
2002-06-12 14:13:12 -07:00
|
|
|
};
|
2002-10-02 13:33:08 +03:00
|
|
|
|
|
|
|
/* TODO: Add remaning types */
|
|
|
|
|
|
|
|
static struct show_column_type_st sys_column_types[]=
|
|
|
|
{
|
2002-06-12 14:13:12 -07:00
|
|
|
{"tinyint",
|
|
|
|
1, "-128", "127", 0, 0, "YES", "YES",
|
2004-03-24 14:44:31 +01:00
|
|
|
"NO", "YES", "YES", "NO", "NULL,0",
|
|
|
|
"A very small integer"},
|
2002-06-12 14:13:12 -07:00
|
|
|
{"tinyint unsigned",
|
2004-03-24 14:44:31 +01:00
|
|
|
1, "0" , "255", 0, 0, "YES", "YES",
|
|
|
|
"YES", "YES", "YES", "NO", "NULL,0",
|
2002-06-12 14:13:12 -07:00
|
|
|
"A very small integer"},
|
|
|
|
};
|
|
|
|
|
|
|
|
int mysqld_show_column_types(THD *thd)
|
|
|
|
{
|
|
|
|
List<Item> field_list;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_ENTER("mysqld_show_column_types");
|
|
|
|
|
|
|
|
field_list.push_back(new Item_empty_string("Type",30));
|
|
|
|
field_list.push_back(new Item_int("Size",(longlong) 1,21));
|
|
|
|
field_list.push_back(new Item_empty_string("Min_Value",20));
|
|
|
|
field_list.push_back(new Item_empty_string("Max_Value",20));
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(new Item_return_int("Prec", 4, MYSQL_TYPE_SHORT));
|
|
|
|
field_list.push_back(new Item_return_int("Scale", 4, MYSQL_TYPE_SHORT));
|
2002-06-12 14:13:12 -07:00
|
|
|
field_list.push_back(new Item_empty_string("Nullable",4));
|
|
|
|
field_list.push_back(new Item_empty_string("Auto_Increment",4));
|
|
|
|
field_list.push_back(new Item_empty_string("Unsigned",4));
|
|
|
|
field_list.push_back(new Item_empty_string("Zerofill",4));
|
|
|
|
field_list.push_back(new Item_empty_string("Searchable",4));
|
|
|
|
field_list.push_back(new Item_empty_string("Case_Sensitive",4));
|
|
|
|
field_list.push_back(new Item_empty_string("Default",NAME_LEN));
|
|
|
|
field_list.push_back(new Item_empty_string("Comment",NAME_LEN));
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
/* TODO: Change the loop to not use 'i' */
|
2002-06-12 14:13:12 -07:00
|
|
|
for (uint i=0; i < sizeof(sys_column_types)/sizeof(sys_column_types[0]); i++)
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(sys_column_types[i].type, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store((ulonglong) sys_column_types[i].size);
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(sys_column_types[i].min_value, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].max_value, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_short((longlong) sys_column_types[i].precision);
|
|
|
|
protocol->store_short((longlong) sys_column_types[i].scale);
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(sys_column_types[i].nullable, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].auto_increment, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].unsigned_attr, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].zerofill, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].searchable, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].case_sensitivity, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].default_value, system_charset_info);
|
|
|
|
protocol->store(sys_column_types[i].comment, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2002-06-12 14:13:12 -07:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-10 11:13:05 +02:00
|
|
|
int
|
2000-07-31 21:29:14 +02:00
|
|
|
mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
|
2000-09-01 15:24:36 +04:00
|
|
|
const char *wild, bool dir)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
char *ext;
|
|
|
|
MY_DIR *dirp;
|
|
|
|
FILEINFO *file;
|
2004-04-05 13:56:05 +03:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2000-07-31 21:29:14 +02:00
|
|
|
uint col_access=thd->col_access;
|
2004-04-05 13:56:05 +03:00
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
TABLE_LIST table_list;
|
|
|
|
DBUG_ENTER("mysql_find_files");
|
|
|
|
|
2001-08-28 06:43:55 +03:00
|
|
|
if (wild && !wild[0])
|
|
|
|
wild=0;
|
2004-09-21 12:13:58 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
bzero((char*) &table_list,sizeof(table_list));
|
|
|
|
|
|
|
|
if (!(dirp = my_dir(path,MYF(MY_WME | (dir ? MY_WANT_STAT : 0)))))
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
|
2000-09-01 15:24:36 +04:00
|
|
|
for (i=0 ; i < (uint) dirp->number_off_files ; i++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
file=dirp->dir_entry+i;
|
|
|
|
if (dir)
|
2000-09-01 15:24:36 +04:00
|
|
|
{ /* Return databases */
|
2000-07-31 21:29:14 +02:00
|
|
|
#ifdef USE_SYMDIR
|
|
|
|
char *ext;
|
2004-09-25 18:43:07 +02:00
|
|
|
char buff[FN_REFLEN];
|
2000-07-31 21:29:14 +02:00
|
|
|
if (my_use_symdir && !strcmp(ext=fn_ext(file->name), ".sym"))
|
2003-12-11 06:24:08 +02:00
|
|
|
{
|
|
|
|
/* Only show the sym file if it points to a directory */
|
2004-09-25 18:43:07 +02:00
|
|
|
char *end;
|
2000-09-01 15:24:36 +04:00
|
|
|
*ext=0; /* Remove extension */
|
2003-12-11 06:24:08 +02:00
|
|
|
unpack_dirname(buff, file->name);
|
|
|
|
end= strend(buff);
|
|
|
|
if (end != buff && end[-1] == FN_LIBCHAR)
|
|
|
|
end[-1]= 0; // Remove end FN_LIBCHAR
|
2004-09-25 18:43:07 +02:00
|
|
|
if (!my_stat(buff, file->mystat, MYF(0)))
|
|
|
|
continue;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
#endif
|
2003-12-12 03:39:29 +03:00
|
|
|
if (file->name[0] == '.' || !MY_S_ISDIR(file->mystat->st_mode) ||
|
2003-07-22 22:21:23 +02:00
|
|
|
(wild && wild_compare(file->name,wild,0)))
|
2000-09-01 15:24:36 +04:00
|
|
|
continue;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-12-18 23:22:20 +02:00
|
|
|
// Return only .frm files which aren't temp files.
|
2002-03-12 21:37:58 +04:00
|
|
|
if (my_strcasecmp(system_charset_info, ext=fn_ext(file->name),reg_ext) ||
|
2000-12-18 23:22:20 +02:00
|
|
|
is_prefix(file->name,tmp_file_prefix))
|
2000-09-01 15:24:36 +04:00
|
|
|
continue;
|
2000-07-31 21:29:14 +02:00
|
|
|
*ext=0;
|
2001-08-28 06:43:55 +03:00
|
|
|
if (wild)
|
|
|
|
{
|
|
|
|
if (lower_case_table_names)
|
|
|
|
{
|
2004-05-22 23:41:58 +04:00
|
|
|
if (wild_case_compare(files_charset_info, file->name, wild))
|
2001-08-28 06:43:55 +03:00
|
|
|
continue;
|
|
|
|
}
|
2003-07-22 22:21:23 +02:00
|
|
|
else if (wild_compare(file->name,wild,0))
|
2001-08-28 06:43:55 +03:00
|
|
|
continue;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-09-26 15:33:13 +05:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2000-07-31 21:29:14 +02:00
|
|
|
/* Don't show tables where we don't have any privileges */
|
|
|
|
if (db && !(col_access & TABLE_ACLS))
|
|
|
|
{
|
|
|
|
table_list.db= (char*) db;
|
|
|
|
table_list.real_name=file->name;
|
|
|
|
table_list.grant.privilege=col_access;
|
2004-04-10 01:14:32 +03:00
|
|
|
if (check_grant(thd, TABLE_ACLS, &table_list, 1, UINT_MAX, 1))
|
2000-09-01 15:24:36 +04:00
|
|
|
continue;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-09-26 15:33:13 +05:00
|
|
|
#endif
|
2000-08-21 03:00:52 +03:00
|
|
|
if (files->push_back(thd->strdup(file->name)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
my_dirend(dirp);
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_PRINT("info",("found: %d files", files->elements));
|
|
|
|
my_dirend(dirp);
|
2004-09-26 16:11:24 +02:00
|
|
|
|
|
|
|
VOID(ha_find_files(thd,db,path,wild,dir,files));
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/***************************************************************************
|
2002-10-02 13:33:08 +03:00
|
|
|
Extended version of mysqld_show_tables
|
2000-07-31 21:29:14 +02:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
|
|
|
|
{
|
|
|
|
Item *item;
|
|
|
|
List<char> files;
|
|
|
|
List<Item> field_list;
|
|
|
|
char path[FN_LEN];
|
|
|
|
char *file_name;
|
|
|
|
TABLE *table;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
TIME time;
|
2005-10-03 23:22:46 +04:00
|
|
|
int res= 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_extend_show_tables");
|
|
|
|
|
|
|
|
(void) sprintf(path,"%s/%s",mysql_data_home,db);
|
|
|
|
(void) unpack_dirname(path,path);
|
|
|
|
field_list.push_back(item=new Item_empty_string("Name",NAME_LEN));
|
2004-04-27 15:33:40 +03:00
|
|
|
field_list.push_back(item=new Item_empty_string("Engine",10));
|
2000-07-31 21:29:14 +02:00
|
|
|
item->maybe_null=1;
|
2004-06-24 18:46:41 +05:00
|
|
|
field_list.push_back(item=new Item_int("Version", (longlong) 0, 21));
|
|
|
|
item->maybe_null=1;
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(item=new Item_empty_string("Row_format",10));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_int("Rows",(longlong) 1,21));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_int("Avg_row_length",(int32) 0,21));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_int("Data_length",(longlong) 1,21));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_int("Max_data_length",(longlong) 1,21));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_int("Index_length",(longlong) 1,21));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_int("Data_free",(longlong) 1,21));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_int("Auto_increment",(longlong) 1,21));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_datetime("Create_time"));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_datetime("Update_time"));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_datetime("Check_time"));
|
|
|
|
item->maybe_null=1;
|
2003-09-16 12:36:36 +05:00
|
|
|
field_list.push_back(item=new Item_empty_string("Collation",32));
|
2002-10-01 13:54:59 +05:00
|
|
|
item->maybe_null=1;
|
2003-08-05 21:14:15 +02:00
|
|
|
field_list.push_back(item=new Item_int("Checksum",(longlong) 1,21));
|
|
|
|
item->maybe_null=1;
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(item=new Item_empty_string("Create_options",255));
|
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_empty_string("Comment",80));
|
2003-02-26 09:52:19 +02:00
|
|
|
item->maybe_null=1;
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
if (mysql_find_files(thd,&files,db,path,wild,0))
|
|
|
|
DBUG_RETURN(-1);
|
2001-08-02 06:29:50 +03:00
|
|
|
List_iterator_fast<char> it(files);
|
2000-07-31 21:29:14 +02:00
|
|
|
while ((file_name=it++))
|
|
|
|
{
|
|
|
|
TABLE_LIST table_list;
|
|
|
|
bzero((char*) &table_list,sizeof(table_list));
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(file_name, system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
table_list.db=(char*) db;
|
2002-09-20 14:05:18 +03:00
|
|
|
table_list.real_name= table_list.alias= file_name;
|
2003-01-29 18:56:34 +02:00
|
|
|
if (lower_case_table_names)
|
2003-02-07 15:47:24 +02:00
|
|
|
my_casedn_str(files_charset_info, file_name);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(table = open_ltable(thd, &table_list, TL_READ)))
|
|
|
|
{
|
2003-02-26 10:16:50 +02:00
|
|
|
for (uint i=2 ; i < field_list.elements ; i++)
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
2003-02-24 17:05:03 -08:00
|
|
|
// Send error to Comment field
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(thd->net.last_error, system_charset_info);
|
2004-02-09 12:31:03 +01:00
|
|
|
thd->clear_error();
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
const char *str;
|
2000-07-31 21:29:14 +02:00
|
|
|
handler *file=table->file;
|
|
|
|
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(file->table_type(), system_charset_info);
|
2004-06-24 18:46:41 +05:00
|
|
|
protocol->store((ulonglong) table->frm_version);
|
2002-12-11 09:17:51 +02:00
|
|
|
str= ((table->db_options_in_use & HA_OPTION_COMPRESS_RECORD) ?
|
|
|
|
"Compressed" :
|
|
|
|
(table->db_options_in_use & HA_OPTION_PACK_RECORD) ?
|
|
|
|
"Dynamic" : "Fixed");
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(str, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store((ulonglong) file->records);
|
|
|
|
protocol->store((ulonglong) file->mean_rec_length);
|
|
|
|
protocol->store((ulonglong) file->data_file_length);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (file->max_data_file_length)
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store((ulonglong) file->max_data_file_length);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
|
|
|
protocol->store((ulonglong) file->index_file_length);
|
|
|
|
protocol->store((ulonglong) file->delete_length);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (table->found_next_number_field)
|
|
|
|
{
|
2000-09-01 15:24:36 +04:00
|
|
|
table->next_number_field=table->found_next_number_field;
|
|
|
|
table->next_number_field->reset();
|
|
|
|
file->update_auto_increment();
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store(table->next_number_field->val_int());
|
2000-09-01 15:24:36 +04:00
|
|
|
table->next_number_field=0;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!file->create_time)
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
2004-06-18 10:11:31 +04:00
|
|
|
thd->variables.time_zone->gmt_sec_to_TIME(&time, file->create_time);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store(&time);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
if (!file->update_time)
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
2004-06-18 10:11:31 +04:00
|
|
|
thd->variables.time_zone->gmt_sec_to_TIME(&time, file->update_time);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store(&time);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
if (!file->check_time)
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
2004-06-18 10:11:31 +04:00
|
|
|
thd->variables.time_zone->gmt_sec_to_TIME(&time, file->check_time);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store(&time);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
str= (table->table_charset ? table->table_charset->name : "default");
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(str, system_charset_info);
|
2003-08-05 21:14:15 +02:00
|
|
|
if (file->table_flags() & HA_HAS_CHECKSUM)
|
|
|
|
protocol->store((ulonglong)file->checksum());
|
|
|
|
else
|
|
|
|
protocol->store_null(); // Checksum
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2000-09-01 15:24:36 +04:00
|
|
|
char option_buff[350],*ptr;
|
|
|
|
ptr=option_buff;
|
|
|
|
if (table->min_rows)
|
|
|
|
{
|
|
|
|
ptr=strmov(ptr," min_rows=");
|
|
|
|
ptr=longlong10_to_str(table->min_rows,ptr,10);
|
|
|
|
}
|
|
|
|
if (table->max_rows)
|
|
|
|
{
|
|
|
|
ptr=strmov(ptr," max_rows=");
|
|
|
|
ptr=longlong10_to_str(table->max_rows,ptr,10);
|
|
|
|
}
|
|
|
|
if (table->avg_row_length)
|
|
|
|
{
|
|
|
|
ptr=strmov(ptr," avg_row_length=");
|
|
|
|
ptr=longlong10_to_str(table->avg_row_length,ptr,10);
|
|
|
|
}
|
|
|
|
if (table->db_create_options & HA_OPTION_PACK_KEYS)
|
|
|
|
ptr=strmov(ptr," pack_keys=1");
|
|
|
|
if (table->db_create_options & HA_OPTION_NO_PACK_KEYS)
|
|
|
|
ptr=strmov(ptr," pack_keys=0");
|
|
|
|
if (table->db_create_options & HA_OPTION_CHECKSUM)
|
|
|
|
ptr=strmov(ptr," checksum=1");
|
|
|
|
if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
|
|
|
|
ptr=strmov(ptr," delay_key_write=1");
|
|
|
|
if (table->row_type != ROW_TYPE_DEFAULT)
|
2001-09-30 05:47:35 +03:00
|
|
|
ptr=strxmov(ptr, " row_format=", ha_row_type[(uint) table->row_type],
|
2000-09-01 15:24:36 +04:00
|
|
|
NullS);
|
|
|
|
if (file->raid_type)
|
|
|
|
{
|
|
|
|
char buff[100];
|
|
|
|
sprintf(buff," raid_type=%s raid_chunks=%d raid_chunksize=%ld",
|
|
|
|
my_raid_type(file->raid_type), file->raid_chunks, file->raid_chunksize/RAID_BLOCK_SIZE);
|
|
|
|
ptr=strmov(ptr,buff);
|
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store(option_buff+1,
|
2003-03-17 13:14:04 +04:00
|
|
|
(ptr == option_buff ? 0 : (uint) (ptr-option_buff)-1)
|
|
|
|
, system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2001-02-17 14:19:19 +02:00
|
|
|
{
|
|
|
|
char *comment=table->file->update_table_comment(table->comment);
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(comment, system_charset_info);
|
2001-02-17 14:19:19 +02:00
|
|
|
if (comment != table->comment)
|
|
|
|
my_free(comment,MYF(0));
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
close_thread_tables(thd,0);
|
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2005-10-03 23:22:46 +04:00
|
|
|
{
|
|
|
|
res= -1;
|
|
|
|
break;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2005-10-03 23:22:46 +04:00
|
|
|
thd->insert_id(0);
|
|
|
|
if (!res)
|
|
|
|
send_eof(thd);
|
|
|
|
DBUG_RETURN(res);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:47:54 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/***************************************************************************
|
2002-09-21 21:36:23 +03:00
|
|
|
** List all columns in a table_list->real_name
|
2000-07-31 21:29:14 +02:00
|
|
|
***************************************************************************/
|
2003-01-15 12:11:44 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int
|
2001-01-22 05:32:58 +02:00
|
|
|
mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
|
|
|
|
bool verbose)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
handler *file;
|
|
|
|
char tmp[MAX_FIELD_WIDTH];
|
2004-08-11 14:03:24 +05:00
|
|
|
char tmp1[MAX_FIELD_WIDTH];
|
2002-05-31 15:22:38 +03:00
|
|
|
Item *item;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_show_fields");
|
|
|
|
DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
|
2000-09-01 15:24:36 +04:00
|
|
|
table_list->real_name));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
|
|
|
|
{
|
2002-10-02 13:33:08 +03:00
|
|
|
send_error(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
file=table->file;
|
|
|
|
file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
|
2003-09-26 15:33:13 +05:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2000-07-31 21:29:14 +02:00
|
|
|
(void) get_table_grant(thd, table_list);
|
2003-09-26 15:33:13 +05:00
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
List<Item> field_list;
|
|
|
|
field_list.push_back(new Item_empty_string("Field",NAME_LEN));
|
2005-09-09 13:22:16 +05:00
|
|
|
field_list.push_back(new Item_empty_string("Type", 40));
|
2003-06-02 17:19:06 +05:00
|
|
|
if (verbose)
|
|
|
|
field_list.push_back(new Item_empty_string("Collation",40));
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Null",1));
|
|
|
|
field_list.push_back(new Item_empty_string("Key",3));
|
2002-05-31 15:22:38 +03:00
|
|
|
field_list.push_back(item=new Item_empty_string("Default",NAME_LEN));
|
|
|
|
item->maybe_null=1;
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Extra",20));
|
2001-01-22 05:32:58 +02:00
|
|
|
if (verbose)
|
2002-06-02 21:22:20 +03:00
|
|
|
{
|
2001-01-22 05:32:58 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Privileges",80));
|
2002-06-02 21:22:20 +03:00
|
|
|
field_list.push_back(new Item_empty_string("Comment",255));
|
|
|
|
}
|
2000-09-01 15:24:36 +04:00
|
|
|
// Send first number of fields and records
|
2003-01-20 18:47:25 +04:00
|
|
|
if (protocol->send_records_num(&field_list, (ulonglong)file->records) ||
|
|
|
|
protocol->send_fields(&field_list,0))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
2003-05-03 01:16:56 +02:00
|
|
|
restore_record(table,default_values); // Get empty record
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
Field **ptr,*field;
|
|
|
|
for (ptr=table->field; (field= *ptr) ; ptr++)
|
|
|
|
{
|
2002-03-12 21:37:58 +04:00
|
|
|
if (!wild || !wild[0] ||
|
|
|
|
!wild_case_compare(system_charset_info, field->field_name,wild))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
{
|
2000-09-01 15:24:36 +04:00
|
|
|
byte *pos;
|
|
|
|
uint flags=field->flags;
|
2003-12-16 17:39:33 +04:00
|
|
|
String type(tmp,sizeof(tmp), system_charset_info);
|
2004-07-08 15:45:25 +03:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2000-09-01 15:24:36 +04:00
|
|
|
uint col_access;
|
2004-07-08 15:45:25 +03:00
|
|
|
#endif
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(field->field_name, system_charset_info);
|
2000-09-01 15:24:36 +04:00
|
|
|
field->sql_type(type);
|
2003-12-16 17:39:33 +04:00
|
|
|
protocol->store(type.ptr(), type.length(), system_charset_info);
|
2003-06-02 17:19:06 +05:00
|
|
|
if (verbose)
|
|
|
|
protocol->store(field->has_charset() ? field->charset()->name : "NULL",
|
2003-05-23 13:10:25 +05:00
|
|
|
system_charset_info);
|
2004-01-30 15:13:19 +03:00
|
|
|
/*
|
2004-10-01 18:54:06 +04:00
|
|
|
Even if TIMESTAMP field can't contain NULL as its value it
|
2004-01-30 15:13:19 +03:00
|
|
|
will accept NULL if you will try to insert such value and will
|
2004-10-01 18:54:06 +04:00
|
|
|
convert NULL value to current TIMESTAMP. So YES here means
|
|
|
|
that NULL is allowed for assignment (but may be won't be
|
|
|
|
returned).
|
2004-01-30 15:13:19 +03:00
|
|
|
*/
|
2000-09-01 15:24:36 +04:00
|
|
|
pos=(byte*) ((flags & NOT_NULL_FLAG) &&
|
|
|
|
field->type() != FIELD_TYPE_TIMESTAMP ?
|
|
|
|
"" : "YES");
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store((const char*) pos, system_charset_info);
|
2000-09-01 15:24:36 +04:00
|
|
|
pos=(byte*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
|
|
|
|
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
|
|
|
|
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store((char*) pos, system_charset_info);
|
2000-09-01 15:24:36 +04:00
|
|
|
|
2004-04-02 10:12:53 +04:00
|
|
|
if (table->timestamp_field == field &&
|
|
|
|
field->unireg_check != Field::TIMESTAMP_UN_FIELD)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We have NOW() as default value but we use CURRENT_TIMESTAMP form
|
|
|
|
because it is more SQL standard comatible
|
|
|
|
*/
|
|
|
|
protocol->store("CURRENT_TIMESTAMP", system_charset_info);
|
|
|
|
}
|
2004-04-06 21:35:26 +02:00
|
|
|
else if (field->unireg_check != Field::NEXT_NUMBER &&
|
2004-04-02 10:12:53 +04:00
|
|
|
!field->is_null())
|
2000-09-01 15:24:36 +04:00
|
|
|
{ // Not null by default
|
2004-08-11 14:03:24 +05:00
|
|
|
/*
|
|
|
|
Note: we have to convert the default value into
|
|
|
|
system_charset_info before sending.
|
|
|
|
This is necessary for "SET NAMES binary":
|
|
|
|
If the client character set is binary, we want to
|
|
|
|
send metadata in UTF8 rather than in the column's
|
|
|
|
character set.
|
|
|
|
This conversion also makes "SHOW COLUMNS" and
|
|
|
|
"SHOW CREATE TABLE" output consistent. Without
|
|
|
|
this conversion the default values were displayed
|
|
|
|
differently.
|
|
|
|
*/
|
|
|
|
String def(tmp1,sizeof(tmp1), system_charset_info);
|
2003-12-15 21:01:38 +04:00
|
|
|
type.set(tmp, sizeof(tmp), field->charset());
|
2004-04-06 21:35:26 +02:00
|
|
|
field->val_str(&type);
|
2004-10-29 17:00:39 +05:00
|
|
|
uint dummy_errors;
|
2004-08-11 14:03:24 +05:00
|
|
|
def.copy(type.ptr(), type.length(), type.charset(),
|
2004-10-29 17:00:39 +05:00
|
|
|
system_charset_info, &dummy_errors);
|
2004-08-11 14:03:24 +05:00
|
|
|
protocol->store(def.ptr(), def.length(), def.charset());
|
2000-09-01 15:24:36 +04:00
|
|
|
}
|
2004-04-02 10:12:53 +04:00
|
|
|
else if (field->unireg_check == Field::NEXT_NUMBER ||
|
|
|
|
field->maybe_null())
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null(); // Null as default
|
2000-09-01 15:24:36 +04:00
|
|
|
else
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store("",0, system_charset_info); // empty string
|
2000-09-01 15:24:36 +04:00
|
|
|
|
|
|
|
char *end=tmp;
|
|
|
|
if (field->unireg_check == Field::NEXT_NUMBER)
|
|
|
|
end=strmov(tmp,"auto_increment");
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(tmp,(uint) (end-tmp), system_charset_info);
|
2000-09-01 15:24:36 +04:00
|
|
|
|
2001-01-22 05:32:58 +02:00
|
|
|
if (verbose)
|
|
|
|
{
|
2002-06-02 21:22:20 +03:00
|
|
|
/* Add grant options & comments */
|
2001-01-22 05:32:58 +02:00
|
|
|
end=tmp;
|
2003-09-26 15:33:13 +05:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2002-06-17 16:24:51 +05:00
|
|
|
col_access= get_column_grant(thd,table_list,field) & COL_ACLS;
|
2001-01-22 05:32:58 +02:00
|
|
|
for (uint bitnr=0; col_access ; col_access>>=1,bitnr++)
|
|
|
|
{
|
|
|
|
if (col_access & 1)
|
|
|
|
{
|
|
|
|
*end++=',';
|
|
|
|
end=strmov(end,grant_types.type_names[bitnr]);
|
|
|
|
}
|
|
|
|
}
|
2003-09-26 15:33:13 +05:00
|
|
|
#else
|
|
|
|
end=strmov(end,"");
|
|
|
|
#endif
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(tmp+1,end == tmp ? 0 : (uint) (end-tmp-1),
|
|
|
|
system_charset_info);
|
|
|
|
protocol->store(field->comment.str, field->comment.length,
|
|
|
|
system_charset_info);
|
2001-01-22 05:32:58 +02:00
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2000-09-01 15:24:36 +04:00
|
|
|
DBUG_RETURN(1);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int
|
|
|
|
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
char buff[2048];
|
|
|
|
String buffer(buff, sizeof(buff), system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_show_create");
|
|
|
|
DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
|
2000-09-01 15:24:36 +04:00
|
|
|
table_list->real_name));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2000-10-04 23:20:16 +03:00
|
|
|
/* Only one table for now */
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
|
|
|
|
{
|
2002-10-02 13:33:08 +03:00
|
|
|
send_error(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
2005-01-10 16:03:06 +01:00
|
|
|
buffer.length(0);
|
2003-08-29 13:44:35 +03:00
|
|
|
if (store_create_info(thd, table, &buffer))
|
2003-08-21 20:21:07 +02:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
List<Item> field_list;
|
|
|
|
field_list.push_back(new Item_empty_string("Table",NAME_LEN));
|
2003-08-29 13:44:35 +03:00
|
|
|
// 1024 is for not to confuse old clients
|
2003-08-21 21:14:02 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Create Table",
|
2003-08-29 13:44:35 +03:00
|
|
|
max(buffer.length(),1024)));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list, 1))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(table->table_name, system_charset_info);
|
|
|
|
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-01-30 07:32:35 +01:00
|
|
|
int mysqld_show_create_db(THD *thd, char *dbname,
|
|
|
|
HA_CREATE_INFO *create_info)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
char path[FN_REFLEN];
|
|
|
|
char buff[2048];
|
|
|
|
String buffer(buff, sizeof(buff), system_charset_info);
|
2004-04-05 13:56:05 +03:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2004-01-30 07:32:35 +01:00
|
|
|
uint db_access;
|
2004-04-05 13:56:05 +03:00
|
|
|
#endif
|
2004-01-30 07:32:35 +01:00
|
|
|
bool found_libchar;
|
|
|
|
HA_CREATE_INFO create;
|
|
|
|
uint create_options = create_info ? create_info->options : 0;
|
|
|
|
Protocol *protocol=thd->protocol;
|
|
|
|
DBUG_ENTER("mysql_show_create_db");
|
|
|
|
|
|
|
|
if (check_db_name(dbname))
|
|
|
|
{
|
|
|
|
net_printf(thd,ER_WRONG_DB_NAME, dbname);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
if (test_all_bits(thd->master_access,DB_ACLS))
|
|
|
|
db_access=DB_ACLS;
|
|
|
|
else
|
|
|
|
db_access= (acl_get(thd->host,thd->ip, thd->priv_user,dbname,0) |
|
|
|
|
thd->master_access);
|
|
|
|
if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname)))
|
|
|
|
{
|
|
|
|
net_printf(thd,ER_DBACCESS_DENIED_ERROR,
|
|
|
|
thd->priv_user, thd->host_or_ip, dbname);
|
|
|
|
mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
|
|
|
|
thd->priv_user, thd->host_or_ip, dbname);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void) sprintf(path,"%s/%s",mysql_data_home, dbname);
|
|
|
|
length=unpack_dirname(path,path); // Convert if not unix
|
|
|
|
found_libchar= 0;
|
|
|
|
if (length && path[length-1] == FN_LIBCHAR)
|
|
|
|
{
|
|
|
|
found_libchar= 1;
|
|
|
|
path[length-1]=0; // remove ending '\'
|
|
|
|
}
|
|
|
|
if (access(path,F_OK))
|
|
|
|
{
|
|
|
|
net_printf(thd,ER_BAD_DB_ERROR,dbname);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
if (found_libchar)
|
|
|
|
path[length-1]= FN_LIBCHAR;
|
|
|
|
strmov(path+length, MY_DB_OPT_FILE);
|
|
|
|
load_db_opt(thd, path, &create);
|
|
|
|
|
|
|
|
List<Item> field_list;
|
|
|
|
field_list.push_back(new Item_empty_string("Database",NAME_LEN));
|
|
|
|
field_list.push_back(new Item_empty_string("Create Database",1024));
|
|
|
|
|
|
|
|
if (protocol->send_fields(&field_list,1))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
protocol->prepare_for_resend();
|
|
|
|
protocol->store(dbname, strlen(dbname), system_charset_info);
|
|
|
|
buffer.length(0);
|
|
|
|
buffer.append("CREATE DATABASE ", 16);
|
|
|
|
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
|
|
|
|
buffer.append("/*!32312 IF NOT EXISTS*/ ", 25);
|
|
|
|
append_identifier(thd, &buffer, dbname, strlen(dbname));
|
|
|
|
|
|
|
|
if (create.default_table_charset)
|
|
|
|
{
|
|
|
|
buffer.append(" /*!40100", 9);
|
|
|
|
buffer.append(" DEFAULT CHARACTER SET ", 23);
|
|
|
|
buffer.append(create.default_table_charset->csname);
|
|
|
|
if (!(create.default_table_charset->state & MY_CS_PRIMARY))
|
|
|
|
{
|
|
|
|
buffer.append(" COLLATE ", 9);
|
|
|
|
buffer.append(create.default_table_charset->name);
|
|
|
|
}
|
|
|
|
buffer.append(" */", 3);
|
|
|
|
}
|
|
|
|
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
|
|
|
|
|
|
|
|
if (protocol->write())
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
send_eof(thd);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2000-12-15 13:18:52 +02:00
|
|
|
int
|
|
|
|
mysqld_show_logs(THD *thd)
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
List<Item> field_list;
|
|
|
|
Protocol *protocol= thd->protocol;
|
2000-12-15 13:18:52 +02:00
|
|
|
DBUG_ENTER("mysqld_show_logs");
|
|
|
|
|
|
|
|
field_list.push_back(new Item_empty_string("File",FN_REFLEN));
|
|
|
|
field_list.push_back(new Item_empty_string("Type",10));
|
|
|
|
field_list.push_back(new Item_empty_string("Status",10));
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-12-15 13:18:52 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2000-12-15 18:01:17 +02:00
|
|
|
#ifdef HAVE_BERKELEY_DB
|
2004-03-02 10:08:50 +00:00
|
|
|
if ((have_berkeley_db == SHOW_OPTION_YES) && berkeley_show_logs(protocol))
|
2001-01-22 04:46:32 +02:00
|
|
|
DBUG_RETURN(-1);
|
2000-12-15 18:01:17 +02:00
|
|
|
#endif
|
2000-12-15 13:18:52 +02:00
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-12-15 13:18:52 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int
|
|
|
|
mysqld_show_keys(THD *thd, TABLE_LIST *table_list)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_show_keys");
|
|
|
|
DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
|
2000-09-01 15:24:36 +04:00
|
|
|
table_list->real_name));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
|
|
|
|
{
|
2002-10-02 13:33:08 +03:00
|
|
|
send_error(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Item> field_list;
|
|
|
|
Item *item;
|
|
|
|
field_list.push_back(new Item_empty_string("Table",NAME_LEN));
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(new Item_return_int("Non_unique",1, MYSQL_TYPE_TINY));
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Key_name",NAME_LEN));
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(new Item_return_int("Seq_in_index",2, MYSQL_TYPE_TINY));
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Column_name",NAME_LEN));
|
|
|
|
field_list.push_back(item=new Item_empty_string("Collation",1));
|
|
|
|
item->maybe_null=1;
|
2002-11-14 12:21:36 +02:00
|
|
|
field_list.push_back(item=new Item_int("Cardinality",0,21));
|
2000-07-31 21:29:14 +02:00
|
|
|
item->maybe_null=1;
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(item=new Item_return_int("Sub_part",3,
|
2005-04-16 23:35:39 +04:00
|
|
|
MYSQL_TYPE_SHORT));
|
2000-07-31 21:29:14 +02:00
|
|
|
item->maybe_null=1;
|
|
|
|
field_list.push_back(item=new Item_empty_string("Packed",10));
|
|
|
|
item->maybe_null=1;
|
2002-01-02 21:29:41 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Null",3));
|
|
|
|
field_list.push_back(new Item_empty_string("Index_type",16));
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Comment",255));
|
|
|
|
item->maybe_null=1;
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
KEY *key_info=table->key_info;
|
|
|
|
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
|
|
|
|
for (uint i=0 ; i < table->keys ; i++,key_info++)
|
|
|
|
{
|
|
|
|
KEY_PART_INFO *key_part= key_info->key_part;
|
2002-12-11 09:17:51 +02:00
|
|
|
const char *str;
|
2000-07-31 21:29:14 +02:00
|
|
|
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(table->table_name, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_tiny((longlong) ((key_info->flags & HA_NOSAME) ? 0 :1));
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(key_info->name, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_tiny((longlong) (j+1));
|
|
|
|
str=(key_part->field ? key_part->field->field_name :
|
|
|
|
"?unknown field?");
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(str, system_charset_info);
|
2004-07-08 15:45:25 +03:00
|
|
|
if (table->file->index_flags(i, j, 0) & HA_READ_ORDER)
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store(((key_part->key_part_flag & HA_REVERSE_SORT) ?
|
2003-03-17 13:14:04 +04:00
|
|
|
"D" : "A"), 1, system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null(); /* purecov: inspected */
|
2000-07-31 21:29:14 +02:00
|
|
|
KEY *key=table->key_info+i;
|
|
|
|
if (key->rec_per_key[j])
|
|
|
|
{
|
2002-11-14 12:21:36 +02:00
|
|
|
ha_rows records=(table->file->records / key->rec_per_key[j]);
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store((ulonglong) records);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
2002-01-02 21:29:41 +02:00
|
|
|
|
|
|
|
/* Check if we have a key part that only uses part of the field */
|
2004-02-04 17:42:18 +01:00
|
|
|
if (!(key_info->flags & HA_FULLTEXT) && (!key_part->field ||
|
|
|
|
key_part->length != table->field[key_part->fieldnr-1]->key_length()))
|
2005-04-16 23:35:39 +04:00
|
|
|
protocol->store_short((longlong) key_part->length /
|
2005-01-21 16:49:20 +04:00
|
|
|
key_part->field->charset()->mbmaxlen);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
|
|
|
protocol->store_null(); // No pack_information yet
|
2002-01-02 21:29:41 +02:00
|
|
|
|
|
|
|
/* Null flag */
|
|
|
|
uint flags= key_part->field ? key_part->field->flags : 0;
|
2002-01-29 18:32:16 +02:00
|
|
|
char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store((const char*) pos, system_charset_info);
|
|
|
|
protocol->store(table->file->index_type(i), system_charset_info);
|
2002-01-02 21:29:41 +02:00
|
|
|
/* Comment */
|
2003-10-11 13:06:55 +02:00
|
|
|
if (!table->keys_in_use.is_set(i))
|
2003-05-19 16:35:49 +03:00
|
|
|
protocol->store("disabled",8, system_charset_info);
|
2003-04-03 20:24:15 +03:00
|
|
|
else
|
2003-05-19 16:35:49 +03:00
|
|
|
protocol->store("", 0, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2000-09-01 15:24:36 +04:00
|
|
|
DBUG_RETURN(1); /* purecov: inspected */
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2002-10-02 13:33:08 +03:00
|
|
|
Return only fields for API mysql_list_fields
|
|
|
|
Use "show table wildcard" in mysql instead of this
|
2000-07-31 21:29:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
DBUG_ENTER("mysqld_list_fields");
|
|
|
|
DBUG_PRINT("enter",("table: %s",table_list->real_name));
|
|
|
|
|
|
|
|
if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
|
|
|
|
{
|
2002-10-02 13:33:08 +03:00
|
|
|
send_error(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
List<Item> field_list;
|
|
|
|
|
|
|
|
Field **ptr,*field;
|
|
|
|
for (ptr=table->field ; (field= *ptr); ptr++)
|
|
|
|
{
|
2002-03-12 21:37:58 +04:00
|
|
|
if (!wild || !wild[0] ||
|
|
|
|
!wild_case_compare(system_charset_info, field->field_name,wild))
|
2004-03-20 13:36:26 +02:00
|
|
|
field_list.push_back(new Item_field(field));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-05-03 01:16:56 +02:00
|
|
|
restore_record(table,default_values); // Get empty record
|
2002-12-11 09:17:51 +02:00
|
|
|
if (thd->protocol->send_fields(&field_list,2))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2004-11-02 20:13:27 +02:00
|
|
|
thd->protocol->flush();
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int
|
|
|
|
mysqld_dump_create_info(THD *thd, TABLE *table, int fd)
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
String *packet= protocol->storage_packet();
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_dump_create_info");
|
|
|
|
DBUG_PRINT("enter",("table: %s",table->real_name));
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
|
|
|
if (store_create_info(thd, table, packet))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(-1);
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2001-04-11 13:04:03 +02:00
|
|
|
if (fd < 0)
|
2000-09-01 15:24:36 +04:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2000-09-01 15:24:36 +04:00
|
|
|
DBUG_RETURN(-1);
|
2004-11-02 20:13:27 +02:00
|
|
|
protocol->flush();
|
2000-09-01 15:24:36 +04:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2000-09-01 15:24:36 +04:00
|
|
|
{
|
2001-10-08 23:20:19 +03:00
|
|
|
if (my_write(fd, (const byte*) packet->ptr(), packet->length(),
|
|
|
|
MYF(MY_WME)))
|
2000-09-01 15:24:36 +04:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2004-02-07 00:57:22 +04:00
|
|
|
/*
|
2004-02-17 01:35:17 +02:00
|
|
|
Go through all character combinations and ensure that sql_lex.cc can
|
|
|
|
parse it as an identifer.
|
2004-02-07 00:57:22 +04:00
|
|
|
|
|
|
|
SYNOPSIS
|
2004-02-17 01:35:17 +02:00
|
|
|
require_quotes()
|
|
|
|
name attribute name
|
|
|
|
name_length length of name
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
# Pointer to conflicting character
|
|
|
|
0 No conflicting character
|
2004-02-07 00:57:22 +04:00
|
|
|
*/
|
|
|
|
|
2004-02-17 01:35:17 +02:00
|
|
|
static const char *require_quotes(const char *name, uint name_length)
|
2004-02-07 00:57:22 +04:00
|
|
|
{
|
2004-02-17 01:35:17 +02:00
|
|
|
uint length;
|
|
|
|
const char *end= name + name_length;
|
|
|
|
|
|
|
|
for ( ; name < end ; name++)
|
2004-02-07 00:57:22 +04:00
|
|
|
{
|
2004-02-17 01:35:17 +02:00
|
|
|
uchar chr= (uchar) *name;
|
2004-10-20 01:28:42 +03:00
|
|
|
length= my_mbcharlen(system_charset_info, chr);
|
2004-02-17 01:35:17 +02:00
|
|
|
if (length == 1 && !system_charset_info->ident_map[chr])
|
|
|
|
return name;
|
2004-01-14 11:52:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2004-02-17 01:35:17 +02:00
|
|
|
|
2003-06-27 16:29:10 +03:00
|
|
|
void
|
|
|
|
append_identifier(THD *thd, String *packet, const char *name, uint length)
|
2000-10-10 21:31:00 +02:00
|
|
|
{
|
2004-02-17 01:35:17 +02:00
|
|
|
const char *name_end;
|
2004-10-20 01:28:42 +03:00
|
|
|
char quote_char;
|
2004-10-01 11:51:59 +03:00
|
|
|
int q= get_quote_char_for_identifier(thd, name, length);
|
2004-02-17 01:35:17 +02:00
|
|
|
|
2004-10-20 01:28:42 +03:00
|
|
|
if (q == EOF)
|
|
|
|
{
|
2004-10-01 11:51:59 +03:00
|
|
|
packet->append(name, length, system_charset_info);
|
2004-02-17 01:35:17 +02:00
|
|
|
return;
|
2000-10-10 21:31:00 +02:00
|
|
|
}
|
2004-02-17 01:35:17 +02:00
|
|
|
|
2004-10-20 01:28:42 +03:00
|
|
|
/*
|
|
|
|
The identifier must be quoted as it includes a quote character or
|
|
|
|
it's a keyword
|
|
|
|
*/
|
2004-02-17 01:35:17 +02:00
|
|
|
|
|
|
|
packet->reserve(length*2 + 2);
|
2004-10-20 01:28:42 +03:00
|
|
|
quote_char= (char) q;
|
2004-02-17 01:35:17 +02:00
|
|
|
packet->append("e_char, 1, system_charset_info);
|
|
|
|
|
|
|
|
for (name_end= name+length ; name < name_end ; name+= length)
|
|
|
|
{
|
2004-10-20 01:28:42 +03:00
|
|
|
uchar chr= (uchar) *name;
|
|
|
|
length= my_mbcharlen(system_charset_info, chr);
|
2004-12-02 11:39:50 +04:00
|
|
|
/*
|
|
|
|
my_mbcharlen can retur 0 on a wrong multibyte
|
|
|
|
sequence. It is possible when upgrading from 4.0,
|
|
|
|
and identifier contains some accented characters.
|
|
|
|
The manual says it does not work. So we'll just
|
|
|
|
change length to 1 not to hang in the endless loop.
|
|
|
|
*/
|
|
|
|
if (!length)
|
|
|
|
length= 1;
|
2004-10-20 01:28:42 +03:00
|
|
|
if (length == 1 && chr == (uchar) quote_char)
|
2004-02-17 01:35:17 +02:00
|
|
|
packet->append("e_char, 1, system_charset_info);
|
|
|
|
packet->append(name, length, packet->charset());
|
2000-10-10 21:31:00 +02:00
|
|
|
}
|
2004-02-17 01:35:17 +02:00
|
|
|
packet->append("e_char, 1, system_charset_info);
|
2000-10-10 21:31:00 +02:00
|
|
|
}
|
|
|
|
|
2003-08-23 12:25:39 +03:00
|
|
|
|
2004-10-20 01:28:42 +03:00
|
|
|
/*
|
|
|
|
Get the quote character for displaying an identifier.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
get_quote_char_for_identifier()
|
|
|
|
thd Thread handler
|
|
|
|
name name to quote
|
|
|
|
length length of name
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
If name is a keyword or includes a special character, then force
|
|
|
|
quoting.
|
|
|
|
Otherwise identifier is quoted only if the option OPTION_QUOTE_SHOW_CREATE
|
|
|
|
is set.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
EOF No quote character is needed
|
|
|
|
# Quote character
|
|
|
|
*/
|
2004-10-01 11:51:59 +03:00
|
|
|
|
|
|
|
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
|
|
|
|
{
|
|
|
|
if (!is_keyword(name,length) &&
|
|
|
|
!require_quotes(name, length) &&
|
|
|
|
!(thd->options & OPTION_QUOTE_SHOW_CREATE))
|
|
|
|
return EOF;
|
2004-10-20 01:28:42 +03:00
|
|
|
if (thd->variables.sql_mode & MODE_ANSI_QUOTES)
|
2004-10-01 11:51:59 +03:00
|
|
|
return '"';
|
2004-10-20 01:28:42 +03:00
|
|
|
return '`';
|
2004-10-01 11:51:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-23 12:25:39 +03:00
|
|
|
/* Append directory name (if exists) to CREATE INFO */
|
|
|
|
|
|
|
|
static void append_directory(THD *thd, String *packet, const char *dir_type,
|
|
|
|
const char *filename)
|
|
|
|
{
|
2003-09-11 19:06:23 +03:00
|
|
|
if (filename && !(thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE))
|
2003-08-23 12:25:39 +03:00
|
|
|
{
|
2004-10-20 01:28:42 +03:00
|
|
|
uint length= dirname_length(filename);
|
2003-08-23 12:25:39 +03:00
|
|
|
packet->append(' ');
|
|
|
|
packet->append(dir_type);
|
|
|
|
packet->append(" DIRECTORY='", 12);
|
2005-03-15 11:33:06 -06:00
|
|
|
#ifdef __WIN__
|
2005-03-15 16:24:37 -06:00
|
|
|
char *winfilename = thd->memdup(filename, length);
|
2005-03-15 11:33:06 -06:00
|
|
|
for (uint i=0; i < length; i++)
|
|
|
|
if (winfilename[i] == '\\')
|
|
|
|
winfilename[i] = '/';
|
|
|
|
packet->append(winfilename, length);
|
|
|
|
#else
|
2003-08-23 12:25:39 +03:00
|
|
|
packet->append(filename, length);
|
2005-03-15 11:33:06 -06:00
|
|
|
#endif
|
2003-08-23 12:25:39 +03:00
|
|
|
packet->append('\'');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-16 19:17:54 +02:00
|
|
|
#define LIST_PROCESS_HOST_LEN 64
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
static int
|
2000-10-10 21:31:00 +02:00
|
|
|
store_create_info(THD *thd, TABLE *table, String *packet)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-08-23 12:25:39 +03:00
|
|
|
List<Item> field_list;
|
2004-02-11 00:06:46 +01:00
|
|
|
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], *end, *alias;
|
2004-05-25 15:54:03 +05:00
|
|
|
String type(tmp, sizeof(tmp), system_charset_info);
|
2003-08-23 12:25:39 +03:00
|
|
|
Field **ptr,*field;
|
|
|
|
uint primary_key;
|
|
|
|
KEY *key_info;
|
|
|
|
handler *file= table->file;
|
|
|
|
HA_CREATE_INFO create_info;
|
2003-06-04 18:28:51 +03:00
|
|
|
my_bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL |
|
|
|
|
MODE_ORACLE |
|
|
|
|
MODE_MSSQL |
|
|
|
|
MODE_DB2 |
|
2003-10-15 14:50:36 +05:00
|
|
|
MODE_MAXDB |
|
2003-06-04 18:28:51 +03:00
|
|
|
MODE_ANSI)) != 0;
|
|
|
|
my_bool limited_mysql_mode= (thd->variables.sql_mode &
|
|
|
|
(MODE_NO_FIELD_OPTIONS | MODE_MYSQL323 |
|
|
|
|
MODE_MYSQL40)) != 0;
|
2003-07-22 22:21:23 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("store_create_info");
|
|
|
|
DBUG_PRINT("enter",("table: %s",table->real_name));
|
|
|
|
|
2003-05-03 01:16:56 +02:00
|
|
|
restore_record(table,default_values); // Get empty record
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2001-04-25 22:44:27 +03:00
|
|
|
if (table->tmp_table)
|
|
|
|
packet->append("CREATE TEMPORARY TABLE ", 23);
|
|
|
|
else
|
|
|
|
packet->append("CREATE TABLE ", 13);
|
2004-02-11 00:06:46 +01:00
|
|
|
alias= (lower_case_table_names == 2 ? table->table_name :
|
|
|
|
table->real_name);
|
|
|
|
append_identifier(thd, packet, alias, strlen(alias));
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append(" (\n", 3);
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
for (ptr=table->field ; (field= *ptr); ptr++)
|
|
|
|
{
|
2003-08-23 12:25:39 +03:00
|
|
|
bool has_default;
|
2004-04-02 10:12:53 +04:00
|
|
|
bool has_now_default;
|
2003-08-23 12:25:39 +03:00
|
|
|
uint flags = field->flags;
|
|
|
|
|
2001-02-17 14:19:19 +02:00
|
|
|
if (ptr != table->field)
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append(",\n", 2);
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append(" ", 2);
|
2003-06-27 16:29:10 +03:00
|
|
|
append_identifier(thd,packet,field->field_name, strlen(field->field_name));
|
2000-07-31 21:29:14 +02:00
|
|
|
packet->append(' ');
|
|
|
|
// check for surprises from the previous call to Field::sql_type()
|
2001-02-17 14:19:19 +02:00
|
|
|
if (type.ptr() != tmp)
|
2004-06-08 14:26:16 +05:00
|
|
|
type.set(tmp, sizeof(tmp), system_charset_info);
|
2004-09-24 13:14:44 +05:00
|
|
|
else
|
|
|
|
type.set_charset(system_charset_info);
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
field->sql_type(type);
|
2004-05-25 15:54:03 +05:00
|
|
|
packet->append(type.ptr(), type.length(), system_charset_info);
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2005-09-29 16:17:45 +05:00
|
|
|
if (field->has_charset() &&
|
|
|
|
!(thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)))
|
2003-01-09 15:37:59 +04:00
|
|
|
{
|
2004-03-26 16:11:46 +04:00
|
|
|
if (field->charset() != table->table_charset)
|
2003-05-23 13:10:25 +05:00
|
|
|
{
|
2004-03-26 16:11:46 +04:00
|
|
|
packet->append(" character set ", 15);
|
|
|
|
packet->append(field->charset()->csname);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
For string types dump collation name only if
|
|
|
|
collation is not primary for the given charset
|
|
|
|
*/
|
|
|
|
if (!(field->charset()->state & MY_CS_PRIMARY))
|
|
|
|
{
|
|
|
|
packet->append(" collate ", 9);
|
|
|
|
packet->append(field->charset()->name);
|
2003-05-23 13:10:25 +05:00
|
|
|
}
|
2003-01-09 15:37:59 +04:00
|
|
|
}
|
2003-05-23 13:10:25 +05:00
|
|
|
|
2000-10-24 02:39:54 +03:00
|
|
|
if (flags & NOT_NULL_FLAG)
|
|
|
|
packet->append(" NOT NULL", 9);
|
2004-10-01 18:54:06 +04:00
|
|
|
else if (field->type() == FIELD_TYPE_TIMESTAMP)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
TIMESTAMP field require explicit NULL flag, because unlike
|
|
|
|
all other fields they are treated as NOT NULL by default.
|
|
|
|
*/
|
|
|
|
packet->append(" NULL", 5);
|
|
|
|
}
|
2004-04-02 10:12:53 +04:00
|
|
|
|
|
|
|
/*
|
2004-04-06 12:13:43 +03:00
|
|
|
Again we are using CURRENT_TIMESTAMP instead of NOW because it is
|
2004-04-02 10:12:53 +04:00
|
|
|
more standard
|
|
|
|
*/
|
|
|
|
has_now_default= table->timestamp_field == field &&
|
|
|
|
field->unireg_check != Field::TIMESTAMP_UN_FIELD;
|
|
|
|
|
2003-08-23 12:25:39 +03:00
|
|
|
has_default= (field->type() != FIELD_TYPE_BLOB &&
|
2004-04-02 10:12:53 +04:00
|
|
|
field->unireg_check != Field::NEXT_NUMBER &&
|
2006-04-30 16:01:34 +03:00
|
|
|
!((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40))
|
|
|
|
&& has_now_default));
|
2003-05-23 13:10:25 +05:00
|
|
|
|
2000-10-24 02:39:54 +03:00
|
|
|
if (has_default)
|
2000-09-01 15:24:36 +04:00
|
|
|
{
|
|
|
|
packet->append(" default ", 9);
|
2004-04-02 10:12:53 +04:00
|
|
|
if (has_now_default)
|
|
|
|
packet->append("CURRENT_TIMESTAMP",17);
|
|
|
|
else if (!field->is_null())
|
2000-09-01 15:24:36 +04:00
|
|
|
{ // Not null by default
|
2003-12-15 21:01:38 +04:00
|
|
|
type.set(tmp, sizeof(tmp), field->charset());
|
2004-04-06 21:35:26 +02:00
|
|
|
field->val_str(&type);
|
2001-02-17 14:19:19 +02:00
|
|
|
if (type.length())
|
2003-12-16 17:39:33 +04:00
|
|
|
{
|
2004-04-06 21:35:26 +02:00
|
|
|
String def_val;
|
2004-10-29 17:00:39 +05:00
|
|
|
uint dummy_errors;
|
2003-12-16 17:39:33 +04:00
|
|
|
/* convert to system_charset_info == utf8 */
|
|
|
|
def_val.copy(type.ptr(), type.length(), field->charset(),
|
2004-10-29 17:00:39 +05:00
|
|
|
system_charset_info, &dummy_errors);
|
2003-12-16 17:39:33 +04:00
|
|
|
append_unescaped(packet, def_val.ptr(), def_val.length());
|
|
|
|
}
|
2002-06-02 21:22:20 +03:00
|
|
|
else
|
|
|
|
packet->append("''",2);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2000-10-24 02:39:54 +03:00
|
|
|
else if (field->maybe_null())
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append("NULL", 4); // Null as default
|
|
|
|
else
|
2004-05-25 15:54:03 +05:00
|
|
|
packet->append(tmp);
|
2000-09-01 15:24:36 +04:00
|
|
|
}
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2006-04-30 16:01:34 +03:00
|
|
|
if (!limited_mysql_mode && table->timestamp_field == field &&
|
2004-04-02 10:12:53 +04:00
|
|
|
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
|
|
|
|
packet->append(" on update CURRENT_TIMESTAMP",28);
|
|
|
|
|
2005-09-29 16:17:45 +05:00
|
|
|
if (field->unireg_check == Field::NEXT_NUMBER &&
|
|
|
|
!(thd->variables.sql_mode & MODE_NO_FIELD_OPTIONS))
|
2002-06-02 21:22:20 +03:00
|
|
|
packet->append(" auto_increment", 15 );
|
|
|
|
|
|
|
|
if (field->comment.length)
|
|
|
|
{
|
|
|
|
packet->append(" COMMENT ",9);
|
|
|
|
append_unescaped(packet, field->comment.str, field->comment.length);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-08-23 12:25:39 +03:00
|
|
|
key_info= table->key_info;
|
|
|
|
file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
|
2003-08-25 17:19:44 +03:00
|
|
|
bzero((char*) &create_info, sizeof(create_info));
|
2003-08-23 12:25:39 +03:00
|
|
|
file->update_create_info(&create_info);
|
|
|
|
primary_key= table->primary_key;
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
for (uint i=0 ; i < table->keys ; i++,key_info++)
|
|
|
|
{
|
2001-06-21 10:50:14 +03:00
|
|
|
KEY_PART_INFO *key_part= key_info->key_part;
|
|
|
|
bool found_primary=0;
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append(",\n ", 4);
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2004-01-14 16:01:55 +04:00
|
|
|
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
|
2001-06-21 10:50:14 +03:00
|
|
|
{
|
|
|
|
found_primary=1;
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append("PRIMARY ", 8);
|
2001-06-21 10:50:14 +03:00
|
|
|
}
|
2001-02-17 14:19:19 +02:00
|
|
|
else if (key_info->flags & HA_NOSAME)
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append("UNIQUE ", 7);
|
2001-02-17 14:19:19 +02:00
|
|
|
else if (key_info->flags & HA_FULLTEXT)
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append("FULLTEXT ", 9);
|
2002-02-22 15:24:42 +04:00
|
|
|
else if (key_info->flags & HA_SPATIAL)
|
|
|
|
packet->append("SPATIAL ", 8);
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append("KEY ", 4);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2001-06-21 10:50:14 +03:00
|
|
|
if (!found_primary)
|
2003-06-27 16:29:10 +03:00
|
|
|
append_identifier(thd, packet, key_info->name, strlen(key_info->name));
|
2002-02-22 15:24:42 +04:00
|
|
|
|
2003-01-16 02:04:50 +02:00
|
|
|
if (!(thd->variables.sql_mode & MODE_NO_KEY_OPTIONS) &&
|
|
|
|
!limited_mysql_mode && !foreign_db_mode)
|
|
|
|
{
|
2005-01-08 06:15:41 +01:00
|
|
|
if (key_info->algorithm == HA_KEY_ALG_BTREE)
|
2005-07-07 14:44:28 +02:00
|
|
|
packet->append(" USING BTREE", 12);
|
2003-01-16 02:04:50 +02:00
|
|
|
|
2005-01-08 06:15:41 +01:00
|
|
|
if (key_info->algorithm == HA_KEY_ALG_HASH)
|
2005-07-07 14:44:28 +02:00
|
|
|
packet->append(" USING HASH", 11);
|
2005-01-08 06:15:41 +01:00
|
|
|
|
2003-01-16 02:04:50 +02:00
|
|
|
// +BAR: send USING only in non-default case: non-spatial rtree
|
|
|
|
if ((key_info->algorithm == HA_KEY_ALG_RTREE) &&
|
|
|
|
!(key_info->flags & HA_SPATIAL))
|
2005-07-07 14:44:28 +02:00
|
|
|
packet->append(" USING RTREE", 12);
|
2005-01-08 06:15:41 +01:00
|
|
|
|
|
|
|
// No need to send TYPE FULLTEXT, it is sent as FULLTEXT KEY
|
2003-01-16 02:04:50 +02:00
|
|
|
}
|
2001-02-13 08:43:14 +02:00
|
|
|
packet->append(" (", 2);
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
|
|
|
|
{
|
2000-09-29 00:58:16 +03:00
|
|
|
if (j)
|
2000-09-01 15:24:36 +04:00
|
|
|
packet->append(',');
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2000-09-29 00:58:16 +03:00
|
|
|
if (key_part->field)
|
2003-06-27 16:29:10 +03:00
|
|
|
append_identifier(thd,packet,key_part->field->field_name,
|
|
|
|
strlen(key_part->field->field_name));
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!key_part->field ||
|
2000-09-01 15:24:36 +04:00
|
|
|
(key_part->length !=
|
|
|
|
table->field[key_part->fieldnr-1]->key_length() &&
|
|
|
|
!(key_info->flags & HA_FULLTEXT)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2000-09-01 15:24:36 +04:00
|
|
|
buff[0] = '(';
|
2003-09-15 14:45:42 +05:00
|
|
|
char* end=int10_to_str((long) key_part->length /
|
|
|
|
key_part->field->charset()->mbmaxlen,
|
|
|
|
buff + 1,10);
|
2000-09-01 15:24:36 +04:00
|
|
|
*end++ = ')';
|
|
|
|
packet->append(buff,(uint) (end-buff));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
packet->append(')');
|
|
|
|
}
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2003-06-27 16:29:10 +03:00
|
|
|
/*
|
|
|
|
Get possible foreign key definitions stored in InnoDB and append them
|
|
|
|
to the CREATE TABLE statement
|
|
|
|
*/
|
2002-03-21 18:05:46 +02:00
|
|
|
|
2003-08-23 12:25:39 +03:00
|
|
|
if ((for_str= file->get_foreign_key_create_info()))
|
2003-06-27 16:29:10 +03:00
|
|
|
{
|
|
|
|
packet->append(for_str, strlen(for_str));
|
|
|
|
file->free_foreign_key_create_info(for_str);
|
2002-03-21 18:05:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
packet->append("\n)", 2);
|
2003-01-16 02:04:50 +02:00
|
|
|
if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode)
|
2002-06-19 21:21:30 +05:00
|
|
|
{
|
2004-02-05 02:30:28 +00:00
|
|
|
if (thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40))
|
|
|
|
packet->append(" TYPE=", 6);
|
|
|
|
else
|
|
|
|
packet->append(" ENGINE=", 8);
|
2003-01-16 02:04:50 +02:00
|
|
|
packet->append(file->table_type());
|
|
|
|
|
Bug#19025 4.1 mysqldump doesn't correctly dump "auto_increment = [int]"
mysqldump / SHOW CREATE TABLE will show the NEXT available value for
the PK, rather than the *first* one that was available (that named in
the original CREATE TABLE ... AUTO_INCREMENT = ... statement).
This should produce correct and robust behaviour for the obvious use
cases -- when no data were inserted, then we'll produce a statement
featuring the same value the original CREATE TABLE had; if we dump
with values, INSERTing the values on the target machine should set the
correct next_ID anyway (and if not, we'll still have our AUTO_INCREMENT =
... to do that). Lastly, just the CREATE statement (with no data) for
a table that saw inserts would still result in a table that new values
could safely be inserted to).
There seems to be no robust way however to see whether the next_ID
field is > 1 because it was set to something else with CREATE TABLE
... AUTO_INCREMENT = ..., or because there is an AUTO_INCREMENT column
in the table (but no initial value was set with AUTO_INCREMENT = ...)
and then one or more rows were INSERTed, counting up next_ID. This
means that in both cases, we'll generate an AUTO_INCREMENT =
... clause in SHOW CREATE TABLE / mysqldump. As we also show info on,
say, charsets even if the user did not explicitly give that info in
their own CREATE TABLE, this shouldn't be an issue.
As per above, the next_ID will be affected by any INSERTs that have
taken place, though. This /should/ result in correct and robust
behaviour, but it may look non-intuitive to some users if they CREATE
TABLE ... AUTO_INCREMENT = 1000 and later (after some INSERTs) have
SHOW CREATE TABLE give them a different value (say, CREATE TABLE
... AUTO_INCREMENT = 1006), so the docs should possibly feature a
caveat to that effect.
It's not very intuitive the way it works now (with the fix), but it's
*correct*. We're not storing the original value anyway, if we wanted
that, we'd have to change on-disk representation?
If we do dump/load cycles with empty DBs, nothing will change. This
changeset includes an additional test case that proves that tables
with rows will create the same next_ID for AUTO_INCREMENT = ... across
dump/restore cycles.
Confirmed by support as likely solution for client's problem.
2006-05-04 03:12:51 +02:00
|
|
|
/*
|
|
|
|
Add AUTO_INCREMENT=... if there is an AUTO_INCREMENT column,
|
|
|
|
and NEXT_ID > 1 (the default). We must not print the clause
|
|
|
|
for engines that do not support this as it would break the
|
|
|
|
import of dumps, but as of this writing, the test for whether
|
|
|
|
AUTO_INCREMENT columns are allowed and wether AUTO_INCREMENT=...
|
|
|
|
is supported is identical, !(file->table_flags() & HA_NO_AUTO_INCREMENT))
|
|
|
|
Because of that, we do not explicitly test for the feature,
|
|
|
|
but may extrapolate its existence from that of an AUTO_INCREMENT column.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(create_info.auto_increment_value > 1)
|
|
|
|
{
|
|
|
|
packet->append(" AUTO_INCREMENT=", 16);
|
|
|
|
end= longlong10_to_str(create_info.auto_increment_value, buff,10);
|
|
|
|
packet->append(buff, (uint) (end - buff));
|
|
|
|
}
|
|
|
|
|
2003-01-16 05:35:59 +02:00
|
|
|
if (table->table_charset &&
|
|
|
|
!(thd->variables.sql_mode & MODE_MYSQL323) &&
|
|
|
|
!(thd->variables.sql_mode & MODE_MYSQL40))
|
2003-01-09 15:37:59 +04:00
|
|
|
{
|
2003-11-18 13:47:27 +02:00
|
|
|
packet->append(" DEFAULT CHARSET=", 17);
|
2003-01-16 02:04:50 +02:00
|
|
|
packet->append(table->table_charset->csname);
|
|
|
|
if (!(table->table_charset->state & MY_CS_PRIMARY))
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
packet->append(" COLLATE=", 9);
|
2003-01-16 02:04:50 +02:00
|
|
|
packet->append(table->table_charset->name);
|
|
|
|
}
|
2003-01-09 15:37:59 +04:00
|
|
|
}
|
2002-06-19 21:21:30 +05:00
|
|
|
|
2003-01-16 02:04:50 +02:00
|
|
|
if (table->min_rows)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
packet->append(" MIN_ROWS=", 10);
|
2003-08-29 13:44:35 +03:00
|
|
|
end= longlong10_to_str(table->min_rows, buff, 10);
|
|
|
|
packet->append(buff, (uint) (end- buff));
|
2003-01-16 02:04:50 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-01-16 02:04:50 +02:00
|
|
|
if (table->max_rows)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
packet->append(" MAX_ROWS=", 10);
|
2003-08-29 13:44:35 +03:00
|
|
|
end= longlong10_to_str(table->max_rows, buff, 10);
|
|
|
|
packet->append(buff, (uint) (end - buff));
|
2003-01-16 02:04:50 +02:00
|
|
|
}
|
2003-08-29 13:44:35 +03:00
|
|
|
|
2003-01-16 02:04:50 +02:00
|
|
|
if (table->avg_row_length)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
packet->append(" AVG_ROW_LENGTH=", 16);
|
2003-08-29 13:44:35 +03:00
|
|
|
end= longlong10_to_str(table->avg_row_length, buff,10);
|
|
|
|
packet->append(buff, (uint) (end - buff));
|
2003-01-16 02:04:50 +02:00
|
|
|
}
|
2000-08-29 19:44:22 +04:00
|
|
|
|
2003-01-16 02:04:50 +02:00
|
|
|
if (table->db_create_options & HA_OPTION_PACK_KEYS)
|
|
|
|
packet->append(" PACK_KEYS=1", 12);
|
|
|
|
if (table->db_create_options & HA_OPTION_NO_PACK_KEYS)
|
|
|
|
packet->append(" PACK_KEYS=0", 12);
|
|
|
|
if (table->db_create_options & HA_OPTION_CHECKSUM)
|
|
|
|
packet->append(" CHECKSUM=1", 11);
|
|
|
|
if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
|
|
|
|
packet->append(" DELAY_KEY_WRITE=1",18);
|
|
|
|
if (table->row_type != ROW_TYPE_DEFAULT)
|
|
|
|
{
|
|
|
|
packet->append(" ROW_FORMAT=",12);
|
|
|
|
packet->append(ha_row_type[(uint) table->row_type]);
|
|
|
|
}
|
|
|
|
table->file->append_create_info(packet);
|
|
|
|
if (table->comment && table->comment[0])
|
|
|
|
{
|
|
|
|
packet->append(" COMMENT=", 9);
|
|
|
|
append_unescaped(packet, table->comment, strlen(table->comment));
|
|
|
|
}
|
|
|
|
if (file->raid_type)
|
|
|
|
{
|
2003-08-29 13:44:35 +03:00
|
|
|
uint length;
|
|
|
|
length= my_snprintf(buff,sizeof(buff),
|
|
|
|
" RAID_TYPE=%s RAID_CHUNKS=%d RAID_CHUNKSIZE=%ld",
|
|
|
|
my_raid_type(file->raid_type), file->raid_chunks,
|
|
|
|
file->raid_chunksize/RAID_BLOCK_SIZE);
|
|
|
|
packet->append(buff, length);
|
2003-01-16 02:04:50 +02:00
|
|
|
}
|
2003-08-29 13:44:35 +03:00
|
|
|
append_directory(thd, packet, "DATA", create_info.data_file_name);
|
|
|
|
append_directory(thd, packet, "INDEX", create_info.index_file_name);
|
2000-12-22 12:25:49 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2002-10-02 13:33:08 +03:00
|
|
|
Return info about all processes
|
|
|
|
returns for each thread: thread id, user, host, db, command, info
|
2000-07-31 21:29:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
class thread_info :public ilink {
|
|
|
|
public:
|
2000-08-23 15:02:27 +03:00
|
|
|
static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
|
2000-07-31 21:29:14 +02:00
|
|
|
static void operator delete(void *ptr __attribute__((unused)),
|
2000-09-01 15:24:36 +04:00
|
|
|
size_t size __attribute__((unused))) {} /*lint -e715 */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2000-08-23 15:02:27 +03:00
|
|
|
ulong thread_id;
|
|
|
|
time_t start_time;
|
2000-09-01 15:24:36 +04:00
|
|
|
uint command;
|
2000-07-31 21:29:14 +02:00
|
|
|
const char *user,*host,*db,*proc_info,*state_info;
|
|
|
|
char *query;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
template class I_List<thread_info>;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
|
|
|
|
{
|
|
|
|
Item *field;
|
|
|
|
List<Item> field_list;
|
|
|
|
I_List<thread_info> thread_infos;
|
2002-07-23 18:31:22 +03:00
|
|
|
ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
|
|
|
|
PROCESS_LIST_WIDTH);
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_list_processes");
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(new Item_int("Id",0,11));
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(new Item_empty_string("User",16));
|
2003-02-17 22:07:26 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN));
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(field=new Item_empty_string("db",NAME_LEN));
|
|
|
|
field->maybe_null=1;
|
|
|
|
field_list.push_back(new Item_empty_string("Command",16));
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(new Item_return_int("Time",7, FIELD_TYPE_LONG));
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(field=new Item_empty_string("State",30));
|
|
|
|
field->maybe_null=1;
|
|
|
|
field_list.push_back(field=new Item_empty_string("Info",max_query_length));
|
|
|
|
field->maybe_null=1;
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
|
|
|
|
if (!thd->killed)
|
|
|
|
{
|
|
|
|
I_List_iterator<THD> it(threads);
|
|
|
|
THD *tmp;
|
|
|
|
while ((tmp=it++))
|
|
|
|
{
|
2002-12-11 12:44:17 +02:00
|
|
|
struct st_my_thread_var *mysys_var;
|
2004-05-28 15:59:29 +05:00
|
|
|
if ((tmp->vio_ok() || tmp->system_thread) &&
|
2000-09-01 15:24:36 +04:00
|
|
|
(!user || (tmp->user && !strcmp(tmp->user,user))))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2000-09-01 15:24:36 +04:00
|
|
|
thread_info *thd_info=new thread_info;
|
|
|
|
|
|
|
|
thd_info->thread_id=tmp->thread_id;
|
2001-08-14 20:33:49 +03:00
|
|
|
thd_info->user=thd->strdup(tmp->user ? tmp->user :
|
|
|
|
(tmp->system_thread ?
|
|
|
|
"system user" : "unauthenticated user"));
|
2003-03-26 22:04:20 +02:00
|
|
|
if (tmp->peer_port && (tmp->host || tmp->ip) && thd->host_or_ip[0])
|
2003-02-17 22:07:26 +02:00
|
|
|
{
|
|
|
|
if ((thd_info->host= thd->alloc(LIST_PROCESS_HOST_LEN+1)))
|
2003-02-28 21:17:44 +02:00
|
|
|
my_snprintf((char *) thd_info->host, LIST_PROCESS_HOST_LEN,
|
2003-03-19 21:43:41 +02:00
|
|
|
"%s:%u", tmp->host_or_ip, tmp->peer_port);
|
2003-02-17 22:07:26 +02:00
|
|
|
}
|
|
|
|
else
|
2003-03-19 21:43:41 +02:00
|
|
|
thd_info->host= thd->strdup(tmp->host_or_ip);
|
2000-09-01 15:24:36 +04:00
|
|
|
if ((thd_info->db=tmp->db)) // Safe test
|
|
|
|
thd_info->db=thd->strdup(thd_info->db);
|
|
|
|
thd_info->command=(int) tmp->command;
|
2002-12-11 12:44:17 +02:00
|
|
|
if ((mysys_var= tmp->mysys_var))
|
|
|
|
pthread_mutex_lock(&mysys_var->mutex);
|
2000-09-01 15:24:36 +04:00
|
|
|
thd_info->proc_info= (char*) (tmp->killed ? "Killed" : 0);
|
2003-01-15 12:11:44 +04:00
|
|
|
#ifndef EMBEDDED_LIBRARY
|
2000-09-01 15:24:36 +04:00
|
|
|
thd_info->state_info= (char*) (tmp->locked ? "Locked" :
|
|
|
|
tmp->net.reading_or_writing ?
|
|
|
|
(tmp->net.reading_or_writing == 2 ?
|
|
|
|
"Writing to net" :
|
|
|
|
thd_info->command == COM_SLEEP ? "" :
|
|
|
|
"Reading from net") :
|
|
|
|
tmp->proc_info ? tmp->proc_info :
|
|
|
|
tmp->mysys_var &&
|
|
|
|
tmp->mysys_var->current_cond ?
|
|
|
|
"Waiting on cond" : NullS);
|
2003-01-15 12:11:44 +04:00
|
|
|
#else
|
|
|
|
thd_info->state_info= (char*)"Writing to net";
|
|
|
|
#endif
|
2002-12-11 12:44:17 +02:00
|
|
|
if (mysys_var)
|
|
|
|
pthread_mutex_unlock(&mysys_var->mutex);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
#if !defined(DONT_USE_THR_ALARM) && ! defined(SCO)
|
2000-09-01 15:24:36 +04:00
|
|
|
if (pthread_kill(tmp->real_id,0))
|
|
|
|
tmp->proc_info="*** DEAD ***"; // This shouldn't happen
|
2000-07-31 21:29:14 +02:00
|
|
|
#endif
|
2001-04-01 13:45:48 +03:00
|
|
|
#ifdef EXTRA_DEBUG
|
|
|
|
thd_info->start_time= tmp->time_after_lock;
|
|
|
|
#else
|
2000-09-01 15:24:36 +04:00
|
|
|
thd_info->start_time= tmp->start_time;
|
2001-04-01 13:45:48 +03:00
|
|
|
#endif
|
2000-09-01 15:24:36 +04:00
|
|
|
thd_info->query=0;
|
|
|
|
if (tmp->query)
|
|
|
|
{
|
2004-05-14 16:48:56 +03:00
|
|
|
/*
|
|
|
|
query_length is always set to 0 when we set query = NULL; see
|
|
|
|
the comment in sql_class.h why this prevents crashes in possible
|
|
|
|
races with query_length
|
|
|
|
*/
|
2001-12-05 13:03:00 +02:00
|
|
|
uint length= min(max_query_length, tmp->query_length);
|
2004-05-15 09:08:03 +03:00
|
|
|
thd_info->query=(char*) thd->strmake(tmp->query,length);
|
2000-09-01 15:24:36 +04:00
|
|
|
}
|
|
|
|
thread_infos.append(thd_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VOID(pthread_mutex_unlock(&LOCK_thread_count));
|
|
|
|
|
|
|
|
thread_info *thd_info;
|
2002-12-11 09:17:51 +02:00
|
|
|
time_t now= time(0);
|
2000-07-31 21:29:14 +02:00
|
|
|
while ((thd_info=thread_infos.get()))
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
|
|
|
protocol->store((ulonglong) thd_info->thread_id);
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(thd_info->user, system_charset_info);
|
|
|
|
protocol->store(thd_info->host, system_charset_info);
|
|
|
|
protocol->store(thd_info->db, system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (thd_info->proc_info)
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(thd_info->proc_info, system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(command_name[thd_info->command], system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (thd_info->start_time)
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store((uint32) (now - thd_info->start_time));
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->store_null();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(thd_info->state_info, system_charset_info);
|
|
|
|
protocol->store(thd_info->query, system_charset_info);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->write())
|
2000-07-31 21:29:14 +02:00
|
|
|
break; /* purecov: inspected */
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2002-08-30 12:40:40 +03:00
|
|
|
Status functions
|
2000-07-31 21:29:14 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2003-03-25 13:38:05 +04:00
|
|
|
static bool write_collation(Protocol *protocol, CHARSET_INFO *cs)
|
|
|
|
{
|
|
|
|
protocol->prepare_for_resend();
|
|
|
|
protocol->store(cs->name, system_charset_info);
|
2003-05-22 17:20:19 +05:00
|
|
|
protocol->store(cs->csname, system_charset_info);
|
2003-03-25 13:38:05 +04:00
|
|
|
protocol->store_short((longlong) cs->number);
|
2003-06-02 17:19:06 +05:00
|
|
|
protocol->store((cs->state & MY_CS_PRIMARY) ? "Yes" : "",system_charset_info);
|
|
|
|
protocol->store((cs->state & MY_CS_COMPILED)? "Yes" : "",system_charset_info);
|
2003-03-25 13:38:05 +04:00
|
|
|
protocol->store_short((longlong) cs->strxfrm_multiply);
|
|
|
|
return protocol->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
int mysqld_show_collations(THD *thd, const char *wild)
|
2002-06-11 17:40:06 +05:00
|
|
|
{
|
|
|
|
char buff[8192];
|
2003-02-26 14:54:57 +04:00
|
|
|
String packet2(buff,sizeof(buff),thd->charset());
|
2002-06-11 17:40:06 +05:00
|
|
|
List<Item> field_list;
|
2002-10-10 15:52:32 +05:00
|
|
|
CHARSET_INFO **cs;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2003-01-04 14:12:20 +04:00
|
|
|
|
2002-06-11 17:40:06 +05:00
|
|
|
DBUG_ENTER("mysqld_show_charsets");
|
|
|
|
|
2003-03-25 13:38:05 +04:00
|
|
|
field_list.push_back(new Item_empty_string("Collation",30));
|
2003-05-22 17:20:19 +05:00
|
|
|
field_list.push_back(new Item_empty_string("Charset",30));
|
2002-12-11 09:17:51 +02:00
|
|
|
field_list.push_back(new Item_return_int("Id",11, FIELD_TYPE_SHORT));
|
2003-06-02 17:19:06 +05:00
|
|
|
field_list.push_back(new Item_empty_string("Default",30));
|
|
|
|
field_list.push_back(new Item_empty_string("Compiled",30));
|
2003-03-26 13:27:19 +04:00
|
|
|
field_list.push_back(new Item_return_int("Sortlen",3, FIELD_TYPE_SHORT));
|
2002-06-11 17:40:06 +05:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list, 1))
|
2002-06-11 17:40:06 +05:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2003-03-25 13:38:05 +04:00
|
|
|
for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ )
|
2002-06-11 17:40:06 +05:00
|
|
|
{
|
2003-03-25 13:38:05 +04:00
|
|
|
CHARSET_INFO **cl;
|
2003-09-22 11:11:36 +05:00
|
|
|
if (!cs[0] || !(cs[0]->state & MY_CS_AVAILABLE) ||
|
|
|
|
!(cs[0]->state & MY_CS_PRIMARY))
|
|
|
|
continue;
|
2003-03-25 13:38:05 +04:00
|
|
|
for ( cl= all_charsets; cl < all_charsets+255 ;cl ++)
|
|
|
|
{
|
2003-09-22 11:11:36 +05:00
|
|
|
if (!cl[0] || !(cl[0]->state & MY_CS_AVAILABLE) ||
|
|
|
|
!my_charset_same(cs[0],cl[0]))
|
2003-03-25 13:38:05 +04:00
|
|
|
continue;
|
2003-09-22 11:11:36 +05:00
|
|
|
if (!(wild && wild[0] &&
|
2003-03-25 13:42:01 +04:00
|
|
|
wild_case_compare(system_charset_info,cl[0]->name,wild)))
|
2003-03-25 13:38:05 +04:00
|
|
|
{
|
|
|
|
if (write_collation(protocol, cl[0]))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send_eof(thd);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
err:
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool write_charset(Protocol *protocol, CHARSET_INFO *cs)
|
|
|
|
{
|
|
|
|
protocol->prepare_for_resend();
|
|
|
|
protocol->store(cs->csname, system_charset_info);
|
2003-03-25 16:12:49 +04:00
|
|
|
protocol->store(cs->comment ? cs->comment : "", system_charset_info);
|
2003-03-25 13:38:05 +04:00
|
|
|
protocol->store(cs->name, system_charset_info);
|
|
|
|
protocol->store_short((longlong) cs->mbmaxlen);
|
|
|
|
return protocol->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
int mysqld_show_charsets(THD *thd, const char *wild)
|
|
|
|
{
|
|
|
|
char buff[8192];
|
|
|
|
String packet2(buff,sizeof(buff),thd->charset());
|
|
|
|
List<Item> field_list;
|
|
|
|
CHARSET_INFO **cs;
|
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
|
|
|
|
DBUG_ENTER("mysqld_show_charsets");
|
|
|
|
|
|
|
|
field_list.push_back(new Item_empty_string("Charset",30));
|
2003-03-25 16:12:49 +04:00
|
|
|
field_list.push_back(new Item_empty_string("Description",60));
|
2003-03-25 13:38:05 +04:00
|
|
|
field_list.push_back(new Item_empty_string("Default collation",60));
|
|
|
|
field_list.push_back(new Item_return_int("Maxlen",3, FIELD_TYPE_SHORT));
|
|
|
|
|
|
|
|
if (protocol->send_fields(&field_list, 1))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ )
|
|
|
|
{
|
2003-09-22 11:11:36 +05:00
|
|
|
if (cs[0] && (cs[0]->state & MY_CS_PRIMARY) &&
|
|
|
|
(cs[0]->state & MY_CS_AVAILABLE) &&
|
|
|
|
!(wild && wild[0] &&
|
|
|
|
wild_case_compare(system_charset_info,cs[0]->csname,wild)))
|
2002-06-11 17:40:06 +05:00
|
|
|
{
|
2003-03-25 13:38:05 +04:00
|
|
|
if (write_charset(protocol, cs[0]))
|
2002-12-11 09:17:51 +02:00
|
|
|
goto err;
|
2002-06-11 17:40:06 +05:00
|
|
|
}
|
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2002-06-11 17:40:06 +05:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
err:
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
2002-08-30 12:40:40 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-06-28 19:30:09 +03:00
|
|
|
int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
|
2003-08-17 14:10:15 +03:00
|
|
|
enum enum_var_type value_type,
|
|
|
|
pthread_mutex_t *mutex)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
char buff[1024];
|
2000-07-31 21:29:14 +02:00
|
|
|
List<Item> field_list;
|
2002-12-11 09:17:51 +02:00
|
|
|
Protocol *protocol= thd->protocol;
|
2003-07-06 19:09:57 +03:00
|
|
|
LEX_STRING null_lex_str;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("mysqld_show");
|
2002-08-30 12:40:40 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
field_list.push_back(new Item_empty_string("Variable_name",30));
|
|
|
|
field_list.push_back(new Item_empty_string("Value",256));
|
2002-12-11 09:17:51 +02:00
|
|
|
if (protocol->send_fields(&field_list,1))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1); /* purecov: inspected */
|
2003-07-06 19:09:57 +03:00
|
|
|
null_lex_str.str= 0; // For sys_var->value_ptr()
|
2003-11-18 13:47:27 +02:00
|
|
|
null_lex_str.length= 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-08-17 14:10:15 +03:00
|
|
|
pthread_mutex_lock(mutex);
|
2002-07-23 18:31:22 +03:00
|
|
|
for (; variables->name; variables++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-06-04 08:23:57 +03:00
|
|
|
if (!(wild && wild[0] && wild_case_compare(system_charset_info,
|
2002-10-02 13:33:08 +03:00
|
|
|
variables->name,wild)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->prepare_for_resend();
|
2003-03-17 13:14:04 +04:00
|
|
|
protocol->store(variables->name, system_charset_info);
|
2002-07-23 18:31:22 +03:00
|
|
|
SHOW_TYPE show_type=variables->type;
|
|
|
|
char *value=variables->value;
|
2002-12-11 09:17:51 +02:00
|
|
|
const char *pos, *end;
|
|
|
|
long nr;
|
|
|
|
|
2002-07-23 18:31:22 +03:00
|
|
|
if (show_type == SHOW_SYS)
|
|
|
|
{
|
|
|
|
show_type= ((sys_var*) value)->type();
|
2003-07-06 19:09:57 +03:00
|
|
|
value= (char*) ((sys_var*) value)->value_ptr(thd, value_type,
|
|
|
|
&null_lex_str);
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= end= buff;
|
2002-07-23 18:31:22 +03:00
|
|
|
switch (show_type) {
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_LONG:
|
|
|
|
case SHOW_LONG_CONST:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str(*(long*) value, buff, 10);
|
2002-07-23 18:31:22 +03:00
|
|
|
break;
|
|
|
|
case SHOW_LONGLONG:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= longlong10_to_str(*(longlong*) value, buff, 10);
|
2003-01-03 00:04:33 +02:00
|
|
|
break;
|
2002-12-20 14:58:27 +02:00
|
|
|
case SHOW_HA_ROWS:
|
2003-01-03 00:04:33 +02:00
|
|
|
end= longlong10_to_str((longlong) *(ha_rows*) value, buff, 10);
|
2000-09-01 15:24:36 +04:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_BOOL:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= strmov(buff, *(bool*) value ? "ON" : "OFF");
|
2000-09-01 15:24:36 +04:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_MY_BOOL:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= strmov(buff, *(my_bool*) value ? "ON" : "OFF");
|
2002-06-28 19:30:09 +03:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_INT_CONST:
|
|
|
|
case SHOW_INT:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) *(uint32*) value, buff, 10);
|
2002-06-28 19:30:09 +03:00
|
|
|
break;
|
2000-12-26 17:34:04 +02:00
|
|
|
case SHOW_HAVE:
|
|
|
|
{
|
2002-07-23 18:31:22 +03:00
|
|
|
SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= show_comp_option_name[(int) tmp];
|
|
|
|
end= strend(pos);
|
2000-12-26 17:34:04 +02:00
|
|
|
break;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_CHAR:
|
2003-07-18 14:11:01 +05:00
|
|
|
{
|
|
|
|
if (!(pos= value))
|
|
|
|
pos= "";
|
|
|
|
end= strend(pos);
|
2000-09-01 15:24:36 +04:00
|
|
|
break;
|
2003-07-18 14:11:01 +05:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_STARTTIME:
|
2002-12-11 09:17:51 +02:00
|
|
|
nr= (long) (thd->query_start() - start_time);
|
|
|
|
end= int10_to_str(nr, buff, 10);
|
2000-09-01 15:24:36 +04:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_QUESTION:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) thd->query_id, buff, 10);
|
2000-09-01 15:24:36 +04:00
|
|
|
break;
|
2003-05-21 21:39:58 +03:00
|
|
|
#ifdef HAVE_REPLICATION
|
2001-10-09 20:56:24 -06:00
|
|
|
case SHOW_RPL_STATUS:
|
2002-12-24 13:58:07 +02:00
|
|
|
end= strmov(buff, rpl_status_type[(int)rpl_status]);
|
2001-10-09 20:56:24 -06:00
|
|
|
break;
|
2002-01-19 19:16:52 -07:00
|
|
|
case SHOW_SLAVE_RUNNING:
|
|
|
|
{
|
2004-03-11 16:23:35 +01:00
|
|
|
pthread_mutex_lock(&LOCK_active_mi);
|
2005-11-01 11:48:55 -08:00
|
|
|
end= strmov(buff, (active_mi && active_mi->slave_running &&
|
2002-12-11 09:17:51 +02:00
|
|
|
active_mi->rli.slave_running) ? "ON" : "OFF");
|
2004-03-11 16:23:35 +01:00
|
|
|
pthread_mutex_unlock(&LOCK_active_mi);
|
2002-01-19 19:16:52 -07:00
|
|
|
break;
|
|
|
|
}
|
2005-03-23 19:19:36 +01:00
|
|
|
case SHOW_SLAVE_RETRIED_TRANS:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
TODO: in 5.1 with multimaster, have one such counter per line in SHOW
|
|
|
|
SLAVE STATUS, and have the sum over all lines here.
|
|
|
|
*/
|
|
|
|
pthread_mutex_lock(&LOCK_active_mi);
|
2005-11-01 11:48:55 -08:00
|
|
|
if (active_mi)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&active_mi->rli.data_lock);
|
|
|
|
end= int10_to_str(active_mi->rli.retried_trans, buff, 10);
|
|
|
|
pthread_mutex_unlock(&active_mi->rli.data_lock);
|
|
|
|
}
|
2005-03-23 19:19:36 +01:00
|
|
|
pthread_mutex_unlock(&LOCK_active_mi);
|
|
|
|
break;
|
|
|
|
}
|
2003-05-19 16:35:49 +03:00
|
|
|
#endif /* HAVE_REPLICATION */
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_OPENTABLES:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) cached_tables(), buff, 10);
|
2000-09-01 15:24:36 +04:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case SHOW_CHAR_PTR:
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2003-12-08 09:13:14 +04:00
|
|
|
if (!(pos= *(char**) value))
|
|
|
|
pos= "";
|
|
|
|
end= strend(pos);
|
|
|
|
break;
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
2001-08-27 03:34:52 +08:00
|
|
|
#ifdef HAVE_OPENSSL
|
2001-09-01 05:18:01 +08:00
|
|
|
/* First group - functions relying on CTX */
|
2001-08-27 03:34:52 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_ACCEPT:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
|
|
|
SSL_CTX_sess_accept(ssl_acceptor_fd->
|
2003-08-29 13:44:35 +03:00
|
|
|
ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_CTX_SESS_ACCEPT_GOOD:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
|
|
|
SSL_CTX_sess_accept_good(ssl_acceptor_fd->
|
2003-08-29 13:44:35 +03:00
|
|
|
ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
2001-09-30 10:46:20 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_CONNECT_GOOD:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
|
|
|
SSL_CTX_sess_connect_good(ssl_acceptor_fd->
|
2003-08-29 13:44:35 +03:00
|
|
|
ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-09-30 10:46:20 +08:00
|
|
|
break;
|
2001-08-27 03:34:52 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_ACCEPT_RENEGOTIATE:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_sess_accept_renegotiate(ssl_acceptor_fd->ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
2001-09-30 10:46:20 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_CONNECT_RENEGOTIATE:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_sess_connect_renegotiate(ssl_acceptor_fd-> ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-09-30 10:46:20 +08:00
|
|
|
break;
|
2001-08-27 03:34:52 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_CB_HITS:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
|
|
|
SSL_CTX_sess_cb_hits(ssl_acceptor_fd->
|
2003-08-29 13:44:35 +03:00
|
|
|
ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
2001-09-30 10:46:20 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_HITS:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
|
|
|
SSL_CTX_sess_hits(ssl_acceptor_fd->
|
2003-08-29 13:44:35 +03:00
|
|
|
ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-09-30 10:46:20 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_CTX_SESS_CACHE_FULL:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
|
|
|
SSL_CTX_sess_cache_full(ssl_acceptor_fd->
|
2003-08-29 13:44:35 +03:00
|
|
|
ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-09-30 10:46:20 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_CTX_SESS_MISSES:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
|
|
|
SSL_CTX_sess_misses(ssl_acceptor_fd->
|
2003-08-29 13:44:35 +03:00
|
|
|
ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff, 10);
|
2001-09-30 10:46:20 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_CTX_SESS_TIMEOUTS:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_sess_timeouts(ssl_acceptor_fd->ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff,10);
|
2001-09-30 10:46:20 +08:00
|
|
|
break;
|
2001-08-27 03:34:52 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_NUMBER:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_sess_number(ssl_acceptor_fd->ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff,10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
2001-09-30 10:46:20 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_CONNECT:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_sess_connect(ssl_acceptor_fd->ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff,10);
|
2001-09-30 10:46:20 +08:00
|
|
|
break;
|
2001-08-27 03:34:52 +08:00
|
|
|
case SHOW_SSL_CTX_SESS_GET_CACHE_SIZE:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_sess_get_cache_size(ssl_acceptor_fd->ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff,10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_CTX_GET_VERIFY_MODE:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_get_verify_mode(ssl_acceptor_fd->ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff,10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_CTX_GET_VERIFY_DEPTH:
|
2002-12-11 09:17:51 +02:00
|
|
|
end= int10_to_str((long) (!ssl_acceptor_fd ? 0 :
|
2003-08-29 13:44:35 +03:00
|
|
|
SSL_CTX_get_verify_depth(ssl_acceptor_fd->ssl_context)),
|
2002-12-11 09:17:51 +02:00
|
|
|
buff,10);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_CTX_GET_SESSION_CACHE_MODE:
|
2001-12-13 22:03:09 +02:00
|
|
|
if (!ssl_acceptor_fd)
|
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "NONE";
|
|
|
|
end= pos+4;
|
2001-12-13 22:03:09 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-08-27 02:51:39 +03:00
|
|
|
switch (SSL_CTX_get_session_cache_mode(ssl_acceptor_fd->ssl_context))
|
2001-08-27 03:34:52 +08:00
|
|
|
{
|
|
|
|
case SSL_SESS_CACHE_OFF:
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "OFF";
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SSL_SESS_CACHE_CLIENT:
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "CLIENT";
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SSL_SESS_CACHE_SERVER:
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "SERVER";
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SSL_SESS_CACHE_BOTH:
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "BOTH";
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SSL_SESS_CACHE_NO_AUTO_CLEAR:
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "NO_AUTO_CLEAR";
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
case SSL_SESS_CACHE_NO_INTERNAL_LOOKUP:
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "NO_INTERNAL_LOOKUP";
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
default:
|
2002-12-11 09:17:51 +02:00
|
|
|
pos= "Unknown";
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
|
|
|
}
|
2003-02-17 18:06:51 +04:00
|
|
|
end= strend(pos);
|
2001-08-27 03:34:52 +08:00
|
|
|
break;
|
2001-09-01 05:18:01 +08:00
|
|
|
/* First group - functions relying on SSL */
|
|
|
|
case SHOW_SSL_GET_VERSION:
|
2003-08-29 13:44:35 +03:00
|
|
|
pos= (thd->net.vio->ssl_arg ?
|
|
|
|
SSL_get_version((SSL*) thd->net.vio->ssl_arg) : "");
|
2002-12-11 09:17:51 +02:00
|
|
|
end= strend(pos);
|
2001-09-01 05:18:01 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_SESSION_REUSED:
|
2003-08-29 13:44:35 +03:00
|
|
|
end= int10_to_str((long) (thd->net.vio->ssl_arg ?
|
|
|
|
SSL_session_reused((SSL*) thd->net.vio->
|
|
|
|
ssl_arg) :
|
|
|
|
0),
|
|
|
|
buff, 10);
|
2001-09-01 05:18:01 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_GET_DEFAULT_TIMEOUT:
|
2003-08-29 13:44:35 +03:00
|
|
|
end= int10_to_str((long) (thd->net.vio->ssl_arg ?
|
|
|
|
SSL_get_default_timeout((SSL*) thd->net.vio->
|
|
|
|
ssl_arg) :
|
|
|
|
0),
|
|
|
|
buff, 10);
|
2001-09-01 05:18:01 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_GET_VERIFY_MODE:
|
2003-08-29 13:44:35 +03:00
|
|
|
end= int10_to_str((long) (thd->net.vio->ssl_arg ?
|
|
|
|
SSL_get_verify_mode((SSL*) thd->net.vio->
|
|
|
|
ssl_arg):
|
|
|
|
0),
|
|
|
|
buff, 10);
|
2001-09-01 05:18:01 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_GET_VERIFY_DEPTH:
|
2003-08-29 13:44:35 +03:00
|
|
|
end= int10_to_str((long) (thd->net.vio->ssl_arg ?
|
|
|
|
SSL_get_verify_depth((SSL*) thd->net.vio->
|
|
|
|
ssl_arg):
|
|
|
|
0),
|
|
|
|
buff, 10);
|
2001-09-01 05:18:01 +08:00
|
|
|
break;
|
|
|
|
case SHOW_SSL_GET_CIPHER:
|
2003-08-29 13:44:35 +03:00
|
|
|
pos= (thd->net.vio->ssl_arg ?
|
|
|
|
SSL_get_cipher((SSL*) thd->net.vio->ssl_arg) : "" );
|
2002-12-11 09:17:51 +02:00
|
|
|
end= strend(pos);
|
2001-12-13 22:03:09 +02:00
|
|
|
break;
|
2001-09-30 10:46:20 +08:00
|
|
|
case SHOW_SSL_GET_CIPHER_LIST:
|
2003-08-27 02:51:39 +03:00
|
|
|
if (thd->net.vio->ssl_arg)
|
2001-09-30 10:46:20 +08:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
char *to= buff;
|
2001-12-13 22:03:09 +02:00
|
|
|
for (int i=0 ; i++ ;)
|
2001-09-30 10:46:20 +08:00
|
|
|
{
|
2003-08-29 13:44:35 +03:00
|
|
|
const char *p= SSL_get_cipher_list((SSL*) thd->net.vio->ssl_arg,i);
|
2001-09-30 10:46:20 +08:00
|
|
|
if (p == NULL)
|
|
|
|
break;
|
2002-12-11 09:17:51 +02:00
|
|
|
to= strmov(to, p);
|
|
|
|
*to++= ':';
|
2001-09-30 10:46:20 +08:00
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
if (to != buff)
|
|
|
|
to--; // Remove last ':'
|
|
|
|
end= to;
|
2001-12-13 22:03:09 +02:00
|
|
|
}
|
2001-09-01 05:18:01 +08:00
|
|
|
break;
|
2001-08-27 03:34:52 +08:00
|
|
|
|
|
|
|
#endif /* HAVE_OPENSSL */
|
2003-11-18 13:47:27 +02:00
|
|
|
case SHOW_KEY_CACHE_LONG:
|
2004-05-03 15:55:21 +02:00
|
|
|
case SHOW_KEY_CACHE_CONST_LONG:
|
2005-01-19 12:55:54 +02:00
|
|
|
value= (value-(char*) &dflt_key_cache_var)+ (char*) dflt_key_cache;
|
2003-11-18 13:47:27 +02:00
|
|
|
end= int10_to_str(*(long*) value, buff, 10);
|
|
|
|
break;
|
2005-09-14 13:18:16 +02:00
|
|
|
case SHOW_KEY_CACHE_LONGLONG:
|
|
|
|
value= (value-(char*) &dflt_key_cache_var)+ (char*) dflt_key_cache;
|
|
|
|
end= longlong10_to_str(*(longlong*) value, buff, 10);
|
|
|
|
break;
|
2002-07-23 18:31:22 +03:00
|
|
|
case SHOW_UNDEF: // Show never happen
|
|
|
|
case SHOW_SYS:
|
2002-12-11 09:17:51 +02:00
|
|
|
break; // Return empty string
|
2003-01-15 12:11:44 +04:00
|
|
|
default:
|
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-03-17 13:14:04 +04:00
|
|
|
if (protocol->store(pos, (uint32) (end - pos), system_charset_info) ||
|
2002-12-11 09:17:51 +02:00
|
|
|
protocol->write())
|
2000-09-01 15:24:36 +04:00
|
|
|
goto err; /* purecov: inspected */
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
2003-08-17 14:37:26 +03:00
|
|
|
pthread_mutex_unlock(mutex);
|
2002-10-02 13:33:08 +03:00
|
|
|
send_eof(thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
err:
|
2003-08-17 14:37:26 +03:00
|
|
|
pthread_mutex_unlock(mutex);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
2001-08-02 06:29:50 +03:00
|
|
|
template class List_iterator_fast<char>;
|
2000-07-31 21:29:14 +02:00
|
|
|
template class List<char>;
|
|
|
|
#endif
|