diff options
author | unknown <pem@mysql.comhem.se> | 2004-03-11 17:18:59 +0100 |
---|---|---|
committer | unknown <pem@mysql.comhem.se> | 2004-03-11 17:18:59 +0100 |
commit | eb4aa092e5648cc950ff8a6e3e5acbe296ae8fa7 (patch) | |
tree | 2a790442a0c109f0f5eabc6530c71782c2104c30 /sql/sp_head.cc | |
parent | 5aa57221d8b40a0b5146c9af027cdd2dc15af737 (diff) | |
download | mariadb-git-eb4aa092e5648cc950ff8a6e3e5acbe296ae8fa7.tar.gz |
WL#1366: Use the schema (db) associated with an SP.
Phase 2: Make SPs belong to a DB, and use qualified names.
As a side effect, using USE in an SP is no longer allowed.
(It just doesn't work otherwise.)
include/mysqld_error.h:
New error code (USE is no longer allowed in a stored procedure).
include/sql_state.h:
New error state (USE is no longer allowed in a stored procedure).
mysql-test/r/sp-error.result:
Updated result for test of USE in SP (not allowed now).
mysql-test/r/sp-security.result:
Updated test results for new db column and qualified procedured names.
mysql-test/r/sp.result:
Updated results for USE in SP (as it's no longer allowed), and
for new db column in status result.
mysql-test/t/sp-error.test:
Moved test of USE in SP from sp.test (as it's no longer allowed).
mysql-test/t/sp-security.test:
Ajusted tests for new db column and qualified procedured names.
mysql-test/t/sp.test:
Moved test of USE in SP to sp-error.test (as it's no longer allowed).
Adjusted tests for new db column in status result.
sql/mysql_priv.h:
mysql_change_db() now has optional arguments for use by SP with qualified names.
sql/share/czech/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/danish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/dutch/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/english/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/estonian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/french/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/german/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/greek/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/hungarian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/italian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/japanese/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/korean/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/norwegian-ny/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/norwegian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/polish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/portuguese/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/romanian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/russian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/serbian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/slovak/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/spanish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/swedish/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/share/ukrainian/errmsg.txt:
New error message: USE is not allowed in a stored procedure.
sql/sp.cc:
SPs are now "belong" to a DB and may have qualified names.
New functions for changing DB ("use") when parsing and invoking SPs.
sql/sp.h:
New functions for changing DB ("use") when parsing and invoking SPs.
sql/sp_cache.cc:
Use the qualified name in the SP cache.
sql/sp_head.cc:
New function for allocating a qualified SP name (used in sql_yacc.yy).
Change DB when executing an SP (if needed).
Moved thd_mem_root swap functions from sp_head.h.
sql/sp_head.h:
New function for allocating a qualified SP name (used in sql_yacc.yy).
Moved thd_mem_root swap functions to sp_head.cc.
sql/sql_db.cc:
mysql_change_db() now has optional arguments for use by SP with qualified names
(for use when reading an SP from database and executing it); also allow "unusing"
a database, i.e. setting thd->thd to "".
sql/sql_yacc.yy:
Initialize qualfied SP names correctly.
USE is no longer allowed in an SP.
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r-- | sql/sp_head.cc | 85 |
1 files changed, 58 insertions, 27 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc index eebe02c1834..ebf74e25bbe 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -147,6 +147,26 @@ sp_name::init_qname(THD *thd) m_name.length, m_name.str); } +sp_name * +sp_name_current_db_new(THD *thd, LEX_STRING name) +{ + sp_name *qname; + + if (! thd->db) + qname= new sp_name(name); + else + { + LEX_STRING db; + + db.length= strlen(thd->db); + db.str= thd->strmake(thd->db, db.length); + qname= new sp_name(db, name); + } + qname->init_qname(thd); + return qname; +} + + /* ------------------------------------------------------------------ */ @@ -224,8 +244,8 @@ sp_head::init_strings(THD *thd, LEX *lex, sp_name *name) /* We have to copy strings to get them into the right memroot */ if (name->m_db.length == 0) { - m_db.length= strlen(thd->db); - m_db.str= strmake_root(root, thd->db, m_db.length); + m_db.length= (thd->db ? strlen(thd->db) : 0); + m_db.str= strmake_root(root, (thd->db ? thd->db : ""), m_db.length); } else { @@ -317,30 +337,22 @@ int sp_head::execute(THD *thd) { DBUG_ENTER("sp_head::execute"); - char olddbname[128]; - char *olddbptr= thd->db; + char olddb[128]; + char *olddbptr; sp_rcontext *ctx= thd->spcont; int ret= 0; uint ip= 0; #ifndef EMBEDDED_LIBRARY - if (check_stack_overrun(thd, olddbptr)) + if (check_stack_overrun(thd, olddb)) { DBUG_RETURN(-1); } #endif - if (olddbptr) - { - uint i= 0; - char *p= olddbptr; - - /* Fast inline strncpy without padding... */ - while (*p && i < sizeof(olddbname)) - olddbname[i++]= *p++; - if (i == sizeof(olddbname)) - i-= 1; // QQ Error or warning for truncate? - olddbname[i]= '\0'; - } + + olddbptr= thd->db; + if ((ret= sp_use_new_db(thd, m_db.str, olddb, sizeof(olddb), 0))) + goto done; if (ctx) ctx->clear_handler(); @@ -379,18 +391,17 @@ sp_head::execute(THD *thd) } } while (ret == 0 && !thd->killed && !thd->query_error); + done: DBUG_PRINT("info", ("ret=%d killed=%d query_error=%d", ret, thd->killed, thd->query_error)); if (thd->killed || thd->query_error) ret= -1; /* If the DB has changed, the pointer has changed too, but the original thd->db will then have been freed */ - if (olddbptr && olddbptr != thd->db) + if (olddbptr != thd->db) { - /* QQ Maybe we should issue some special error message or warning here, - if this fails?? */ if (! thd->killed) - ret= mysql_change_db(thd, olddbname); + ret= sp_change_db(thd, olddb, 0); } DBUG_RETURN(ret); } @@ -757,6 +768,32 @@ sp_head::set_info(char *definer, uint definerlen, m_chistics->comment.length); } +void +sp_head::reset_thd_mem_root(THD *thd) +{ + m_thd_root= thd->mem_root; + thd->mem_root= m_mem_root; + m_free_list= thd->free_list; // Keep the old list + thd->free_list= NULL; // Start a new one + /* Copy the db, since substatements will point to it */ + m_thd_db= thd->db; + thd->db= strmake_root(&thd->mem_root, thd->db, thd->db_length); + m_thd= thd; +} + +void +sp_head::restore_thd_mem_root(THD *thd) +{ + Item *flist= m_free_list; // The old list + m_free_list= thd->free_list; // Get the new one + thd->free_list= flist; // Restore the old one + thd->db= m_thd_db; // Restore the original db pointer + m_mem_root= thd->mem_root; + thd->mem_root= m_thd_root; + m_thd= NULL; +} + + int sp_head::show_create_procedure(THD *thd) { @@ -1157,8 +1194,6 @@ sp_change_security_context(THD *thd, sp_head *sp, st_sp_security_context *ctxp) { ctxp->master_access= thd->master_access; ctxp->db_access= thd->db_access; - ctxp->db= thd->db; - ctxp->db_length= thd->db_length; ctxp->priv_user= thd->priv_user; strncpy(ctxp->priv_host, thd->priv_host, sizeof(ctxp->priv_host)); ctxp->user= thd->user; @@ -1174,8 +1209,6 @@ sp_change_security_context(THD *thd, sp_head *sp, st_sp_security_context *ctxp) ctxp->changed= FALSE; thd->master_access= ctxp->master_access; thd->db_access= ctxp->db_access; - thd->db= ctxp->db; - thd->db_length= ctxp->db_length; thd->priv_user= ctxp->priv_user; strncpy(thd->priv_host, ctxp->priv_host, sizeof(thd->priv_host)); } @@ -1195,8 +1228,6 @@ sp_restore_security_context(THD *thd, sp_head *sp, st_sp_security_context *ctxp) ctxp->changed= FALSE; thd->master_access= ctxp->master_access; thd->db_access= ctxp->db_access; - thd->db= ctxp->db; - thd->db_length= ctxp->db_length; thd->priv_user= ctxp->priv_user; strncpy(thd->priv_host, ctxp->priv_host, sizeof(thd->priv_host)); } |