2002-12-12 13:14:23 +01:00
|
|
|
/* Copyright (C) 2002 MySQL AB
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
2004-03-19 19:01:54 +01:00
|
|
|
#include "sql_acl.h"
|
2002-12-12 13:14:23 +01:00
|
|
|
#include "sp.h"
|
|
|
|
#include "sp_head.h"
|
2003-07-03 15:58:37 +02:00
|
|
|
#include "sp_cache.h"
|
2003-07-01 18:14:24 +02:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
static char *
|
|
|
|
create_string(THD *thd, ulong *lenp,
|
|
|
|
int sp_type,
|
2004-03-11 17:18:59 +01:00
|
|
|
sp_name *name,
|
2003-12-12 14:05:29 +01:00
|
|
|
const char *params, ulong paramslen,
|
|
|
|
const char *returns, ulong returnslen,
|
|
|
|
const char *body, ulong bodylen,
|
|
|
|
st_sp_chistics *chistics);
|
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* DB storage of Stored PROCEDUREs and FUNCTIONs
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
enum
|
|
|
|
{
|
2003-12-16 19:14:10 +01:00
|
|
|
MYSQL_PROC_FIELD_DB = 0,
|
2003-12-12 14:05:29 +01:00
|
|
|
MYSQL_PROC_FIELD_NAME,
|
|
|
|
MYSQL_PROC_FIELD_TYPE,
|
|
|
|
MYSQL_PROC_FIELD_SPECIFIC_NAME,
|
|
|
|
MYSQL_PROC_FIELD_LANGUAGE,
|
|
|
|
MYSQL_PROC_FIELD_ACCESS,
|
|
|
|
MYSQL_PROC_FIELD_DETERMINISTIC,
|
|
|
|
MYSQL_PROC_FIELD_SECURITY_TYPE,
|
|
|
|
MYSQL_PROC_FIELD_PARAM_LIST,
|
|
|
|
MYSQL_PROC_FIELD_RETURNS,
|
|
|
|
MYSQL_PROC_FIELD_BODY,
|
|
|
|
MYSQL_PROC_FIELD_DEFINER,
|
|
|
|
MYSQL_PROC_FIELD_CREATED,
|
|
|
|
MYSQL_PROC_FIELD_MODIFIED,
|
|
|
|
MYSQL_PROC_FIELD_SQL_MODE,
|
|
|
|
MYSQL_PROC_FIELD_COMMENT,
|
|
|
|
MYSQL_PROC_FIELD_COUNT
|
|
|
|
};
|
2003-10-30 10:25:45 +01:00
|
|
|
|
|
|
|
/* *opened=true means we opened ourselves */
|
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
2004-02-17 17:36:53 +01:00
|
|
|
db_find_routine_aux(THD *thd, int type, sp_name *name,
|
2003-03-02 19:17:41 +01:00
|
|
|
enum thr_lock_type ltype, TABLE **tablep, bool *opened)
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
2003-12-16 19:14:10 +01:00
|
|
|
byte key[64+64+1]; // db, name, type
|
2003-02-21 17:37:05 +01:00
|
|
|
uint keylen;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_find_routine_aux");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %*s",
|
|
|
|
type, name->m_name.length, name->m_name.str));
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
// Put the key used to read the row together
|
2004-03-11 17:18:59 +01:00
|
|
|
keylen= name->m_db.length;
|
|
|
|
if (keylen > 64)
|
|
|
|
keylen= 64;
|
|
|
|
memcpy(key, name->m_db.str, keylen);
|
|
|
|
memset(key+keylen, (int)' ', 64-keylen); // Pad with space
|
2004-02-17 17:36:53 +01:00
|
|
|
keylen= name->m_name.length;
|
2003-12-10 19:05:37 +01:00
|
|
|
if (keylen > 64)
|
|
|
|
keylen= 64;
|
2004-02-17 17:36:53 +01:00
|
|
|
memcpy(key+64, name->m_name.str, keylen);
|
2003-12-10 19:05:37 +01:00
|
|
|
memset(key+64+keylen, (int)' ', 64-keylen); // Pad with space
|
|
|
|
key[128]= type;
|
2003-02-21 17:37:05 +01:00
|
|
|
keylen= sizeof(key);
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-03-02 19:17:41 +01:00
|
|
|
for (table= thd->open_tables ; table ; table= table->next)
|
|
|
|
if (strcmp(table->table_cache_key, "mysql") == 0 &&
|
|
|
|
strcmp(table->real_name, "proc") == 0)
|
|
|
|
break;
|
|
|
|
if (table)
|
|
|
|
*opened= FALSE;
|
|
|
|
else
|
2003-02-28 15:07:14 +01:00
|
|
|
{
|
2003-03-02 19:17:41 +01:00
|
|
|
TABLE_LIST tables;
|
|
|
|
|
|
|
|
memset(&tables, 0, sizeof(tables));
|
|
|
|
tables.db= (char*)"mysql";
|
|
|
|
tables.real_name= tables.alias= (char*)"proc";
|
|
|
|
if (! (table= open_ltable(thd, &tables, ltype)))
|
|
|
|
{
|
|
|
|
*tablep= NULL;
|
|
|
|
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
|
|
|
|
}
|
|
|
|
*opened= TRUE;
|
2003-02-28 15:07:14 +01:00
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
|
|
|
if (table->file->index_read_idx(table->record[0], 0,
|
2003-02-21 17:37:05 +01:00
|
|
|
key, keylen,
|
2002-12-12 13:14:23 +01:00
|
|
|
HA_READ_KEY_EXACT))
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2003-02-28 15:07:14 +01:00
|
|
|
*tablep= NULL;
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
|
|
|
}
|
|
|
|
*tablep= table;
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(SP_OK);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
2004-02-17 17:36:53 +01:00
|
|
|
db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
extern int yyparse(void *thd);
|
|
|
|
TABLE *table;
|
2003-12-12 14:05:29 +01:00
|
|
|
const char *params, *returns, *body;
|
2003-02-21 17:37:05 +01:00
|
|
|
int ret;
|
2003-03-02 19:17:41 +01:00
|
|
|
bool opened;
|
2003-12-13 16:40:52 +01:00
|
|
|
const char *definer;
|
2003-05-06 18:09:20 +02:00
|
|
|
longlong created;
|
|
|
|
longlong modified;
|
2003-12-13 16:40:52 +01:00
|
|
|
st_sp_chistics chistics;
|
2003-05-06 18:09:20 +02:00
|
|
|
char *ptr;
|
|
|
|
uint length;
|
|
|
|
char buff[65];
|
2003-07-03 15:58:37 +02:00
|
|
|
String str(buff, sizeof(buff), &my_charset_bin);
|
2003-12-11 12:23:50 +01:00
|
|
|
ulong sql_mode;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_find_routine");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %*s",
|
|
|
|
type, name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
ret= db_find_routine_aux(thd, type, name, TL_READ, &table, &opened);
|
2003-02-21 17:37:05 +01:00
|
|
|
if (ret != SP_OK)
|
|
|
|
goto done;
|
2003-10-30 10:25:45 +01:00
|
|
|
|
|
|
|
if (table->fields != MYSQL_PROC_FIELD_COUNT)
|
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if ((ptr= get_field(&thd->mem_root,
|
|
|
|
table->field[MYSQL_PROC_FIELD_DETERMINISTIC])) == NULL)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2003-12-13 16:40:52 +01:00
|
|
|
bzero((char *)&chistics, sizeof(chistics));
|
|
|
|
chistics.detistic= (ptr[0] == 'N' ? FALSE : TRUE);
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if ((ptr= get_field(&thd->mem_root,
|
|
|
|
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE])) == NULL)
|
2003-05-06 18:09:20 +02:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2003-12-13 16:40:52 +01:00
|
|
|
chistics.suid= (ptr[0] == 'I' ? IS_NOT_SUID : IS_SUID);
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if ((params= get_field(&thd->mem_root,
|
|
|
|
table->field[MYSQL_PROC_FIELD_PARAM_LIST])) == NULL)
|
|
|
|
{
|
|
|
|
params= "";
|
|
|
|
}
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if (type == TYPE_ENUM_PROCEDURE)
|
|
|
|
returns= "";
|
|
|
|
else if ((returns= get_field(&thd->mem_root,
|
|
|
|
table->field[MYSQL_PROC_FIELD_RETURNS])) == NULL)
|
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((body= get_field(&thd->mem_root,
|
|
|
|
table->field[MYSQL_PROC_FIELD_BODY])) == NULL)
|
2003-05-06 18:09:20 +02:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2003-12-12 14:05:29 +01:00
|
|
|
|
|
|
|
// Get additional information
|
2003-12-13 16:40:52 +01:00
|
|
|
if ((definer= get_field(&thd->mem_root,
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_DEFINER])) == NULL)
|
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
modified= table->field[MYSQL_PROC_FIELD_MODIFIED]->val_int();
|
|
|
|
created= table->field[MYSQL_PROC_FIELD_CREATED]->val_int();
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2003-12-21 01:07:45 +01:00
|
|
|
sql_mode= (ulong) table->field[MYSQL_PROC_FIELD_SQL_MODE]->val_int();
|
2003-12-11 12:23:50 +01:00
|
|
|
|
2003-10-30 10:25:45 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_COMMENT]->val_str(&str, &str);
|
|
|
|
|
2003-05-06 18:09:20 +02:00
|
|
|
ptr= 0;
|
2003-06-02 11:25:01 +02:00
|
|
|
if ((length= str.length()))
|
2003-12-12 14:05:29 +01:00
|
|
|
ptr= thd->strmake(str.ptr(), length);
|
2003-12-13 16:40:52 +01:00
|
|
|
chistics.comment.str= ptr;
|
|
|
|
chistics.comment.length= length;
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2003-03-02 19:17:41 +01:00
|
|
|
if (opened)
|
|
|
|
{
|
2003-09-17 12:30:05 +02:00
|
|
|
opened= FALSE;
|
2003-12-21 11:48:03 +01:00
|
|
|
close_thread_tables(thd, 0, 1);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2003-05-06 18:09:20 +02:00
|
|
|
{
|
2003-12-12 14:05:29 +01:00
|
|
|
char *defstr;
|
|
|
|
ulong deflen;
|
2003-05-23 15:32:31 +02:00
|
|
|
LEX *oldlex= thd->lex;
|
2004-03-11 17:18:59 +01:00
|
|
|
char olddb[128];
|
2004-06-08 18:41:18 +02:00
|
|
|
bool dbchanged;
|
2003-05-23 15:32:31 +02:00
|
|
|
enum enum_sql_command oldcmd= thd->lex->sql_command;
|
2003-12-11 12:23:50 +01:00
|
|
|
ulong old_sql_mode= thd->variables.sql_mode;
|
|
|
|
ha_rows select_limit= thd->variables.select_limit;
|
|
|
|
|
|
|
|
thd->variables.sql_mode= sql_mode;
|
|
|
|
thd->variables.select_limit= HA_POS_ERROR;
|
2003-05-23 15:32:31 +02:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
if (!(defstr= create_string(thd, &deflen,
|
2004-03-11 17:18:59 +01:00
|
|
|
type,
|
|
|
|
name,
|
|
|
|
params, strlen(params),
|
|
|
|
returns, strlen(returns),
|
|
|
|
body, strlen(body),
|
2003-12-21 11:48:03 +01:00
|
|
|
&chistics)))
|
|
|
|
{
|
|
|
|
ret= SP_INTERNAL_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-06-08 18:41:18 +02:00
|
|
|
dbchanged= FALSE;
|
|
|
|
if ((ret= sp_use_new_db(thd, name->m_db.str, olddb, sizeof(olddb),
|
|
|
|
1, &dbchanged)))
|
2004-03-11 17:18:59 +01:00
|
|
|
goto done;
|
|
|
|
|
2004-03-17 12:09:03 +01:00
|
|
|
{
|
|
|
|
/* This is something of a kludge. We need to initialize some fields
|
|
|
|
* in thd->lex (the unit and master stuff), and the easiest way to
|
|
|
|
* do it is, is to call mysql_init_query(), but this unfortunately
|
|
|
|
* resets teh value_list where we keep the CALL parameters. So we
|
|
|
|
* copy the list and then restore it.
|
|
|
|
*/
|
|
|
|
List<Item> vals= thd->lex->value_list;
|
|
|
|
|
|
|
|
mysql_init_query(thd, TRUE);
|
|
|
|
lex_start(thd, (uchar*)defstr, deflen);
|
|
|
|
thd->lex->value_list= vals;
|
|
|
|
}
|
|
|
|
|
2003-05-23 15:32:31 +02:00
|
|
|
if (yyparse(thd) || thd->is_fatal_error || thd->lex->sphead == NULL)
|
|
|
|
{
|
2003-07-01 17:19:48 +02:00
|
|
|
LEX *newlex= thd->lex;
|
|
|
|
sp_head *sp= newlex->sphead;
|
|
|
|
|
2004-06-08 18:41:18 +02:00
|
|
|
if (dbchanged && (ret= sp_change_db(thd, olddb, 1)))
|
2004-03-11 17:18:59 +01:00
|
|
|
goto done;
|
2003-07-01 17:19:48 +02:00
|
|
|
if (sp)
|
2003-05-23 15:32:31 +02:00
|
|
|
{
|
2003-07-01 17:19:48 +02:00
|
|
|
if (oldlex != newlex)
|
|
|
|
sp->restore_lex(thd);
|
|
|
|
delete sp;
|
|
|
|
newlex->sphead= NULL;
|
2003-05-23 15:32:31 +02:00
|
|
|
}
|
|
|
|
ret= SP_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-08 18:41:18 +02:00
|
|
|
if (dbchanged && (ret= sp_change_db(thd, olddb, 1)))
|
2004-03-11 17:18:59 +01:00
|
|
|
goto done;
|
2003-05-23 15:32:31 +02:00
|
|
|
*sphp= thd->lex->sphead;
|
2003-12-13 16:40:52 +01:00
|
|
|
(*sphp)->set_info((char *)definer, (uint)strlen(definer),
|
|
|
|
created, modified, &chistics);
|
2003-05-23 15:32:31 +02:00
|
|
|
}
|
|
|
|
thd->lex->sql_command= oldcmd;
|
2003-12-11 12:23:50 +01:00
|
|
|
thd->variables.sql_mode= old_sql_mode;
|
|
|
|
thd->variables.select_limit= select_limit;
|
2003-05-06 18:09:20 +02:00
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
|
|
|
done:
|
2004-03-11 17:18:59 +01:00
|
|
|
|
2003-09-17 12:30:05 +02:00
|
|
|
if (opened)
|
2002-12-12 13:14:23 +01:00
|
|
|
close_thread_tables(thd);
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(ret);
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
2003-12-12 14:05:29 +01:00
|
|
|
db_create_routine(THD *thd, int type, sp_head *sp)
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
2003-02-21 17:37:05 +01:00
|
|
|
int ret;
|
2002-12-12 13:14:23 +01:00
|
|
|
TABLE *table;
|
|
|
|
TABLE_LIST tables;
|
2003-12-13 16:40:52 +01:00
|
|
|
char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2];
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_create_routine");
|
|
|
|
DBUG_PRINT("enter", ("type: %d name: %*s",type,sp->m_name.length,sp->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
|
|
|
memset(&tables, 0, sizeof(tables));
|
|
|
|
tables.db= (char*)"mysql";
|
|
|
|
tables.real_name= tables.alias= (char*)"proc";
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
|
2003-02-21 17:37:05 +01:00
|
|
|
ret= SP_OPEN_TABLE_FAILED;
|
|
|
|
else
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
2003-07-09 17:07:12 +02:00
|
|
|
restore_record(table, default_values); // Get default values for fields
|
2003-12-13 16:40:52 +01:00
|
|
|
strxmov(definer, thd->priv_user, "@", thd->priv_host, NullS);
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2003-10-30 10:25:45 +01:00
|
|
|
if (table->fields != MYSQL_PROC_FIELD_COUNT)
|
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2004-03-11 17:18:59 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_DB]->
|
|
|
|
store(sp->m_db.str, sp->m_db.length, system_charset_info);
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_NAME]->
|
|
|
|
store(sp->m_name.str, sp->m_name.length, system_charset_info);
|
|
|
|
table->field[MYSQL_PROC_FIELD_TYPE]->
|
|
|
|
store((longlong)type);
|
|
|
|
table->field[MYSQL_PROC_FIELD_SPECIFIC_NAME]->
|
|
|
|
store(sp->m_name.str, sp->m_name.length, system_charset_info);
|
|
|
|
table->field[MYSQL_PROC_FIELD_DETERMINISTIC]->
|
|
|
|
store((longlong)(sp->m_chistics->detistic ? 1 : 2));
|
|
|
|
if (sp->m_chistics->suid != IS_DEFAULT_SUID)
|
|
|
|
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
|
|
|
|
store((longlong)sp->m_chistics->suid);
|
|
|
|
table->field[MYSQL_PROC_FIELD_PARAM_LIST]->
|
|
|
|
store(sp->m_params.str, sp->m_params.length, system_charset_info);
|
|
|
|
if (sp->m_retstr.str)
|
|
|
|
table->field[MYSQL_PROC_FIELD_RETURNS]->
|
|
|
|
store(sp->m_retstr.str, sp->m_retstr.length, system_charset_info);
|
|
|
|
table->field[MYSQL_PROC_FIELD_BODY]->
|
|
|
|
store(sp->m_body.str, sp->m_body.length, system_charset_info);
|
|
|
|
table->field[MYSQL_PROC_FIELD_DEFINER]->
|
2003-12-13 16:40:52 +01:00
|
|
|
store(definer, (uint)strlen(definer), system_charset_info);
|
2003-10-30 10:25:45 +01:00
|
|
|
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_CREATED])->set_time();
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_SQL_MODE]->
|
|
|
|
store((longlong)thd->variables.sql_mode);
|
|
|
|
if (sp->m_chistics->comment.str)
|
|
|
|
table->field[MYSQL_PROC_FIELD_COMMENT]->
|
|
|
|
store(sp->m_chistics->comment.str, sp->m_chistics->comment.length,
|
|
|
|
system_charset_info);
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
ret= SP_OK;
|
2003-02-21 17:37:05 +01:00
|
|
|
if (table->file->write_row(table->record[0]))
|
|
|
|
ret= SP_WRITE_ROW_FAILED;
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
|
|
|
|
2003-10-30 10:25:45 +01:00
|
|
|
done:
|
2003-02-28 15:07:14 +01:00
|
|
|
close_thread_tables(thd);
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
2004-02-17 17:36:53 +01:00
|
|
|
db_drop_routine(THD *thd, int type, sp_name *name)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
int ret;
|
2003-03-02 19:17:41 +01:00
|
|
|
bool opened;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_drop_routine");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %*s",
|
|
|
|
type, name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
ret= db_find_routine_aux(thd, type, name, TL_WRITE, &table, &opened);
|
2003-02-21 17:37:05 +01:00
|
|
|
if (ret == SP_OK)
|
|
|
|
{
|
|
|
|
if (table->file->delete_row(table->record[0]))
|
|
|
|
ret= SP_DELETE_ROW_FAILED;
|
|
|
|
}
|
|
|
|
|
2003-03-02 19:17:41 +01:00
|
|
|
if (opened)
|
|
|
|
close_thread_tables(thd);
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
static int
|
2004-02-17 17:36:53 +01:00
|
|
|
db_update_routine(THD *thd, int type, sp_name *name,
|
2003-11-17 18:21:36 +01:00
|
|
|
char *newname, uint newnamelen,
|
2003-12-10 19:05:37 +01:00
|
|
|
st_sp_chistics *chistics)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
int ret;
|
|
|
|
bool opened;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_update_routine");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %*s",
|
|
|
|
type, name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
ret= db_find_routine_aux(thd, type, name, TL_WRITE, &table, &opened);
|
2003-11-17 18:21:36 +01:00
|
|
|
if (ret == SP_OK)
|
|
|
|
{
|
|
|
|
store_record(table,record[1]);
|
|
|
|
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time();
|
2003-12-12 14:05:29 +01:00
|
|
|
if (chistics->suid != IS_DEFAULT_SUID)
|
2003-12-10 19:05:37 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->store((longlong)chistics->suid);
|
2003-11-17 18:21:36 +01:00
|
|
|
if (newname)
|
|
|
|
table->field[MYSQL_PROC_FIELD_NAME]->store(newname,
|
|
|
|
newnamelen,
|
|
|
|
system_charset_info);
|
2003-12-10 19:05:37 +01:00
|
|
|
if (chistics->comment.str)
|
|
|
|
table->field[MYSQL_PROC_FIELD_COMMENT]->store(chistics->comment.str,
|
|
|
|
chistics->comment.length,
|
2003-11-17 18:21:36 +01:00
|
|
|
system_charset_info);
|
|
|
|
if ((table->file->update_row(table->record[1],table->record[0])))
|
|
|
|
ret= SP_WRITE_ROW_FAILED;
|
|
|
|
}
|
|
|
|
if (opened)
|
|
|
|
close_thread_tables(thd);
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
struct st_used_field
|
|
|
|
{
|
|
|
|
const char *field_name;
|
|
|
|
uint field_length;
|
|
|
|
enum enum_field_types field_type;
|
|
|
|
Field *field;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct st_used_field init_fields[]=
|
|
|
|
{
|
2004-03-11 17:18:59 +01:00
|
|
|
{ "Db", NAME_LEN, MYSQL_TYPE_STRING, 0},
|
2003-11-17 18:21:36 +01:00
|
|
|
{ "Name", NAME_LEN, MYSQL_TYPE_STRING, 0},
|
|
|
|
{ "Type", 9, MYSQL_TYPE_STRING, 0},
|
2003-12-10 19:05:37 +01:00
|
|
|
{ "Definer", 77, MYSQL_TYPE_STRING, 0},
|
2003-11-17 18:21:36 +01:00
|
|
|
{ "Modified", 0, MYSQL_TYPE_TIMESTAMP, 0},
|
|
|
|
{ "Created", 0, MYSQL_TYPE_TIMESTAMP, 0},
|
2003-12-10 19:05:37 +01:00
|
|
|
{ "Security_type", 1, MYSQL_TYPE_STRING, 0},
|
2003-11-17 18:21:36 +01:00
|
|
|
{ "Comment", NAME_LEN, MYSQL_TYPE_STRING, 0},
|
|
|
|
{ 0, 0, MYSQL_TYPE_STRING, 0}
|
|
|
|
};
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-20 15:07:22 +01:00
|
|
|
static int
|
|
|
|
print_field_values(THD *thd, TABLE *table,
|
|
|
|
struct st_used_field *used_fields,
|
|
|
|
int type, const char *wild)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
|
|
|
|
if (table->field[MYSQL_PROC_FIELD_TYPE]->val_int() == type)
|
|
|
|
{
|
2004-03-11 17:18:59 +01:00
|
|
|
String db_string;
|
|
|
|
String name_string;
|
2003-11-17 18:21:36 +01:00
|
|
|
struct st_used_field *used_field= used_fields;
|
2003-11-20 15:07:22 +01:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
if (get_field(&thd->mem_root, used_field->field, &db_string))
|
|
|
|
db_string.set_ascii("", 0);
|
|
|
|
used_field+= 1;
|
|
|
|
get_field(&thd->mem_root, used_field->field, &name_string);
|
|
|
|
|
|
|
|
if (!wild || !wild[0] || !wild_compare(name_string.ptr(), wild, 0))
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
|
|
|
protocol->prepare_for_resend();
|
2004-03-11 17:18:59 +01:00
|
|
|
protocol->store(&db_string);
|
|
|
|
protocol->store(&name_string);
|
2003-11-17 18:21:36 +01:00
|
|
|
for (used_field++;
|
|
|
|
used_field->field_name;
|
|
|
|
used_field++)
|
|
|
|
{
|
|
|
|
switch (used_field->field_type) {
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
|
|
|
TIME tmp_time;
|
2003-12-10 19:05:37 +01:00
|
|
|
|
|
|
|
bzero((char *)&tmp_time, sizeof(tmp_time));
|
2003-11-20 15:07:22 +01:00
|
|
|
((Field_timestamp *) used_field->field)->get_time(&tmp_time);
|
|
|
|
protocol->store(&tmp_time);
|
|
|
|
}
|
|
|
|
break;
|
2003-11-17 18:21:36 +01:00
|
|
|
default:
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
2004-03-11 17:18:59 +01:00
|
|
|
String tmp_string;
|
2003-12-10 19:05:37 +01:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
get_field(&thd->mem_root, used_field->field, &tmp_string);
|
|
|
|
protocol->store(&tmp_string);
|
2003-11-20 15:07:22 +01:00
|
|
|
}
|
|
|
|
break;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (protocol->write())
|
2003-11-20 15:07:22 +01:00
|
|
|
return SP_INTERNAL_ERROR;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
return SP_OK;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-20 15:07:22 +01:00
|
|
|
static int
|
2003-11-17 18:21:36 +01:00
|
|
|
db_show_routine_status(THD *thd, int type, const char *wild)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
TABLE_LIST tables;
|
2003-11-20 15:07:22 +01:00
|
|
|
int res;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_show_routine_status");
|
2003-11-17 18:21:36 +01:00
|
|
|
|
|
|
|
memset(&tables, 0, sizeof(tables));
|
|
|
|
tables.db= (char*)"mysql";
|
|
|
|
tables.real_name= tables.alias= (char*)"proc";
|
|
|
|
|
|
|
|
if (! (table= open_ltable(thd, &tables, TL_READ)))
|
|
|
|
{
|
2003-11-20 15:07:22 +01:00
|
|
|
res= SP_OPEN_TABLE_FAILED;
|
|
|
|
goto done;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Item *item;
|
|
|
|
List<Item> field_list;
|
|
|
|
struct st_used_field *used_field;
|
|
|
|
st_used_field used_fields[array_elements(init_fields)];
|
2003-11-20 15:07:22 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
memcpy((char*) used_fields, (char*) init_fields, sizeof(used_fields));
|
|
|
|
/* Init header */
|
|
|
|
for (used_field= &used_fields[0];
|
|
|
|
used_field->field_name;
|
|
|
|
used_field++)
|
|
|
|
{
|
|
|
|
switch (used_field->field_type) {
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
field_list.push_back(item=new Item_datetime(used_field->field_name));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
field_list.push_back(item=new Item_empty_string(used_field->field_name,
|
|
|
|
used_field->
|
|
|
|
field_length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Print header */
|
|
|
|
if (thd->protocol->send_fields(&field_list,1))
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
|
|
|
res= SP_INTERNAL_ERROR;
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case;
|
2003-11-20 15:07:22 +01:00
|
|
|
}
|
2003-11-17 18:21:36 +01:00
|
|
|
|
|
|
|
/* Init fields */
|
2004-04-28 12:08:54 +02:00
|
|
|
setup_tables(&tables);
|
2003-11-17 18:21:36 +01:00
|
|
|
for (used_field= &used_fields[0];
|
|
|
|
used_field->field_name;
|
|
|
|
used_field++)
|
|
|
|
{
|
|
|
|
TABLE_LIST *not_used;
|
|
|
|
Item_field *field= new Item_field("mysql", "proc",
|
|
|
|
used_field->field_name);
|
|
|
|
if (!(used_field->field= find_field_in_tables(thd, field, &tables,
|
|
|
|
¬_used, TRUE)))
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
|
|
|
res= SP_INTERNAL_ERROR;
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case1;
|
2003-11-20 15:07:22 +01:00
|
|
|
}
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
table->file->index_init(0);
|
2003-11-20 15:07:22 +01:00
|
|
|
if ((res= table->file->index_first(table->record[0])))
|
|
|
|
{
|
2003-12-21 11:48:03 +01:00
|
|
|
res= (res == HA_ERR_END_OF_FILE) ? 0 : SP_INTERNAL_ERROR;
|
2003-11-20 15:07:22 +01:00
|
|
|
goto err_case1;
|
|
|
|
}
|
|
|
|
if ((res= print_field_values(thd, table, used_fields, type, wild)))
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case1;
|
|
|
|
while (!table->file->index_next(table->record[0]))
|
|
|
|
{
|
2003-11-20 15:07:22 +01:00
|
|
|
if ((res= print_field_values(thd, table, used_fields, type, wild)))
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case1;
|
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
res= SP_OK;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
err_case1:
|
2003-11-17 18:21:36 +01:00
|
|
|
send_eof(thd);
|
2003-12-21 11:48:03 +01:00
|
|
|
err_case:
|
2003-11-17 18:21:36 +01:00
|
|
|
close_thread_tables(thd);
|
2003-12-21 11:48:03 +01:00
|
|
|
done:
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_RETURN(res);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2004-03-22 14:44:41 +01:00
|
|
|
/* Drop all routines in database 'db' */
|
|
|
|
int
|
|
|
|
sp_drop_db_routines(THD *thd, char *db)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
byte key[64]; // db
|
|
|
|
uint keylen;
|
|
|
|
int ret;
|
|
|
|
DBUG_ENTER("sp_drop_db_routines");
|
|
|
|
DBUG_PRINT("enter", ("db: %s", db));
|
|
|
|
|
|
|
|
// Put the key used to read the row together
|
|
|
|
keylen= strlen(db);
|
|
|
|
if (keylen > 64)
|
|
|
|
keylen= 64;
|
|
|
|
memcpy(key, db, keylen);
|
|
|
|
memset(key+keylen, (int)' ', 64-keylen); // Pad with space
|
|
|
|
keylen= sizeof(key);
|
|
|
|
|
|
|
|
for (table= thd->open_tables ; table ; table= table->next)
|
|
|
|
if (strcmp(table->table_cache_key, "mysql") == 0 &&
|
|
|
|
strcmp(table->real_name, "proc") == 0)
|
|
|
|
break;
|
|
|
|
if (! table)
|
|
|
|
{
|
|
|
|
TABLE_LIST tables;
|
|
|
|
|
|
|
|
memset(&tables, 0, sizeof(tables));
|
|
|
|
tables.db= (char*)"mysql";
|
|
|
|
tables.real_name= tables.alias= (char*)"proc";
|
|
|
|
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
|
|
|
|
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret= SP_OK;
|
|
|
|
table->file->index_init(0);
|
|
|
|
if (! table->file->index_read(table->record[0],
|
|
|
|
key, keylen, HA_READ_KEY_EXACT))
|
|
|
|
{
|
|
|
|
int nxtres;
|
|
|
|
bool deleted= FALSE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (! table->file->delete_row(table->record[0]))
|
|
|
|
deleted= TRUE; /* We deleted something */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret= SP_DELETE_ROW_FAILED;
|
2004-03-23 12:04:40 +01:00
|
|
|
nxtres= 0;
|
2004-03-22 14:44:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (! (nxtres= table->file->index_next_same(table->record[0],
|
|
|
|
key, keylen)));
|
|
|
|
if (nxtres != HA_ERR_END_OF_FILE)
|
|
|
|
ret= SP_KEY_NOT_FOUND;
|
|
|
|
if (deleted)
|
|
|
|
sp_cache_invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
close_thread_tables(thd);
|
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
PROCEDURE
|
|
|
|
******************************************************************************/
|
2003-02-21 17:37:05 +01:00
|
|
|
|
|
|
|
sp_head *
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_find_procedure(THD *thd, sp_name *name)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
sp_head *sp;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("sp_find_procedure");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s.%*s",
|
|
|
|
name->m_db.length, name->m_db.str,
|
|
|
|
name->m_name.length, name->m_name.str));
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
if (!(sp= sp_cache_lookup(&thd->sp_proc_cache, name)))
|
2003-07-01 18:14:24 +02:00
|
|
|
{
|
2004-02-17 17:36:53 +01:00
|
|
|
if (db_find_routine(thd, TYPE_ENUM_PROCEDURE, name, &sp) == SP_OK)
|
2003-10-21 12:08:35 +02:00
|
|
|
sp_cache_insert(&thd->sp_proc_cache, sp);
|
2003-07-01 18:14:24 +02:00
|
|
|
}
|
2003-02-21 17:37:05 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(sp);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
int
|
2003-12-12 14:05:29 +01:00
|
|
|
sp_create_procedure(THD *thd, sp_head *sp)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_ENTER("sp_create_procedure");
|
2003-12-12 14:05:29 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", sp->m_name.length, sp->m_name.str));
|
2004-01-14 18:18:29 +01:00
|
|
|
|
|
|
|
ret= db_create_routine(thd, TYPE_ENUM_PROCEDURE, sp);
|
|
|
|
DBUG_RETURN(ret);
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
int
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_drop_procedure(THD *thd, sp_name *name)
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_drop_procedure");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_cache_remove(&thd->sp_proc_cache, name);
|
|
|
|
ret= db_drop_routine(thd, TYPE_ENUM_PROCEDURE, name);
|
2004-01-14 18:18:29 +01:00
|
|
|
DBUG_RETURN(ret);
|
2003-02-21 17:37:05 +01:00
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_update_procedure(THD *thd, sp_name *name,
|
2003-11-17 18:21:36 +01:00
|
|
|
char *newname, uint newnamelen,
|
2003-12-10 19:05:37 +01:00
|
|
|
st_sp_chistics *chistics)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_update_procedure");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_cache_remove(&thd->sp_proc_cache, name);
|
|
|
|
ret= db_update_routine(thd, TYPE_ENUM_PROCEDURE, name,
|
2004-01-14 18:18:29 +01:00
|
|
|
newname, newnamelen, chistics);
|
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_show_create_procedure(THD *thd, sp_name *name)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2003-12-21 11:48:03 +01:00
|
|
|
sp_head *sp;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_show_create_procedure");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
if ((sp= sp_find_procedure(thd, name)))
|
2004-01-14 18:18:29 +01:00
|
|
|
{
|
|
|
|
int ret= sp->show_create_procedure(thd);
|
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2003-11-20 15:07:22 +01:00
|
|
|
sp_show_status_procedure(THD *thd, const char *wild)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_ENTER("sp_show_status_procedure");
|
2004-01-14 18:18:29 +01:00
|
|
|
|
|
|
|
ret= db_show_routine_status(thd, TYPE_ENUM_PROCEDURE, wild);
|
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
FUNCTION
|
|
|
|
******************************************************************************/
|
2003-02-21 17:37:05 +01:00
|
|
|
|
|
|
|
sp_head *
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_find_function(THD *thd, sp_name *name)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
sp_head *sp;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("sp_find_function");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
if (!(sp= sp_cache_lookup(&thd->sp_func_cache, name)))
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2004-02-17 17:36:53 +01:00
|
|
|
if (db_find_routine(thd, TYPE_ENUM_FUNCTION, name, &sp) != SP_OK)
|
2003-03-02 19:17:41 +01:00
|
|
|
sp= NULL;
|
2003-12-21 11:48:03 +01:00
|
|
|
else
|
|
|
|
sp_cache_insert(&thd->sp_func_cache, sp);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(sp);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
int
|
2003-12-12 14:05:29 +01:00
|
|
|
sp_create_function(THD *thd, sp_head *sp)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_ENTER("sp_create_function");
|
2003-12-12 14:05:29 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", sp->m_name.length, sp->m_name.str));
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2004-01-14 18:18:29 +01:00
|
|
|
ret= db_create_routine(thd, TYPE_ENUM_FUNCTION, sp);
|
|
|
|
DBUG_RETURN(ret);
|
2003-02-21 17:37:05 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
int
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_drop_function(THD *thd, sp_name *name)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_ENTER("sp_drop_function");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_cache_remove(&thd->sp_func_cache, name);
|
|
|
|
ret= db_drop_routine(thd, TYPE_ENUM_FUNCTION, name);
|
2004-01-14 18:18:29 +01:00
|
|
|
DBUG_RETURN(ret);
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_update_function(THD *thd, sp_name *name,
|
2003-11-17 18:21:36 +01:00
|
|
|
char *newname, uint newnamelen,
|
2003-12-10 19:05:37 +01:00
|
|
|
st_sp_chistics *chistics)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_update_procedure");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_cache_remove(&thd->sp_func_cache, name);
|
|
|
|
ret= db_update_routine(thd, TYPE_ENUM_FUNCTION, name,
|
2004-01-14 18:18:29 +01:00
|
|
|
newname, newnamelen, chistics);
|
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_show_create_function(THD *thd, sp_name *name)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2003-12-21 11:48:03 +01:00
|
|
|
sp_head *sp;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_show_create_function");
|
2004-02-17 17:36:53 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
if ((sp= sp_find_function(thd, name)))
|
2004-01-14 18:18:29 +01:00
|
|
|
{
|
|
|
|
int ret= sp->show_create_function(thd);
|
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2003-11-20 15:07:22 +01:00
|
|
|
sp_show_status_function(THD *thd, const char *wild)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_ENTER("sp_show_status_function");
|
2004-01-14 18:18:29 +01:00
|
|
|
ret= db_show_routine_status(thd, TYPE_ENUM_FUNCTION, wild);
|
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
bool
|
2004-03-11 17:18:59 +01:00
|
|
|
sp_function_exists(THD *thd, sp_name *name)
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
2003-02-28 15:07:14 +01:00
|
|
|
bool ret= FALSE;
|
2003-07-01 18:14:24 +02:00
|
|
|
bool opened= FALSE;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("sp_function_exists");
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
if (sp_cache_lookup(&thd->sp_func_cache, name) ||
|
2003-07-01 18:14:24 +02:00
|
|
|
db_find_routine_aux(thd, TYPE_ENUM_FUNCTION,
|
2004-03-11 17:18:59 +01:00
|
|
|
name, TL_READ,
|
2003-03-02 19:17:41 +01:00
|
|
|
&table, &opened) == SP_OK)
|
2003-02-28 15:07:14 +01:00
|
|
|
ret= TRUE;
|
2003-03-02 19:17:41 +01:00
|
|
|
if (opened)
|
2003-04-27 17:35:54 +02:00
|
|
|
close_thread_tables(thd, 0, 1);
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_RETURN(ret);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-07 14:55:10 +02:00
|
|
|
byte *
|
|
|
|
sp_lex_spfuns_key(const byte *ptr, uint *plen, my_bool first)
|
|
|
|
{
|
|
|
|
LEX_STRING *lsp= (LEX_STRING *)ptr;
|
|
|
|
*plen= lsp->length;
|
|
|
|
return (byte *)lsp->str;
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-03-02 19:17:41 +01:00
|
|
|
void
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_add_fun_to_lex(LEX *lex, sp_name *fun)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2004-02-17 17:36:53 +01:00
|
|
|
if (! hash_search(&lex->spfuns,
|
2004-03-11 17:18:59 +01:00
|
|
|
(byte *)fun->m_qname.str, fun->m_qname.length))
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2003-07-07 14:55:10 +02:00
|
|
|
LEX_STRING *ls= (LEX_STRING *)sql_alloc(sizeof(LEX_STRING));
|
2004-03-11 17:18:59 +01:00
|
|
|
ls->str= sql_strmake(fun->m_qname.str, fun->m_qname.length);
|
|
|
|
ls->length= fun->m_qname.length;
|
2003-04-04 15:47:43 +02:00
|
|
|
|
2003-09-24 15:26:20 +02:00
|
|
|
my_hash_insert(&lex->spfuns, (byte *)ls);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-03-02 19:17:41 +01:00
|
|
|
void
|
|
|
|
sp_merge_funs(LEX *dst, LEX *src)
|
|
|
|
{
|
2003-07-07 14:55:10 +02:00
|
|
|
for (uint i=0 ; i < src->spfuns.records ; i++)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2003-07-07 14:55:10 +02:00
|
|
|
LEX_STRING *ls= (LEX_STRING *)hash_element(&src->spfuns, i);
|
2003-03-02 19:17:41 +01:00
|
|
|
|
2003-07-07 14:55:10 +02:00
|
|
|
if (! hash_search(&dst->spfuns, (byte *)ls->str, ls->length))
|
2003-09-24 15:26:20 +02:00
|
|
|
my_hash_insert(&dst->spfuns, (byte *)ls);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-03-02 19:17:41 +01:00
|
|
|
int
|
|
|
|
sp_cache_functions(THD *thd, LEX *lex)
|
|
|
|
{
|
2003-07-07 14:55:10 +02:00
|
|
|
HASH *h= &lex->spfuns;
|
2003-03-02 19:17:41 +01:00
|
|
|
int ret= 0;
|
|
|
|
|
2003-07-07 14:55:10 +02:00
|
|
|
for (uint i=0 ; i < h->records ; i++)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2003-07-07 14:55:10 +02:00
|
|
|
LEX_STRING *ls= (LEX_STRING *)hash_element(h, i);
|
2004-02-17 17:36:53 +01:00
|
|
|
sp_name name(*ls);
|
2003-07-01 18:14:24 +02:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
name.m_qname= *ls;
|
2004-02-17 17:36:53 +01:00
|
|
|
if (! sp_cache_lookup(&thd->sp_func_cache, &name))
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2003-07-07 14:55:10 +02:00
|
|
|
sp_head *sp;
|
|
|
|
LEX *oldlex= thd->lex;
|
|
|
|
LEX *newlex= new st_lex;
|
|
|
|
|
|
|
|
thd->lex= newlex;
|
2004-03-11 17:18:59 +01:00
|
|
|
name.m_name.str= strchr(name.m_qname.str, '.');
|
|
|
|
name.m_db.length= name.m_name.str - name.m_qname.str;
|
|
|
|
name.m_db.str= strmake_root(&thd->mem_root,
|
|
|
|
name.m_qname.str, name.m_db.length);
|
|
|
|
name.m_name.str+= 1;
|
|
|
|
name.m_name.length= name.m_qname.length - name.m_db.length - 1;
|
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
if (db_find_routine(thd, TYPE_ENUM_FUNCTION, &name, &sp)
|
|
|
|
== SP_OK)
|
2003-07-07 14:55:10 +02:00
|
|
|
{
|
|
|
|
ret= sp_cache_functions(thd, newlex);
|
|
|
|
delete newlex;
|
|
|
|
thd->lex= oldlex;
|
|
|
|
if (ret)
|
|
|
|
break;
|
2003-10-21 12:08:35 +02:00
|
|
|
sp_cache_insert(&thd->sp_func_cache, sp);
|
2003-07-07 14:55:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete newlex;
|
|
|
|
thd->lex= oldlex;
|
|
|
|
net_printf(thd, ER_SP_DOES_NOT_EXIST, "FUNCTION", ls->str);
|
|
|
|
ret= 1;
|
2003-03-02 19:17:41 +01:00
|
|
|
break;
|
2003-07-07 14:55:10 +02:00
|
|
|
}
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
|
|
|
}
|
2003-02-28 15:07:14 +01:00
|
|
|
return ret;
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
2003-12-12 14:05:29 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
static char *
|
|
|
|
create_string(THD *thd, ulong *lenp,
|
|
|
|
int type,
|
2004-03-11 17:18:59 +01:00
|
|
|
sp_name *name,
|
2003-12-12 14:05:29 +01:00
|
|
|
const char *params, ulong paramslen,
|
|
|
|
const char *returns, ulong returnslen,
|
|
|
|
const char *body, ulong bodylen,
|
|
|
|
st_sp_chistics *chistics)
|
|
|
|
{
|
|
|
|
char *buf, *ptr;
|
2003-12-21 01:07:45 +01:00
|
|
|
ulong buflen;
|
2003-12-12 14:05:29 +01:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
buflen= 100 + name->m_qname.length + paramslen + returnslen + bodylen +
|
2004-02-17 17:36:53 +01:00
|
|
|
chistics->comment.length;
|
2003-12-21 11:48:03 +01:00
|
|
|
if (!(buf= thd->alloc(buflen)))
|
|
|
|
return 0;
|
|
|
|
|
2004-02-17 17:36:53 +01:00
|
|
|
ptr= strxmov(buf, "CREATE ",
|
|
|
|
(type == TYPE_ENUM_FUNCTION) ? "FUNCTION" : "PROCEDURE",
|
2004-03-11 17:18:59 +01:00
|
|
|
" `", name->m_db.str, "`.`", name->m_name.str, "`(", params, ")",
|
|
|
|
NullS);
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if (type == TYPE_ENUM_FUNCTION)
|
2003-12-21 11:48:03 +01:00
|
|
|
ptr= strxmov(ptr, " RETURNS ", returns, NullS);
|
|
|
|
*ptr++= '\n';
|
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if (chistics->detistic)
|
2003-12-21 01:07:45 +01:00
|
|
|
ptr= strmov(ptr, " DETERMINISTIC\n");
|
2003-12-12 14:05:29 +01:00
|
|
|
if (chistics->suid == IS_NOT_SUID)
|
2003-12-21 01:07:45 +01:00
|
|
|
ptr= strmov(ptr, " SQL SECURITY INVOKER\n");
|
2003-12-13 16:40:52 +01:00
|
|
|
if (chistics->comment.length)
|
2003-12-21 01:07:45 +01:00
|
|
|
{
|
|
|
|
ptr= strmov(strnmov(strmov(ptr, " COMMENT '"),chistics->comment.str,
|
|
|
|
chistics->comment.length),"'\n");
|
|
|
|
}
|
|
|
|
ptr= strmov(ptr, body);
|
|
|
|
*lenp= (ptr-buf);
|
2003-12-12 14:05:29 +01:00
|
|
|
return buf;
|
|
|
|
}
|
2004-03-11 17:18:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Utilities...
|
|
|
|
//
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_use_new_db(THD *thd, char *newdb, char *olddb, uint olddblen,
|
2004-06-08 18:41:18 +02:00
|
|
|
bool no_access_check, bool *dbchangedp)
|
2004-03-11 17:18:59 +01:00
|
|
|
{
|
|
|
|
bool changeit;
|
|
|
|
DBUG_ENTER("sp_use_new_db");
|
|
|
|
DBUG_PRINT("enter", ("newdb: %s", newdb));
|
|
|
|
|
|
|
|
if (thd->db && thd->db[0])
|
|
|
|
{
|
|
|
|
if (my_strcasecmp(system_charset_info, thd->db, newdb) == 0)
|
|
|
|
changeit= 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
changeit= 1;
|
|
|
|
strnmov(olddb, thd->db, olddblen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // thd->db empty
|
|
|
|
if (newdb[0])
|
|
|
|
changeit= 1;
|
|
|
|
else
|
|
|
|
changeit= 0;
|
|
|
|
olddb[0] = '\0';
|
|
|
|
}
|
|
|
|
if (!changeit)
|
|
|
|
{
|
2004-06-08 18:41:18 +02:00
|
|
|
*dbchangedp= FALSE;
|
2004-03-11 17:18:59 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ret= sp_change_db(thd, newdb, no_access_check);
|
|
|
|
|
2004-06-08 18:41:18 +02:00
|
|
|
if (! ret)
|
|
|
|
*dbchangedp= TRUE;
|
2004-03-11 17:18:59 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-19 19:01:54 +01:00
|
|
|
/*
|
|
|
|
Change database.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_change_db()
|
|
|
|
thd Thread handler
|
|
|
|
name Database name
|
|
|
|
empty_is_ok True= it's ok with "" as name
|
|
|
|
no_access_check True= don't do access check
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This is the same as mysql_change_db(), but with some extra
|
|
|
|
arguments for Stored Procedure usage; doing implicit "use"
|
|
|
|
when executing an SP in a different database.
|
|
|
|
We also use different error routines, since this might be
|
|
|
|
invoked from a function when executing a query or statement.
|
|
|
|
Note: We would have prefered to reuse mysql_change_db(), but
|
|
|
|
the error handling in particular made that too awkward, so
|
|
|
|
we (reluctantly) have a "copy" here.
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
0 ok
|
|
|
|
1 error
|
|
|
|
*/
|
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
int
|
2004-03-19 19:01:54 +01:00
|
|
|
sp_change_db(THD *thd, char *name, bool no_access_check)
|
2004-03-11 17:18:59 +01:00
|
|
|
{
|
2004-03-19 19:01:54 +01:00
|
|
|
int length, db_length;
|
|
|
|
char *dbname=my_strdup((char*) name,MYF(MY_WME));
|
|
|
|
char path[FN_REFLEN];
|
|
|
|
ulong db_access;
|
|
|
|
HA_CREATE_INFO create;
|
2004-03-11 17:18:59 +01:00
|
|
|
DBUG_ENTER("sp_change_db");
|
2004-03-19 19:01:54 +01:00
|
|
|
DBUG_PRINT("enter", ("db: %s, no_access_check: %d", name, no_access_check));
|
2004-03-11 17:18:59 +01:00
|
|
|
|
2004-03-19 19:01:54 +01:00
|
|
|
db_length= (!dbname ? 0 : strip_sp(dbname));
|
|
|
|
if (dbname && db_length)
|
|
|
|
{
|
|
|
|
if ((db_length > NAME_LEN) || check_db_name(dbname))
|
|
|
|
{
|
|
|
|
my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), dbname);
|
|
|
|
x_free(dbname);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
}
|
2004-03-11 17:18:59 +01:00
|
|
|
|
2004-03-19 19:01:54 +01:00
|
|
|
if (dbname && db_length)
|
|
|
|
{
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
if (! no_access_check)
|
|
|
|
{
|
|
|
|
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)))
|
|
|
|
{
|
|
|
|
my_printf_error(ER_DBACCESS_DENIED_ERROR, ER(ER_DBACCESS_DENIED_ERROR),
|
|
|
|
MYF(0),
|
|
|
|
thd->priv_user,
|
|
|
|
thd->priv_host,
|
|
|
|
dbname);
|
|
|
|
mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
|
|
|
|
thd->priv_user,
|
|
|
|
thd->priv_host,
|
|
|
|
dbname);
|
|
|
|
my_free(dbname,MYF(0));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
(void) sprintf(path,"%s/%s",mysql_data_home,dbname);
|
|
|
|
length=unpack_dirname(path,path); // Convert if not unix
|
|
|
|
if (length && path[length-1] == FN_LIBCHAR)
|
|
|
|
path[length-1]=0; // remove ending '\'
|
|
|
|
if (access(path,F_OK))
|
|
|
|
{
|
|
|
|
my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), dbname);
|
|
|
|
my_free(dbname,MYF(0));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x_free(thd->db);
|
|
|
|
thd->db=dbname; // THD::~THD will free this
|
|
|
|
thd->db_length=db_length;
|
|
|
|
|
|
|
|
if (dbname && db_length)
|
|
|
|
{
|
|
|
|
strmov(path+unpack_dirname(path,path), MY_DB_OPT_FILE);
|
|
|
|
load_db_opt(thd, path, &create);
|
|
|
|
thd->db_charset= create.default_table_charset ?
|
|
|
|
create.default_table_charset :
|
|
|
|
thd->variables.collation_server;
|
|
|
|
thd->variables.collation_database= thd->db_charset;
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
2004-03-11 17:18:59 +01:00
|
|
|
}
|