diff options
author | unknown <pem@mysql.telia.com> | 2003-09-16 14:26:08 +0200 |
---|---|---|
committer | unknown <pem@mysql.telia.com> | 2003-09-16 14:26:08 +0200 |
commit | 4deedf6263df02229a30a0aa2f6621074f140b19 (patch) | |
tree | dccbb3bbe8e061d9d2956a24883ae6f2b5002f9e /sql/sp_rcontext.h | |
parent | e68197450d5f42f1b07138248fff46455190ebce (diff) | |
download | mariadb-git-4deedf6263df02229a30a0aa2f6621074f140b19.tar.gz |
Implemented SP CONDITIONs and HANDLERs, with the extension of handling
MySQL error codes as well.
(No UNDO HANDLERs yet, and no SIGNAL or RESIGNAL.)
WL#850
Docs/sp-imp-spec.txt:
Spec of CONDITIONs and HANDLERs (and updated some old stuff too).
Docs/sp-implemented.txt:
Updated info about caching, CONDITIONs and HANDLERs.
include/mysqld_error.h:
New error for undeclared CONDITION.
libmysqld/Makefile.am:
New file: sp_rcontext.cc.
mysql-test/r/sp-error.result:
New tests for CONDITIONs and HANDLERs.
mysql-test/r/sp.result:
New tests for CONDITIONs and HANDLERs.
mysql-test/t/sp-error.test:
New tests for CONDITIONs and HANDLERs.
mysql-test/t/sp.test:
New tests for CONDITIONs and HANDLERs.
sql/Makefile.am:
New file: sp_rcontext.cc.
sql/lex.h:
New symbols for CONDITIONs, HANDLERs and CURSORs.
sql/mysqld.cc:
Catch error if we have a handler for it.
sql/protocol.cc:
Catch error if we have a handler for it.
sql/share/czech/errmsg.txt:
New error for undeclared CONDITION.
sql/share/danish/errmsg.txt:
New error for undeclared CONDITION.
sql/share/dutch/errmsg.txt:
New error for undeclared CONDITION.
sql/share/english/errmsg.txt:
New error for undeclared CONDITION.
sql/share/estonian/errmsg.txt:
New error for undeclared CONDITION.
sql/share/french/errmsg.txt:
New error for undeclared CONDITION.
sql/share/german/errmsg.txt:
New error for undeclared CONDITION.
sql/share/greek/errmsg.txt:
New error for undeclared CONDITION.
sql/share/hungarian/errmsg.txt:
New error for undeclared CONDITION.
sql/share/italian/errmsg.txt:
New error for undeclared CONDITION.
sql/share/japanese/errmsg.txt:
New error for undeclared CONDITION.
sql/share/korean/errmsg.txt:
New error for undeclared CONDITION.
sql/share/norwegian-ny/errmsg.txt:
New error for undeclared CONDITION.
sql/share/norwegian/errmsg.txt:
New error for undeclared CONDITION.
sql/share/polish/errmsg.txt:
New error for undeclared CONDITION.
sql/share/portuguese/errmsg.txt:
New error for undeclared CONDITION.
sql/share/romanian/errmsg.txt:
New error for undeclared CONDITION.
sql/share/russian/errmsg.txt:
New error for undeclared CONDITION.
sql/share/serbian/errmsg.txt:
New error for undeclared CONDITION.
sql/share/slovak/errmsg.txt:
New error for undeclared CONDITION.
sql/share/spanish/errmsg.txt:
New error for undeclared CONDITION.
sql/share/swedish/errmsg.txt:
New error for undeclared CONDITION.
sql/share/ukrainian/errmsg.txt:
New error for undeclared CONDITION.
sql/sp_head.cc:
New HANDLER code.
sql/sp_head.h:
New HANDLER code.
sql/sp_pcontext.cc:
New CONDITION and HANDLER code.
sql/sp_pcontext.h:
New CONDITION and HANDLER code.
sql/sp_rcontext.h:
New CONDITION and HANDLER code.
sql/sql_yacc.yy:
New CONDITION and HANDLER code.
Diffstat (limited to 'sql/sp_rcontext.h')
-rw-r--r-- | sql/sp_rcontext.h | 97 |
1 files changed, 89 insertions, 8 deletions
diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index 78485fdd090..fe954ed0d94 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -18,6 +18,25 @@ #ifndef _SP_RCONTEXT_H_ #define _SP_RCONTEXT_H_ +#ifdef __GNUC__ +#pragma interface /* gcc class implementation */ +#endif + +struct sp_cond_type; + +#define SP_HANDLER_NONE 0 +#define SP_HANDLER_EXIT 1 +#define SP_HANDLER_CONTINUE 2 +#define SP_HANDLER_UNDO 3 + +typedef struct +{ + struct sp_cond_type *cond; + uint handler; // Location of handler + int type; + uint foffset; // Frame offset for the handlers declare level +} sp_handler_t; + class sp_rcontext : public Sql_alloc { sp_rcontext(const sp_rcontext &); /* Prevent use of these */ @@ -25,23 +44,19 @@ class sp_rcontext : public Sql_alloc public: - sp_rcontext(uint size) - : m_count(0), m_size(size), m_result(NULL) - { - m_frame = (Item **)sql_alloc(size * sizeof(Item*)); - m_outs = (int *)sql_alloc(size * sizeof(int)); - } + sp_rcontext(uint fsize, uint hmax); ~sp_rcontext() { // Not needed? //sql_element_free(m_frame); + //m_saved.empty(); } inline void push_item(Item *i) { - if (m_count < m_size) + if (m_count < m_fsize) m_frame[m_count++] = i; } @@ -82,13 +97,79 @@ class sp_rcontext : public Sql_alloc return m_result; } + inline void + push_handler(struct sp_cond_type *cond, uint h, int type, uint f) + { + m_handler[m_hcount].cond= cond; + m_handler[m_hcount].handler= h; + m_handler[m_hcount].type= type; + m_handler[m_hcount].foffset= f; + m_hcount+= 1; + } + + inline void + pop_handlers(uint count) + { + m_hcount-= count; + } + + // Returns 1 if a handler was found, 0 otherwise. + int + find_handler(uint sql_errno); + + // Returns handler type and sets *ip to location if one was found + inline int + found_handler(uint *ip, uint *fp) + { + if (m_hfound < 0) + return SP_HANDLER_NONE; + *ip= m_handler[m_hfound].handler; + *fp= m_handler[m_hfound].foffset; + return m_handler[m_hfound].type; + } + + // Clears the handler find state + inline void + clear_handler() + { + m_hfound= -1; + } + + inline void + push_hstack(uint h) + { + m_hstack[m_hsp++]= h; + } + + inline uint + pop_hstack() + { + return m_hstack[--m_hsp]; + } + + // Save variables starting at fp and up + void + save_variables(uint fp); + + // Restore variables down to fp + void + restore_variables(uint fp); + private: uint m_count; - uint m_size; + uint m_fsize; Item **m_frame; int *m_outs; Item *m_result; // For FUNCTIONs + sp_handler_t *m_handler; + uint m_hcount; + uint *m_hstack; + uint m_hsp; + + int m_hfound; // Set by find_handler; -1 if not found + + List<Item> m_saved; // Saved variables }; // class sp_rcontext : public Sql_alloc |