summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xBitKeeper/triggers/post-commit19
-rw-r--r--Docs/sp-imp-spec.txt501
-rw-r--r--Docs/sp-implemented.txt80
-rw-r--r--client/mysql.cc46
-rw-r--r--client/mysqltest.c27
-rw-r--r--configure.in2
-rw-r--r--include/mysqld_error.h13
-rw-r--r--libmysqld/Makefile.am3
-rw-r--r--mysql-test/install_test_db.sh14
-rw-r--r--mysql-test/r/connect.result3
-rw-r--r--mysql-test/r/insert.result13
-rw-r--r--mysql-test/r/sp.result300
-rw-r--r--mysql-test/r/subselect.result3
-rw-r--r--mysql-test/t/insert.test31
-rw-r--r--mysql-test/t/sp.test333
-rw-r--r--mysql-test/t/subselect.test1
-rw-r--r--scripts/mysql_install_db.sh13
-rw-r--r--sql/Makefile.am6
-rw-r--r--sql/item.cc19
-rw-r--r--sql/item.h53
-rw-r--r--sql/lex.h17
-rw-r--r--sql/mysql_priv.h2
-rw-r--r--sql/share/czech/errmsg.txt12
-rw-r--r--sql/share/danish/errmsg.txt12
-rw-r--r--sql/share/dutch/errmsg.txt12
-rw-r--r--sql/share/english/errmsg.txt12
-rw-r--r--sql/share/estonian/errmsg.txt12
-rw-r--r--sql/share/french/errmsg.txt12
-rw-r--r--sql/share/german/errmsg.txt12
-rw-r--r--sql/share/greek/errmsg.txt12
-rw-r--r--sql/share/hungarian/errmsg.txt12
-rw-r--r--sql/share/italian/errmsg.txt12
-rw-r--r--sql/share/japanese/errmsg.txt12
-rw-r--r--sql/share/korean/errmsg.txt12
-rw-r--r--sql/share/norwegian-ny/errmsg.txt12
-rw-r--r--sql/share/norwegian/errmsg.txt12
-rw-r--r--sql/share/polish/errmsg.txt12
-rw-r--r--sql/share/portuguese/errmsg.txt12
-rw-r--r--sql/share/romanian/errmsg.txt12
-rw-r--r--sql/share/russian/errmsg.txt12
-rw-r--r--sql/share/serbian/errmsg.txt12
-rw-r--r--sql/share/slovak/errmsg.txt12
-rw-r--r--sql/share/spanish/errmsg.txt12
-rw-r--r--sql/share/swedish/errmsg.txt12
-rw-r--r--sql/share/ukrainian/errmsg.txt12
-rw-r--r--sql/sp.cc125
-rw-r--r--sql/sp.h44
-rw-r--r--sql/sp_head.cc422
-rw-r--r--sql/sp_head.h306
-rw-r--r--sql/sp_pcontext.cc120
-rw-r--r--sql/sp_pcontext.h155
-rw-r--r--sql/sp_rcontext.h82
-rw-r--r--sql/sql_class.cc52
-rw-r--r--sql/sql_class.h15
-rw-r--r--sql/sql_lex.cc3
-rw-r--r--sql/sql_lex.h8
-rw-r--r--sql/sql_parse.cc141
-rw-r--r--sql/sql_yacc.yy560
58 files changed, 3702 insertions, 106 deletions
diff --git a/BitKeeper/triggers/post-commit b/BitKeeper/triggers/post-commit
index a2a0ecb2701..83c6195154f 100755
--- a/BitKeeper/triggers/post-commit
+++ b/BitKeeper/triggers/post-commit
@@ -6,6 +6,7 @@ FROM=$USER@mysql.com
INTERNALS=internals@lists.mysql.com
DOCS=docs-commit@mysql.com
LIMIT=10000
+REPOV=5.0
if [ "$REAL_EMAIL" = "" ]
then
@@ -27,15 +28,15 @@ CHANGESET=`bk -R prs -r+ -h -d':I:' ChangeSet`
echo "Commit successful, notifying developers at $TO"
(
cat <<EOF
-List-ID: <bk.mysql-4.1>
+List-ID: <bk.mysql-$REPOV>
From: $FROM
To: $TO
-Subject: bk commit - 4.1 tree ($CHANGESET)
+Subject: bk commit - $REPOV tree ($CHANGESET)
EOF
bk changes -v -r+
bk cset -r+ -d
- ) | head -n $LIMIT | /usr/sbin/sendmail -t
+ ) | /usr/sbin/sendmail -t
#++
# internals@ mail
@@ -43,13 +44,13 @@ EOF
echo "Notifying internals list at $INTERNALS"
(
cat <<EOF
-List-ID: <bk.mysql-4.1>
+List-ID: <bk.mysql-$REPOV>
From: $FROM
To: $INTERNALS
-Subject: bk commit into 4.1 tree ($CHANGESET)
+Subject: bk commit into $REPOV tree ($CHANGESET)
Below is the list of changes that have just been committed into a local
-4.1 repository of $USER. When $USER does a push these changes will
+$REPOV repository of $USER. When $USER does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
@@ -70,15 +71,15 @@ EOF
echo "Notifying docs list at $DOCS"
(
cat <<EOF
-List-ID: <bk.mysql-4.1>
+List-ID: <bk.mysql-$REPOV>
From: $FROM
To: $DOCS
-Subject: bk commit - 4.1 tree (Manual) ($CHANGESET)
+Subject: bk commit - $REPOV tree (Manual) ($CHANGESET)
EOF
bk changes -v -r+
bk cset -r+ -d
- ) | head -n $LIMIT | /usr/sbin/sendmail -t
+ ) | /usr/sbin/sendmail -t
fi
else
diff --git a/Docs/sp-imp-spec.txt b/Docs/sp-imp-spec.txt
new file mode 100644
index 00000000000..198623a0f5b
--- /dev/null
+++ b/Docs/sp-imp-spec.txt
@@ -0,0 +1,501 @@
+
+ Implementation specification for Stored Procedures
+ ==================================================
+
+This is a first draft, only covering the basics for parsing, creating, and
+calling a PROCEDURE.
+
+
+- How parsing and execution of queries work
+
+ In order to execute a query, the function sql_parse.cc:mysql_parse() is
+ called, which in turn calls the parser (yyparse()) with an updated Lex
+ structure as the result. mysql_parse() then calls mysql_execute_command()
+ which dispatches on the command code (in Lex) to the corresponding code for
+ executing that particular query.
+
+ There are thre structures involved in the execution of a query which are of
+ interest to the stored procedure implementation:
+
+ - Lex (mentioned above) is the "compiled" query, that is the output from
+ the parser and what is then interpreted to do the actual work.
+ It constains an enum value (sql_command) which is the query type, and
+ all the data collected by the parser needed for the execution (table
+ names, fields, values, etc).
+ - THD is the "run-time" state of a connection, containing all that is
+ needed for a particular client connection, and, among other things, the
+ Lex structure currently being executed.
+ - Item_*: During parsing, all data is translated into "items", objects of
+ the subclasses of "Item", such as Item_int, Item_real, Item_string, etc,
+ for basic datatypes, and also various more specialized Item types for
+ expressions to be evaluated (Item_func objects).
+
+
+- How to fit Stored Procedure into this scheme
+
+ - An overview of the classes and files for stored procedures
+ (More detailed APIs at the end of this file)
+
+ - class sp_head (sp_head.{cc,h})
+ This contains, among other things, an array of "instructions" and the
+ method for executing the procedure.
+
+ - class sp_pcontext (sp_pcontext.{cc,h}
+ This is the parse context for the procedure. It's primarily used during
+ parsing to keep track of local parameters, variables and labels, but
+ it's also used at CALL time do find parameters mode (IN, OUT or INOUT)
+ and type when setting up the runtime context.
+
+ - class sp_instr (sp_head.{cc,h})
+ This is the base class for "instructions", that is, what is generated
+ by the parser. It turns out that we only need 4 different sub classes:
+ - sp_instr_stmt
+ Execute a statement. This is the "call-out" any normal SQL statement,
+ like a SELECT, INSERT etc. It contains the Lex structure for the
+ statement in question.
+ - sp_instr_set
+ Set the value of a local variable (or parameter)
+ - sp_instr_jump
+ An unconditional jump.
+ - sp_instr_jump_if_not
+ Jump if condition is not true. It turns out that the negative test is
+ most convenient when generating the code for the flow control
+ constructs.
+
+ - class sp_rcontext (sp_rcontext.h)
+ This is the runtime context in the THD structure.
+ It contains an array of items, the parameters and local variables for
+ the currently executing stored procedure.
+ This means that variable value lookup is in runtime is constant time,
+ a simple index operation.
+
+ - class Item_splocal (Item.{cc,h})
+ This is a subclass of Item. Its sole purpose is to hide the fact that
+ the real Item is actually in the current frame (runtime context).
+ It contains the frame offset and defers all methods to the real Item
+ in the frame. This is what the parser generates for local variables.
+
+ - Utility functions (sp.{cc,h})
+ This contains functions for creating, dropping and finding a stored
+ procedure in the mysql.proc table (or internal cache, when it is
+ implemented).
+
+
+ - Parsing CREATE PROCEDURE ...
+
+ When parsing a CREATE PROCEDURE the parser first initializes the
+ sphead and spcont (runtime context) fields in the Lex.
+ The sql_command code for the result of parsing a is
+ SQLCOM_CREATE_PROCEDURE.
+
+ The parsing of the parameter list and body is relatively
+ straight-forward:
+
+ - Parameters:
+ name, type and mode (IN/OUT/INOUT) is pushed to spcont
+ - Declared local variables:
+ Same as parameters (mode is then IN)
+ - Local Variable references:
+ If an identifier is found in in spcont, an Item_splocal is created
+ with the variable's frame index, otherwise an Item_field or Item_ref
+ is created (as before).
+ - Statements:
+ The Lex in THD is replaced by a new Lex structure and the statement,
+ is parsed as usual. A sp_instr_stmt is created, containing the new
+ Lex, and added to added to the instructions in sphead.
+ Afterwards, the procedure's Lex is restored in THD.
+ - SET var:
+ Setting a local variable generates a sp_instr_set instruction,
+ containing the variable's frame offset, the expression (an Item),
+ and the type.
+ - Flow control:
+ Flow control constructs like, IF, WHILE, etc, generate a conditional
+ and unconditional jumps in the "obvious" way, but a few notes may
+ be required:
+ - Forward jumps: When jumping forward, the exact destination is not
+ known at the time of the creation of the jump instruction. The
+ sphead therefore contains list of instruction-label pairs for
+ each forward reference. When the position later is known, the
+ instructions in the list are updated with the correct location.
+ - Loop constructs have optional labels. If a loop doesn't have a
+ label, an anonymous label is generated to simplify the parsing.
+ - There are two types of CASE. The "simple" case is implemented
+ with an anonymous variable bound to the value to be tested.
+
+
+ - An example
+
+ Parsing the procedure:
+
+ create procedure a(s char(16))
+ begin
+ declare x int;
+ set x = 3;
+ while x > 0 do
+ set x = x-1;
+ insert into db.tab values (x, s);
+ end while
+ end
+
+ would generate the following structures:
+ ______
+ thd: | | _________
+ | lex -+--->| | ___________________
+ |______| | spcont -+------------------->| "s",in,char(16):0 |
+ | sphead -+------ |("x",in,int :1)|
+ |_________| | |___________________|
+ ____V__________________
+ | m_name: "a" |
+ | m_defstr: "create ..."|
+ | m_instr: ... |
+ |_______________________|
+
+ Note that the contents of the spcont is changing during the parsing,
+ at all times reflecting the state of the would-be runtime frame.
+ The m_instr is an array of instructions:
+
+ Pos. Instruction
+ 0 sp_instr_set(1, '3')
+ 1 sp_instr_jump_if_not(5, 'x>0')
+ 2 sp_instr_set(1, 'x-1')
+ 3 sp_instr_stmt('insert into ...')
+ 4 sp_instr_jump(1)
+ 5 <end>
+
+ Here, '3', 'x>0', etc, represent the Items or Lex for the respective
+ expressions or statements.
+
+
+ - Parsing CREATE FUNCTION ...
+
+ Creating a functions is essensially the same thing as for a PROCEDURE,
+ with the addition that a FUNCTION has a return type and a RETURN
+ statement, but no OUT or INOUT parameters.
+
+ [QQ - More details here; sp_head needs a result slot and a type flag
+ indicating if it's a function or procedure]
+
+
+ - Storing, caching, dropping...
+
+ As seen above, the entired definition string, including the "CREATE
+ PROCEDURE" (or "FUNCTION") is kept. The procedure definition string is
+ stored in the table mysql.proc with the name and type as the key, the
+ type being one of the enum ("procedure","function").
+
+ A PROCEDURE is just stored int the mysql.proc table. A FUNCTION has an
+ additional requirement. They will be called in expressions with the same
+ syntax as UDFs, so UDFs and stored FUNCTIONs share the namespace. Thus,
+ we must make sure that we do not have UDFs and FUNCTIONs with the same
+ name (even if they are storded in different places).
+
+ This means that we can reparse the procedure as many time as we want.
+ The first time, the resulting Lex is used to store the procedure in
+ the database (using the function sp.c:sp_create_procedure()).
+
+ The simplest way would be to just leave it at that, and re-read the
+ procedure from the database each time it is called. (And in fact, that's
+ the way the earliest implementation will work.)
+ However, this is not very efficient, and we can do better. The full
+ implementation should work like this:
+
+ 1) Upon creation time, parse and store the procedure. Note that we still
+ need to parse it to catch syntax errors, but we can't check if called
+ procedures exists for instance.
+ 2) Upon first CALL, read from the database, parse it, and cache the
+ resulting Lex in memory. This time we can do more error checking.
+ 3) Upon subsequent CALLs, use the cached Lex.
+
+ Note that this implies that the Lex structure with its sphead must be
+ reentrant, that is, reusable and shareable between different threads
+ and calls. The runtime state for a procedure is kept in the sp_rcontext
+ in THD.
+
+ The mechanisms of storing, finding, and dropping procedures are
+ encapsulated in the files sp.{cc,h}.
+
+
+ - CALLing a procedure
+
+ A CALL is parsed just like any statement. The resulting Lex has the
+ sql_command SQLCOM_CALL, the procedure's name and the parameters are
+ pushed to the Lex' value_list.
+
+ sql_parse.cc:mysql_execute_command() then uses sp.cc:sp_find() to
+ get the sp_head for the procedure (which may have been read from the
+ database or feetched from the in-memory cache) and calls the sp_head's
+ method execute().
+ Note: It's important that substatements called by the procedure do not
+ do send_ok(). Fortunately, there is a flag in THD->net to disable
+ this during CALLs. If a substatement fails, it will however send
+ an error back to the client, so the CALL mechanism must return
+ immediately and without sending an error.
+
+ The sp_head::execute() method works as follows:
+
+ 1) Keep a pointer to the old runtime context in THD (if any)
+ 2) Create a new runtime context. The information about the required size
+ is in sp_head's parse time context.
+ 3) Push each parameter (from the CALL's Lex->value_list) to the new
+ context. If it's an OUT or INOUT parameter, the parameter's offset
+ in the caller's frame is set in the new context as well.
+ 4) For each instruction, call its execute() method.
+ The result is a pointer to the next instruction to execute (or NULL)
+ if an error occured.
+ 5) On success, set the new values of the OUT and INOUT parameters in
+ the caller's frame.
+
+
+ - Evaluating Items
+
+ There are three occasions where we need to evaluate an expression:
+
+ - When SETing a variable
+ - When CALLing a procedure
+ - When testing an expression for a branch (in IF, WHILE, etc)
+
+ The semantics in stored procedures is "call-by-value", so we have to
+ evaluate any "func" Items at the point of the CALL or SET, otherwise
+ we would get a kind of "lazy" evaluation with unexpected results with
+ respect to OUT parameters for instance.
+ For this the support function, sp_head.cc:eval_func_item() is needed.
+
+
+ - Calling a FUNCTION
+
+ Functions don't have an explicit call keyword like procedures. Instead,
+ they appear in expressions with the conventional syntax "fun(arg, ...)".
+ The problem is that we already have User Defined Functions (UDFs) which
+ are called the same way. A UDF is detected by the lexical analyzer (not
+ the parser!), in the find_keyword() function, and returns a UDF_*_FUNC
+ or UDA_*_SUM token with the udf_func object as the yylval.
+
+ So, stored functions must be handled in a simpilar way, and as a
+ consequence, UDFs and functions must not have the same name.
+
+ [QQ - Details of how function calls works here]
+
+
+ - Parsing DROP PROCEDURE/FUNCTION
+
+ The procedure name is pushed to Lex->value_list.
+ The sql_command code for the result of parsing a is
+ SQLCOM_DROP_PROCEDURE/SQLCOM_DROP_FUNCTION.
+
+ Dropping is done by simply getting the procedure with the sp_find()
+ function and calling sp_drop() (both in sp.{cc,h}).
+
+
+ - Class and function APIs
+
+ - The parser context: sp_pcontext.h
+
+ typedef enum
+ {
+ sp_param_in,
+ sp_param_out,
+ sp_param_inout
+ } sp_param_mode_t;
+
+ typedef struct
+ {
+ Item_string *name;
+ enum enum_field_types type;
+ sp_param_mode_t mode;
+ uint offset; // Offset in current frame
+ my_bool isset;
+ } sp_pvar_t;
+
+ class sp_pcontext
+ {
+ sp_pcontext();
+
+ // Return the maximum frame size
+ uint max_framesize();
+
+ // Return the current frame size
+ uint current_framesize();
+
+ // Return the number of parameters
+ uint params();
+
+ // Set the number of parameters to the current frame size
+ void set_params();
+
+ // Set type of the variable at offset 'i' in the frame
+ void set_type(uint i, enum enum_field_types type);
+
+ // Mark the i:th variable to "set" (i.e. having a value) with
+ // 'val' true.
+ void set_isset(uint i, my_bool val);
+
+ // Push the variable 'name' to the frame.
+ void push(LEX_STRING *name,
+ enum enum_field_types type, sp_param_mode_t mode);
+
+ // Pop 'num' variables from the frame.
+ void pop(uint num = 1);
+
+ // Find variable by name
+ sp_pvar_t *find_pvar(LEX_STRING *name);
+
+ // Find variable by index
+ sp_pvar_t *find_pvar(uint i);
+
+ // Push label 'name' of instruction index 'ip' to the label context
+ sp_label_t *push_label(char *name, uint ip);
+
+ // Find label 'name' in the context
+ sp_label_t *find_label(char *name);
+
+ // Return the last pushed label
+ sp_label_t *last_label();
+
+ // Return and remove the last pushed label.
+ sp_label_t *pop_label();
+ }
+
+
+ - The run-time context (call frame): sp_rcontext.h
+
+ class sp_rcontext
+ {
+ // 'size' is the max size of the context
+ sp_rcontext(uint size);
+
+ // Push value (parameter) 'i' to the frame
+ void push_item(Item *i);
+
+ // Set slot 'idx' to value 'i'
+ void set_item(uint idx, Item *i);
+
+ // Return the item in slot 'idx'
+ Item *get_item(uint idx);
+
+ // Set the "out" index 'oidx' for slot 'idx. If it's an IN slot,
+ // use 'oidx' -1.
+ void set_oindex(uint idx, int oidx);
+
+ // Return the "out" index for slot 'idx'
+ int get_oindex(uint idx);
+ }
+
+
+ - The procedure: sp_head.h
+
+ class sp_head
+ {
+ sp_head(LEX_STRING *name, LEX*);
+
+ // Store this procedure in the database. This is a wrapper around
+ // the function sp_create_procedure().
+ int create(THD *);
+
+ // CALL this procedure.
+ int execute(THD *);
+
+ // Add the instruction to this procedure.
+ void add_instr(sp_instr *);
+
+ // Return the number of instructions.
+ uint instructions();
+
+ // Resets lex in 'thd' and keeps a copy of the old one.
+ void reset_lex(THD *);
+
+ // Restores lex in 'thd' from our copy, but keeps some status from the
+ // one in 'thd', like ptr, tables, fields, etc.
+ void restore_lex(THD *);
+
+ // Put the instruction on the backpatch list, associated with
+ // the label.
+ void push_backpatch(sp_instr *, struct sp_label *);
+
+ // Update all instruction with this label in the backpatch list to
+ // the current position.
+ void backpatch(struct sp_label *);
+ }
+
+ - Instructions
+
+ - The base class:
+ class sp_instr
+ {
+ // 'ip' is the index of this instruction
+ sp_instr(uint ip);
+
+ // Execute this instrution.
+ // '*nextp' will be set to the index of the next instruction
+ // to execute. (For most instruction this will be the
+ // instruction following this one.)
+ // Returns 0 on success, non-zero if some error occured.
+ virtual int execute(THD *, uint *nextp)
+ }
+
+ - Statement instruction:
+ class sp_instr_stmt : public sp_instr
+ {
+ sp_instr_stmt(uint ip);
+
+ int execute(THD *, uint *nextp);
+
+ // Set the statement's Lex
+ void set_lex(LEX *);
+
+ // Return the statement's Lex
+ LEX *get_lex();
+ }
+
+ - SET instruction:
+ class sp_instr_set : public sp_instr
+ {
+ // 'offset' is the variable's frame offset, 'val' the value,
+ // and 'type' the variable type.
+ sp_instr_set(uint ip,
+ uint offset, Item *val, enum enum_field_types type);
+
+ int execute(THD *, uint *nextp);
+ }
+
+ - Unconditional jump
+ class sp_instr_jump : public sp_instr
+ {
+ // No destination, must be set.
+ sp_instr_jump(uint ip);
+
+ // 'dest' is the destination instruction index.
+ sp_instr_jump(uint ip, uint dest);
+
+ virtual int execute(THD *, uint *nextp);
+
+ // Set the destination instruction 'dest'.
+ void set_destination(uint dest);
+ }
+
+ - Conditional jump
+ class sp_instr_jump_if_not : public sp_instr_jump
+ {
+ // Jump if 'i' evaluates to false. Destination not set yet.
+ sp_instr_jump_if_not(uint ip, Item *i);
+
+ // Jump to 'dest' if 'i' evaluates to false.
+ sp_instr_jump_if_not(uint ip, Item *i, uint dest)
+
+ int execute(THD *, uint *nextp);
+ }
+
+ - Utility functions: sp.h
+
+ // Finds a stored procedure given its name. Returns NULL if not found.
+ sp_head *sp_find(THD *, Item_string *name);
+
+ // Store the procedure 'name' in the database. 'def' is the complete
+ // definition string ("create procedure ...").
+ int sp_create_procedure(THD *,
+ char *name, uint namelen,
+ char *def, uint deflen);
+
+ // Drop the procedure 'name' from the database.
+ int sp_drop(THD *, char *name, uint namelen);
+
+--
diff --git a/Docs/sp-implemented.txt b/Docs/sp-implemented.txt
new file mode 100644
index 00000000000..97d4df2b62c
--- /dev/null
+++ b/Docs/sp-implemented.txt
@@ -0,0 +1,80 @@
+Stored Procedures implemented 2003-02-02:
+
+
+Summary of Not Yet Implemented:
+
+ - FUNCTIONs
+ - Routine characteristics
+ - External languages
+ - Access control
+ - Prepared SP caching; SPs are fetched and reparsed at each call
+ - SQL-99 COMMIT (related to BEGIN/END)
+ - DECLARE CURSOR ...
+ - FOR-loops (as it requires cursors)
+
+
+Summary of what's implemented:
+
+ - SQL PROCEDURES (CREATE/DROP)
+ - CALL
+ - DECLARE of local variables
+ - BEGIN/END, SET, CASE, IF, LOOP, WHILE, REPEAT, ITERATE, LEAVE
+ - SELECT INTO local variables
+
+
+List of what's implemented:
+
+ - CREATE PROCEDURE name ( args ) body
+ No routine characteristics yet.
+
+ - ALTER PROCEDURE name ...
+ Is parsed, but a no-op (as there are no characteristics implemented yet).
+ CASCADE/RESTRICT is not implemented (and CASCADE probably will not be).
+
+ - DROP PROCEDURE name
+ CASCADE/RESTRICT is not implemented (and CASCADE probably will not be).
+
+ - CALL name (args)
+ OUT and INOUT parameters are only supported for local variables, and
+ therefore only useful when calling such procedures from within another
+ procedure.
+ Note: For the time being, when a procedure with OUT/INOUT parameter is
+ called, the out values are silently discarded. In the future, this
+ will either generate an error message, or it might even work to
+ call all procedures from the top-level.
+
+ - Procedure body:
+ - BEGIN/END
+ Is parsed, but not the real thing with (optional) transaction
+ control, it only serves as block syntax for multiple statements (and
+ local variable binding).
+ Note: Multiple statements requires a client that can send bodies
+ containing ";". This is handled in the CLI clients mysql and
+ mysqltest with the "delimiter" command. Changing the end-of-query
+ delimiter ";" to for instance "|" allows
+ - SET of local variables
+ Implemented as part of the pre-existing SET syntax. This allows an
+ extended syntax of "SET a=x, b=y, ..." where different variable types
+ (SP local and global) can be mixed. This also allows combinations
+ of local variables and some options that only make sense for
+ global/system variables; in that case the options are accepted but
+ ignored.
+ - The flow control constructs: CASE, IF, LOOP, WHILE, ITERATE and LEAVE
+ are fully implemented.
+ - SELECT ... INTO local variables (as well as global session variables)
+ is implemented. (Note: This is not SQL-99 feature, but common in other
+ databases.)
+
+
+Open questions:
+
+ - What is the expected result when creating a procedure with a name that
+ already exists? An error or overwrite?
+ - Do PROCEDUREs and FUNCTIONs share namespace or not? I think not, but the
+ we need to flag the type in the mysql.proc table and the name alone is
+ not a unique key any more, or, we have separate tables.
+ (Unfortunately, mysql.func is already taken. Use "sfunc" and maybe even
+ rename "proc" into "sproc" while we still can, for consistency?)
+ - SQL-99 variables and parameters are typed. For the present we don't do
+ any type checking, since this is the way MySQL works. I still don't know
+ if we should keep it this way, or implement type checking.
diff --git a/client/mysql.cc b/client/mysql.cc
index 75d67afab3f..5d008b94bf0 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -104,6 +104,7 @@ extern "C" {
#include "completion_hash.h"
#define PROMPT_CHAR '\\'
+#define DEFAULT_DELIMITER ';'
typedef struct st_status
{
@@ -155,6 +156,7 @@ static char pager[FN_REFLEN], outfile[FN_REFLEN];
static FILE *PAGER, *OUTFILE;
static MEM_ROOT hash_mem_root;
static uint prompt_counter;
+static char delimiter= DEFAULT_DELIMITER;
#ifdef HAVE_SMEM
static char *shared_memory_base_name=0;
@@ -181,7 +183,7 @@ static int com_quit(String *str,char*),
com_use(String *str,char*), com_source(String *str, char*),
com_rehash(String *str, char*), com_tee(String *str, char*),
com_notee(String *str, char*),
- com_prompt(String *str, char*);
+ com_prompt(String *str, char*), com_delimiter(String *str, char*);
#ifdef USE_POPEN
static int com_nopager(String *str, char*), com_pager(String *str, char*),
@@ -249,7 +251,8 @@ static COMMANDS commands[] = {
"Set outfile [to_outfile]. Append everything into given outfile." },
{ "use", 'u', com_use, 1,
"Use another database. Takes database name as argument." },
-
+ { "delimiter", 'd', com_delimiter, 1,
+ "Set query delimiter. " },
/* Get bash-like expansion for some commands */
{ "create table", 0, 0, 0, ""},
{ "create database", 0, 0, 0, ""},
@@ -918,7 +921,7 @@ static COMMANDS *find_command (char *name,char cmd_char)
{
while (my_isspace(system_charset_info,*name))
name++;
- if (strchr(name,';') || strstr(name,"\\g"))
+ if (strchr(name, delimiter) || strstr(name,"\\g"))
return ((COMMANDS *) 0);
if ((end=strcont(name," \t")))
{
@@ -996,7 +999,7 @@ static bool add_line(String &buffer,char *line,char *in_string,
return 1; // Quit
if (com->takes_params)
{
- for (pos++ ; *pos && *pos != ';' ; pos++) ; // Remove parameters
+ for (pos++ ; *pos && *pos != delimiter; pos++) ; // Remove parameters
if (!*pos)
pos--;
}
@@ -1012,7 +1015,7 @@ static bool add_line(String &buffer,char *line,char *in_string,
continue;
}
}
- else if (!*ml_comment && inchar == ';' && !*in_string)
+ else if (!*ml_comment && inchar == delimiter && !*in_string)
{ // ';' is end of command
if (out != line)
buffer.append(line,(uint) (out-line)); // Add this line
@@ -1529,7 +1532,7 @@ com_help(String *buffer __attribute__((unused)),
for (i = 0; commands[i].name; i++)
{
if (commands[i].func)
- tee_fprintf(stdout, "%s\t(\\%c)\t%s\n", commands[i].name,
+ tee_fprintf(stdout, "%-10s(\\%c)\t%s\n", commands[i].name,
commands[i].cmd_char, commands[i].doc);
}
}
@@ -2366,6 +2369,37 @@ static int com_source(String *buffer, char *line)
return error;
}
+ /* ARGSUSED */
+static int
+com_delimiter(String *buffer __attribute__((unused)), char *line)
+{
+ char *tmp;
+ char buff[256];
+
+ if (strlen(line)> 255)
+ {
+ put_info("'DELIMITER' command was too long.", INFO_ERROR);
+ return 0;
+ }
+ bzero(buff, sizeof(buff));
+ strmov(buff, line);
+ tmp= get_arg(buff, 0);
+
+ if (!tmp || !*tmp)
+ {
+ put_info("DELIMITER must be followed by a 'delimiter' char", INFO_ERROR);
+ return 0;
+ }
+
+ if (strlen(tmp)> 1)
+ {
+ put_info("Argument must be one char", INFO_ERROR);
+ return 0;
+ }
+
+ delimiter= *tmp;
+ return 0;
+}
/* ARGSUSED */
static int
diff --git a/client/mysqltest.c b/client/mysqltest.c
index c8e83969565..357fe0ed202 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -89,6 +89,7 @@
#define SLAVE_POLL_INTERVAL 300000 /* 0.3 of a sec */
+#define DEFAULT_DELIMITER ';'
enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT, OPT_SKIP_SAFEMALLOC};
@@ -123,6 +124,8 @@ static int block_stack[BLOCK_STACK_DEPTH];
static int block_ok_stack[BLOCK_STACK_DEPTH];
static uint global_expected_errno[MAX_EXPECTED_ERRORS], global_expected_errors;
+static char delimiter= DEFAULT_DELIMITER;
+
DYNAMIC_ARRAY q_lines;
typedef struct
@@ -197,7 +200,7 @@ Q_SERVER_START, Q_SERVER_STOP,Q_REQUIRE_MANAGER,
Q_WAIT_FOR_SLAVE_TO_STOP,
Q_REQUIRE_VERSION,
Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS,
-Q_ENABLE_INFO, Q_DISABLE_INFO,
+Q_ENABLE_INFO, Q_DISABLE_INFO, Q_DELIMITER,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
Q_COMMENT_WITH_COMMAND
@@ -260,6 +263,7 @@ const char *command_names[]=
"disable_warnings",
"enable_info",
"diable_info",
+ "delimiter",
0
};
@@ -1529,6 +1533,16 @@ int do_while(struct st_query* q)
return 0;
}
+int do_delimiter(char *p)
+{
+ while (*p && my_isspace(system_charset_info,*p))
+ p++;
+ if (!*p)
+ die("Missing delimiter character\n");
+ delimiter=*p;
+
+ return 0;
+}
int safe_copy_unescape(char* dest, char* src, int size)
{
@@ -1608,7 +1622,7 @@ int read_line(char* buf, int size)
switch(state) {
case R_NORMAL:
/* Only accept '{' in the beginning of a line */
- if (c == ';')
+ if (c == delimiter)
{
*p = 0;
return 0;
@@ -1648,7 +1662,7 @@ int read_line(char* buf, int size)
*buf = 0;
return 0;
}
- else if (c == ';' || c == '{')
+ else if (c == delimiter || c == '{')
{
*p = 0;
return 0;
@@ -1668,7 +1682,7 @@ int read_line(char* buf, int size)
state = R_ESC_SLASH_Q1;
break;
case R_ESC_Q_Q1:
- if (c == ';')
+ if (c == delimiter)
{
*p = 0;
return 0;
@@ -1689,7 +1703,7 @@ int read_line(char* buf, int size)
state = R_ESC_SLASH_Q2;
break;
case R_ESC_Q_Q2:
- if (c == ';')
+ if (c == delimiter)
{
*p = 0;
return 0;
@@ -2535,6 +2549,9 @@ int main(int argc, char** argv)
do_sync_with_master2("");
break;
}
+ case Q_DELIMITER:
+ do_delimiter(q->first_argument);
+ break;
case Q_COMMENT: /* Ignore row */
case Q_COMMENT_WITH_COMMAND:
case Q_PING:
diff --git a/configure.in b/configure.in
index c8fe87fa0af..d06fbcb6740 100644
--- a/configure.in
+++ b/configure.in
@@ -4,7 +4,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_INIT(sql/mysqld.cc)
AC_CANONICAL_SYSTEM
# The Docs Makefile.am parses this line!
-AM_INIT_AUTOMAKE(mysql, 4.1.0-alpha)
+AM_INIT_AUTOMAKE(mysql, 5.0.0-alpha)
AM_CONFIG_HEADER(config.h)
PROTOCOL_VERSION=10
diff --git a/include/mysqld_error.h b/include/mysqld_error.h
index 377f714bfff..f52fc75be86 100644
--- a/include/mysqld_error.h
+++ b/include/mysqld_error.h
@@ -266,4 +266,15 @@
#define ER_SELECT_REDUCED 1247
#define ER_TABLENAME_NOT_ALLOWED_HERE 1248
#define ER_NOT_SUPPORTED_AUTH_MODE 1249
-#define ER_ERROR_MESSAGES 250
+#define ER_SP_NO_RECURSIVE_CREATE 1250
+#define ER_SP_ALREADY_EXISTS 1251
+#define ER_SP_DOES_NOT_EXIST 1252
+#define ER_SP_DROP_FAILED 1253
+#define ER_SP_STORE_FAILED 1254
+#define ER_SP_LILABEL_MISMATCH 1255
+#define ER_SP_LABEL_REDEFINE 1256
+#define ER_SP_LABEL_MISMATCH 1257
+#define ER_SP_UNINIT_VAR 1258
+#define ER_SP_BADSELECT 1259
+#define ER_ERROR_MESSAGES 260
+
diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am
index daf65cb2f80..451ab3378d7 100644
--- a/libmysqld/Makefile.am
+++ b/libmysqld/Makefile.am
@@ -55,7 +55,8 @@ sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \
sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \
sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
unireg.cc uniques.cc stacktrace.c sql_union.cc hash_filo.cc \
- spatial.cc gstream.cc sql_help.cc
+ spatial.cc gstream.cc sql_help.cc \
+ sp_head.cc sp_pcontext.cc sp.cc
EXTRA_DIST = lib_vio.c
diff --git a/mysql-test/install_test_db.sh b/mysql-test/install_test_db.sh
index fc3e00d8501..aff00f6ce00 100644
--- a/mysql-test/install_test_db.sh
+++ b/mysql-test/install_test_db.sh
@@ -69,6 +69,7 @@ c_t="" c_c=""
c_hl="" c_hl=""
c_hc="" c_hc=""
c_clr="" c_clr=""
+c_p=""
# Check for old tables
if test ! -f $mdata/db.frm
@@ -246,6 +247,16 @@ then
c_hc="$c_hc comment='categories of help topics';"
fi
+if test ! -f $mdata/proc.frm
+then
+ c_p="$c_p CREATE TABLE proc ("
+ c_p="$c_p name char(64) binary DEFAULT '' NOT NULL,"
+ c_p="$c_p body blob DEFAULT '' NOT NULL,"
+ c_p="$c_p PRIMARY KEY (name)"
+ c_p="$c_p )"
+ c_p="$c_p comment='Stored Procedures';"
+fi
+
mysqld_boot=" $execdir/mysqld --no-defaults --bootstrap --skip-grant-tables \
--basedir=$basedir --datadir=$ldata --skip-innodb --skip-bdb $EXTRA_ARG"
echo "running $mysqld_boot"
@@ -270,6 +281,9 @@ $c_c
$c_hl
$c_hc
$c_clr
+
+$c_p
+
END_OF_DATA
then
exit 0
diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result
index b7243ac5d0b..8c2e2d1def7 100644
--- a/mysql-test/r/connect.result
+++ b/mysql-test/r/connect.result
@@ -7,6 +7,7 @@ help_category
help_relation
help_topic
host
+proc
tables_priv
user
show tables;
@@ -22,6 +23,7 @@ help_category
help_relation
help_topic
host
+proc
tables_priv
user
show tables;
@@ -37,6 +39,7 @@ help_category
help_relation
help_topic
host
+proc
tables_priv
user
show tables;
diff --git a/mysql-test/r/insert.result b/mysql-test/r/insert.result
index ebd34dd7668..3be04584749 100644
--- a/mysql-test/r/insert.result
+++ b/mysql-test/r/insert.result
@@ -64,3 +64,16 @@ use test_$1;
create table t1 (c int);
insert into test_$1.t1 set test_$1.t1.c = '1';
drop database test_$1;
+use test;
+drop table if exists t1,t2,t3;
+create table t1(id1 int not null auto_increment primary key, t char(12));
+create table t2(id2 int not null, t char(12));
+create table t3(id3 int not null, t char(12), index(id3));
+select count(*) from t2;
+count(*)
+500
+insert into t2 select t1.* from t1, t2 t, t3 where t1.id1 = t.id2 and t.id2 = t3.id3;
+select count(*) from t2;
+count(*)
+25500
+drop table if exists t1,t2,t3;
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
new file mode 100644
index 00000000000..35b35e91777
--- /dev/null
+++ b/mysql-test/r/sp.result
@@ -0,0 +1,300 @@
+use test;
+drop table if exists t1;
+create table t1 (
+id char(16) not null,
+data int not null
+);
+create procedure foo42()
+insert into test.t1 values ("foo", 42);
+create procedure bar(x char(16), y int)
+insert into test.t1 values (x, y);
+create procedure two(x1 char(16), x2 char(16), y int)
+begin
+insert into test.t1 values (x1, y);
+insert into test.t1 values (x2, y);
+end;
+create procedure locset(x char(16), y int)
+begin
+declare z1, z2 int;
+set z1 = y;
+set z2 = z1+2;
+insert into test.t1 values (x, z2);
+end;
+create procedure mixset(x char(16), y int)
+begin
+declare z int;
+set @z = y, z = 666, max_join_size = 100;
+insert into test.t1 values (x, z);
+end;
+create procedure zip(x char(16), y int)
+begin
+declare z int;
+call zap(y, z);
+call bar(x, z);
+end;
+create procedure zap(x int, out y int)
+begin
+declare z int;
+set z = x+1, y = z;
+end;
+create procedure iotest(x1 char(16), x2 char(16), y int)
+begin
+call inc2(x2, y);
+insert into test.t1 values (x1, y);
+end;
+create procedure inc2(x char(16), y int)
+begin
+call inc(y);
+insert into test.t1 values (x, y);
+end;
+create procedure inc(inout io int)
+set io = io + 1;
+create procedure cbv1()
+begin
+declare y int;
+set y = 3;
+call cbv2(y+1, y);
+insert into test.t1 values ("cbv1", y);
+end;
+create procedure cbv2(y1 int, inout y2 int)
+begin
+set y2 = 4711;
+insert into test.t1 values ("cbv2", y1);
+end;
+create procedure a0(x int)
+while x do
+set x = x-1;
+insert into test.t1 values ("a0", x);
+end while;
+create procedure a(x int)
+while x > 0 do
+set x = x-1;
+insert into test.t1 values ("a", x);
+end while;
+create procedure b(x int)
+repeat
+insert into test.t1 values (repeat("b",3), x);
+set x = x-1;
+until x = 0 end repeat;
+create procedure b2(x int)
+repeat(select 1 into outfile 'b2');
+insert into test.t1 values (repeat("b2",3), x);
+set x = x-1;
+until x = 0 end repeat;
+drop procedure b2;
+create procedure b3(x int)
+repeat
+select * from test.t1; # No INTO!
+insert into test.t1 values (repeat("b3",3), x);
+set x = x-1;
+until x = 0 end repeat;
+SELECT in a stored procedure must have INTO
+create procedure c(x int)
+hmm: while x > 0 do
+insert into test.t1 values ("c", x);
+set x = x-1;
+iterate hmm;
+insert into test.t1 values ("x", x);
+end while hmm;
+create procedure d(x int)
+hmm: while x > 0 do
+insert into test.t1 values ("d", x);
+set x = x-1;
+leave hmm;
+insert into test.t1 values ("x", x);
+end while hmm;
+create procedure e(x int)
+foo: loop
+if x = 0 then
+leave foo;
+end if;
+insert into test.t1 values ("e", x);
+set x = x-1;
+end loop foo;
+create procedure f(x int)
+if x < 0 then
+insert into test.t1 values ("f", 0);
+elseif x = 0 then
+insert into test.t1 values ("f", 1);
+else
+insert into test.t1 values ("f", 2);
+end if;
+create procedure g(x int)
+case
+when x < 0 then
+insert into test.t1 values ("g", 0);
+when x = 0 then
+insert into test.t1 values ("g", 1);
+else
+insert into test.t1 values ("g", 2);
+end case;
+create procedure h(x int)
+case x
+when 0 then
+insert into test.t1 values ("h0", x);
+when 1 then
+insert into test.t1 values ("h1", x);
+else
+insert into test.t1 values ("h?", x);
+end case;
+create procedure into_test(x char(16), y int)
+begin
+insert into test.t1 values (x, y);
+select id,data into x,y from test.t1 limit 1;
+insert into test.t1 values (concat(x, "2"), y+2);
+end;
+create procedure into_test2(x char(16), y int)
+begin
+insert into test.t1 values (x, y);
+select id,data into x,@z from test.t1 limit 1;
+insert into test.t1 values (concat(x, "2"), y+2);
+end;
+call foo42();
+select * from t1;
+id data
+foo 42
+delete from t1;
+call bar("bar", 666);
+select * from t1;
+id data
+bar 666
+delete from t1;
+call two("one", "two", 3);
+select * from t1;
+id data
+one 3
+two 3
+delete from t1;
+call locset("locset", 19);
+select * from t1;
+id data
+locset 21
+delete from t1;
+call mixset("mixset", 19);
+show variables like 'max_join_size';
+Variable_name Value
+max_join_size 100
+select id,data,@z from t1;
+id data @z
+mixset 666 19
+delete from t1;
+call zip("zip", 99);
+select * from t1;
+id data
+zip 100
+delete from t1;
+call iotest("io1", "io2", 1);
+select * from t1;
+id data
+io2 2
+io1 1
+delete from t1;
+call cbv1();
+select * from t1;
+id data
+cbv2 4
+cbv1 4711
+delete from t1;
+call a0(3);
+select * from t1;
+id data
+a0 2
+a0 1
+a0 0
+delete from t1;
+call a(3);
+select * from t1;
+id data
+a 2
+a 1
+a 0
+delete from t1;
+call b(3);
+select * from t1;
+id data
+bbb 3
+bbb 2
+bbb 1
+delete from t1;
+call c(3);
+select * from t1;
+id data
+c 3
+c 2
+c 1
+delete from t1;
+call d(3);
+select * from t1;
+id data
+d 3
+delete from t1;
+call e(3);
+select * from t1;
+id data
+e 3
+e 2
+e 1
+delete from t1;
+call f(-2);
+call f(0);
+call f(4);
+select * from t1;
+id data
+f 0
+f 1
+f 2
+delete from t1;
+call g(-42);
+call g(0);
+call g(1);
+select * from t1;
+id data
+g 0
+g 1
+g 2
+delete from t1;
+call h(0);
+call h(1);
+call h(17);
+select * from t1;
+id data
+h0 0
+h1 1
+h? 17
+delete from t1;
+call into_test("into", 100);
+select * from t1;
+id data
+into 100
+into2 102
+delete from t1;
+call into_test2("into", 100);
+select id,data,@z from t1;
+id data @z
+into 100 100
+into2 102 100
+delete from t1;
+drop procedure foo42;
+drop procedure bar;
+drop procedure two;
+drop procedure locset;
+drop procedure mixset;
+drop procedure zip;
+drop procedure zap;
+drop procedure iotest;
+drop procedure inc2;
+drop procedure inc;
+drop procedure cbv1;
+drop procedure cbv2;
+drop procedure a0;
+drop procedure a;
+drop procedure b;
+drop procedure c;
+drop procedure d;
+drop procedure e;
+drop procedure f;
+drop procedure g;
+drop procedure h;
+drop procedure into_test;
+drop procedure into_test2;
+drop table t1;
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 0d8c96fea85..79b0e048385 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -593,7 +593,6 @@ x
3
3
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
-You can't specify target table 't1' for update in FROM clause
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
select * from t1;
x
@@ -601,6 +600,8 @@ x
2
3
3
+11
+11
0
drop table t1, t2, t3;
CREATE TABLE t1 (x int not null, y int, primary key (x));
diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test
index bfa8aac7a1f..34302cdbc60 100644
--- a/mysql-test/t/insert.test
+++ b/mysql-test/t/insert.test
@@ -65,3 +65,34 @@ use test_$1;
create table t1 (c int);
insert into test_$1.t1 set test_$1.t1.c = '1';
drop database test_$1;
+use test;
+--disable_warnings
+drop table if exists t1,t2,t3;
+--enable_warnings
+create table t1(id1 int not null auto_increment primary key, t char(12));
+create table t2(id2 int not null, t char(12));
+create table t3(id3 int not null, t char(12), index(id3));
+disable_query_log;
+let $1 = 100;
+while ($1)
+ {
+ let $2 = 5;
+ eval insert into t1(t) values ('$1');
+ while ($2)
+ {
+ eval insert into t2(id2,t) values ($1,'$2');
+ let $3 = 10;
+ while ($3)
+ {
+ eval insert into t3(id3,t) values ($1,'$2');
+ dec $3;
+ }
+ dec $2;
+ }
+ dec $1;
+ }
+enable_query_log;
+select count(*) from t2;
+insert into t2 select t1.* from t1, t2 t, t3 where t1.id1 = t.id2 and t.id2 = t3.id3;
+select count(*) from t2;
+drop table if exists t1,t2,t3;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
new file mode 100644
index 00000000000..48919ff1d6e
--- /dev/null
+++ b/mysql-test/t/sp.test
@@ -0,0 +1,333 @@
+#
+# Basic stored PROCEDURE tests
+#
+#
+
+use test;
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+create table t1 (
+ id char(16) not null,
+ data int not null
+);
+
+# Single statement, no params.
+create procedure foo42()
+ insert into test.t1 values ("foo", 42);
+
+# Single statement, two IN params.
+create procedure bar(x char(16), y int)
+ insert into test.t1 values (x, y);
+
+# Now for multiple statements...
+
+delimiter |;
+
+# Two statements.
+create procedure two(x1 char(16), x2 char(16), y int)
+begin
+ insert into test.t1 values (x1, y);
+ insert into test.t1 values (x2, y);
+end|
+
+# Simple test of local variables and SET.
+create procedure locset(x char(16), y int)
+begin
+ declare z1, z2 int;
+ set z1 = y;
+ set z2 = z1+2;
+ insert into test.t1 values (x, z2);
+end|
+
+# The peculiar (non-standard) mixture of variables types in SET.
+create procedure mixset(x char(16), y int)
+begin
+ declare z int;
+
+ set @z = y, z = 666, max_join_size = 100;
+ insert into test.t1 values (x, z);
+end|
+
+# Multiple CALL statements, one with OUT parameter.
+create procedure zip(x char(16), y int)
+begin
+ declare z int;
+ call zap(y, z);
+ call bar(x, z);
+end|
+
+# SET local variables and OUT parameter.
+create procedure zap(x int, out y int)
+begin
+ declare z int;
+ set z = x+1, y = z;
+end|
+
+
+# INOUT test
+create procedure iotest(x1 char(16), x2 char(16), y int)
+begin
+ call inc2(x2, y);
+ insert into test.t1 values (x1, y);
+end|
+
+create procedure inc2(x char(16), y int)
+begin
+ call inc(y);
+ insert into test.t1 values (x, y);
+end|
+
+create procedure inc(inout io int)
+ set io = io + 1|
+
+
+# Call-by-value test
+# The expected result is:
+# ("cbv2", 4)
+# ("cbv1", 4711)
+create procedure cbv1()
+begin
+ declare y int;
+
+ set y = 3;
+ call cbv2(y+1, y);
+ insert into test.t1 values ("cbv1", y);
+end|
+
+create procedure cbv2(y1 int, inout y2 int)
+begin
+ set y2 = 4711;
+ insert into test.t1 values ("cbv2", y1);
+end|
+
+
+# Minimal tests of the flow control construts
+
+# Just test on 'x'...
+create procedure a0(x int)
+while x do
+ set x = x-1;
+ insert into test.t1 values ("a0", x);
+end while|
+
+# The same, but with a more traditional test.
+create procedure a(x int)
+while x > 0 do
+ set x = x-1;
+ insert into test.t1 values ("a", x);
+end while|
+
+# REPEAT
+create procedure b(x int)
+repeat
+ insert into test.t1 values (repeat("b",3), x);
+ set x = x-1;
+until x = 0 end repeat|
+
+# Check that repeat isn't parsed the wrong way
+create procedure b2(x int)
+repeat(select 1 into outfile 'b2');
+ insert into test.t1 values (repeat("b2",3), x);
+ set x = x-1;
+until x = 0 end repeat|
+# We don't actually want to call it.
+drop procedure b2|
+
+# Btw, this should generate an error
+--error 1259
+create procedure b3(x int)
+repeat
+ select * from test.t1; # No INTO!
+ insert into test.t1 values (repeat("b3",3), x);
+ set x = x-1;
+until x = 0 end repeat|
+
+# Labelled WHILE with ITERATE (pointless really)
+create procedure c(x int)
+hmm: while x > 0 do
+ insert into test.t1 values ("c", x);
+ set x = x-1;
+ iterate hmm;
+ insert into test.t1 values ("x", x);
+end while hmm|
+
+# Labelled WHILE with LEAVE
+create procedure d(x int)
+hmm: while x > 0 do
+ insert into test.t1 values ("d", x);
+ set x = x-1;
+ leave hmm;
+ insert into test.t1 values ("x", x);
+end while hmm|
+
+# LOOP, with simple IF statement
+create procedure e(x int)
+foo: loop
+ if x = 0 then
+ leave foo;
+ end if;
+ insert into test.t1 values ("e", x);
+ set x = x-1;
+end loop foo|
+
+# A full IF statement
+create procedure f(x int)
+if x < 0 then
+ insert into test.t1 values ("f", 0);
+elseif x = 0 then
+ insert into test.t1 values ("f", 1);
+else
+ insert into test.t1 values ("f", 2);
+end if|
+
+# This form of CASE is really just syntactic sugar for IF-ELSEIF-...
+create procedure g(x int)
+case
+when x < 0 then
+ insert into test.t1 values ("g", 0);
+when x = 0 then
+ insert into test.t1 values ("g", 1);
+else
+ insert into test.t1 values ("g", 2);
+end case|
+
+# The "simple CASE"
+create procedure h(x int)
+case x
+when 0 then
+ insert into test.t1 values ("h0", x);
+when 1 then
+ insert into test.t1 values ("h1", x);
+else
+ insert into test.t1 values ("h?", x);
+end case|
+
+create procedure into_test(x char(16), y int)
+begin
+ insert into test.t1 values (x, y);
+ select id,data into x,y from test.t1 limit 1;
+ insert into test.t1 values (concat(x, "2"), y+2);
+end|
+
+# Test INTO with a mix of local and global variables
+create procedure into_test2(x char(16), y int)
+begin
+ insert into test.t1 values (x, y);
+ select id,data into x,@z from test.t1 limit 1;
+ insert into test.t1 values (concat(x, "2"), y+2);
+end|
+
+delimiter ;|
+
+# Now, the CALL tests...
+call foo42();
+select * from t1;
+delete from t1;
+
+call bar("bar", 666);
+select * from t1;
+delete from t1;
+
+call two("one", "two", 3);
+select * from t1;
+delete from t1;
+
+call locset("locset", 19);
+select * from t1;
+delete from t1;
+
+call mixset("mixset", 19);
+show variables like 'max_join_size';
+select id,data,@z from t1;
+delete from t1;
+
+call zip("zip", 99);
+select * from t1;
+delete from t1;
+
+call iotest("io1", "io2", 1);
+select * from t1;
+delete from t1;
+
+call cbv1();
+select * from t1;
+delete from t1;
+
+call a0(3);
+select * from t1;
+delete from t1;
+
+call a(3);
+select * from t1;
+delete from t1;
+
+call b(3);
+select * from t1;
+delete from t1;
+
+call c(3);
+select * from t1;
+delete from t1;
+
+call d(3);
+select * from t1;
+delete from t1;
+
+call e(3);
+select * from t1;
+delete from t1;
+
+call f(-2);
+call f(0);
+call f(4);
+select * from t1;
+delete from t1;
+
+call g(-42);
+call g(0);
+call g(1);
+select * from t1;
+delete from t1;
+
+call h(0);
+call h(1);
+call h(17);
+select * from t1;
+delete from t1;
+
+call into_test("into", 100);
+select * from t1;
+delete from t1;
+
+call into_test2("into", 100);
+select id,data,@z from t1;
+delete from t1;
+
+drop procedure foo42;
+drop procedure bar;
+drop procedure two;
+drop procedure locset;
+drop procedure mixset;
+drop procedure zip;
+drop procedure zap;
+drop procedure iotest;
+drop procedure inc2;
+drop procedure inc;
+drop procedure cbv1;
+drop procedure cbv2;
+drop procedure a0;
+drop procedure a;
+drop procedure b;
+drop procedure c;
+drop procedure d;
+drop procedure e;
+drop procedure f;
+drop procedure g;
+drop procedure h;
+drop procedure into_test;
+drop procedure into_test2;
+
+drop table t1;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 1841e9f109a..c66240071e4 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -343,7 +343,6 @@ INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
select * from t1;
INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
select * from t1;
--- error 1093
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
-- sleep 1
diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh
index 862cffb0cb7..8ff5653d299 100644
--- a/scripts/mysql_install_db.sh
+++ b/scripts/mysql_install_db.sh
@@ -306,6 +306,18 @@ then
c_c="$c_c comment='Column privileges';"
fi
+if test ! -f $mdata/proc.frm
+then
+ echo "Preparing proc table"
+
+ c_p="$c_p CREATE TABLE proc ("
+ c_p="$c_p name char(64) binary DEFAULT '' NOT NULL,"
+ c_p="$c_p body blob DEFAULT '' NOT NULL,"
+ c_p="$c_p PRIMARY KEY (name)"
+ c_p="$c_p )"
+ c_p="$c_p comment='Stored Procedures';"
+fi
+
echo "Installing all prepared tables"
if (
cat << END_OF_DATA
@@ -324,6 +336,7 @@ $i_f
$c_t
$c_c
+$c_p
END_OF_DATA
cat fill_help_tables.sql
) | eval "$execdir/mysqld $defaults --bootstrap --skip-grant-tables \
diff --git a/sql/Makefile.am b/sql/Makefile.am
index b1d9149ddf4..1f00cfbd9e0 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -57,7 +57,8 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
lex.h lex_symbol.h sql_acl.h sql_crypt.h \
log_event.h mini_client.h sql_repl.h slave.h \
stacktrace.h sql_sort.h sql_cache.h set_var.h \
- spatial.h gstream.h
+ spatial.h gstream.h sp_head.h sp_pcontext.h \
+ sp_rcontext.h sp.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
@@ -85,7 +86,8 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
slave.cc sql_repl.cc sql_union.cc sql_derived.cc \
mini_client.cc mini_client_errors.c \
stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc\
- gstream.cc spatial.cc sql_help.cc
+ gstream.cc spatial.cc sql_help.cc \
+ sp_head.cc sp_pcontext.cc sp.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS)
diff --git a/sql/item.cc b/sql/item.cc
index 50f87235196..b1bc478c67a 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -22,6 +22,7 @@
#include "mysql_priv.h"
#include <m_ctype.h>
#include "my_dir.h"
+#include "sp_rcontext.h"
/*****************************************************************************
** Item functions
@@ -166,6 +167,24 @@ CHARSET_INFO * Item::thd_charset() const
return current_thd->variables.thd_charset;
}
+
+Item *
+Item_splocal::this_item()
+{
+ THD *thd= current_thd;
+
+ return thd->spcont->get_item(m_offset);
+}
+
+Item *
+Item_splocal::this_const_item() const
+{
+ THD *thd= current_thd;
+
+ return thd->spcont->get_item(m_offset);
+}
+
+
Item_field::Item_field(Field *f) :Item_ident(NullS,f->table_name,f->field_name)
{
set_field(f);
diff --git a/sql/item.h b/sql/item.h
index 531817c4844..556911dc780 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -111,6 +111,8 @@ public:
CHARSET_INFO *charset() const { return str_value.charset(); };
void set_charset(CHARSET_INFO *cs) { str_value.set_charset(cs); }
virtual void set_outer_resolving() {}
+ virtual Item *this_item() { return this; } /* For SPs mostly. */
+ virtual Item *this_const_item() const { return const_cast<Item*>(this); } /* For SPs mostly. */
// Row emulation
virtual uint cols() { return 1; }
@@ -124,6 +126,57 @@ public:
};
+// A local SP variable (incl. parameters), used in runtime
+class Item_splocal : public Item
+{
+private:
+
+ uint m_offset;
+
+public:
+
+ Item_splocal(uint offset)
+ : m_offset(offset)
+ {}
+
+ Item *this_item();
+ Item *this_const_item() const;
+
+ inline uint get_offset()
+ {
+ return m_offset;
+ }
+
+ // Abstract methods inherited from Item. Just defer the call to
+ // the item in the frame
+ inline enum Type type() const
+ {
+ return this_const_item()->type();
+ }
+
+ inline double val()
+ {
+ return this_item()->val();
+ }
+
+ inline longlong val_int()
+ {
+ return this_item()->val_int();
+ }
+
+ inline String *val_str(String *sp)
+ {
+ return this_item()->val_str(sp);
+ }
+
+ inline void make_field(Send_field *field)
+ {
+ this_item()->make_field(field);
+ }
+
+};
+
+
class st_select_lex;
class Item_ident :public Item
{
diff --git a/sql/lex.h b/sql/lex.h
index d4ae8c32828..0cec9ef8a5d 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -60,6 +60,7 @@ static SYMBOL symbols[] = {
{ "AS", SYM(AS),0,0},
{ "ASC", SYM(ASC),0,0},
{ "ASCII", SYM(ASCII_SYM),0,0},
+ { "ASENSITIVE", SYM(ASENSITIVE_SYM),0,0},
{ "AVG", SYM(AVG_SYM),0,0},
{ "AVG_ROW_LENGTH", SYM(AVG_ROW_LENGTH),0,0},
{ "AUTO_INCREMENT", SYM(AUTO_INC),0,0},
@@ -80,6 +81,7 @@ static SYMBOL symbols[] = {
{ "BY", SYM(BY),0,0},
{ "BYTE", SYM(BYTE_SYM), 0, 0},
{ "CACHE", SYM(CACHE_SYM),0,0},
+ { "CALL", SYM(CALL_SYM),0,0},
{ "CASCADE", SYM(CASCADE),0,0},
{ "CASE", SYM(CASE_SYM),0,0},
{ "CHAR", SYM(CHAR_SYM),0,0},
@@ -107,6 +109,7 @@ static SYMBOL symbols[] = {
{ "CURRENT_DATE", SYM(CURDATE),0,0},
{ "CURRENT_TIME", SYM(CURTIME),0,0},
{ "CURRENT_TIMESTAMP", SYM(NOW_SYM),0,0},
+ { "CURSOR", SYM(CURSOR_SYM),0,0},
{ "DATA", SYM(DATA_SYM),0,0},
{ "DATABASE", SYM(DATABASE),0,0},
{ "DATABASES", SYM(DATABASES),0,0},
@@ -118,6 +121,7 @@ static SYMBOL symbols[] = {
{ "DAY_SECOND", SYM(DAY_SECOND_SYM),0,0},
{ "DEC", SYM(DECIMAL_SYM),0,0},
{ "DECIMAL", SYM(DECIMAL_SYM),0,0},
+ { "DECLARE", SYM(DECLARE_SYM),0,0},
{ "DES_KEY_FILE", SYM(DES_KEY_FILE),0,0},
{ "DEFAULT", SYM(DEFAULT),0,0},
{ "DELAYED", SYM(DELAYED_SYM),0,0},
@@ -140,6 +144,7 @@ static SYMBOL symbols[] = {
{ "ERRORS", SYM(ERRORS),0,0},
{ "END", SYM(END),0,0},
{ "ELSE", SYM(ELSE),0,0},
+ { "ELSEIF", SYM(ELSEIF_SYM),0,0},
{ "ESCAPE", SYM(ESCAPE_SYM),0,0},
{ "ESCAPED", SYM(ESCAPED),0,0},
{ "ENABLE", SYM(ENABLE_SYM),0,0},
@@ -195,6 +200,8 @@ static SYMBOL symbols[] = {
{ "INNER", SYM(INNER_SYM),0,0},
{ "INNOBASE", SYM(INNOBASE_SYM),0,0},
{ "INNODB", SYM(INNOBASE_SYM),0,0},
+ { "INOUT", SYM(INOUT_SYM),0,0},
+ { "INSENSITIVE", SYM(INSENSITIVE_SYM),0,0},
{ "INSERT", SYM(INSERT),0,0},
{ "INSERT_METHOD", SYM(INSERT_METHOD),0,0},
{ "INT", SYM(INT_SYM),0,0},
@@ -212,12 +219,14 @@ static SYMBOL symbols[] = {
{ "ISOLATION", SYM(ISOLATION),0,0},
{ "ISAM", SYM(ISAM_SYM),0,0},
{ "ISSUER", SYM(ISSUER_SYM),0,0},
+ { "ITERATE", SYM(ITERATE_SYM),0,0},
{ "JOIN", SYM(JOIN_SYM),0,0},
{ "KEY", SYM(KEY_SYM),0,0},
{ "KEYS", SYM(KEYS),0,0},
{ "KILL", SYM(KILL_SYM),0,0},
{ "LAST", SYM(LAST_SYM),0,0},
{ "LEADING", SYM(LEADING),0,0},
+ { "LEAVE", SYM(LEAVE_SYM),0,0},
{ "LEFT", SYM(LEFT),0,0},
{ "LEVEL", SYM(LEVEL_SYM),0,0},
{ "LIKE", SYM(LIKE),0,0},
@@ -233,6 +242,7 @@ static SYMBOL symbols[] = {
{ "LOGS", SYM(LOGS_SYM),0,0},
{ "LONG", SYM(LONG_SYM),0,0},
{ "LONGBLOB", SYM(LONGBLOB),0,0},
+ { "LOOP", SYM(LOOP_SYM),0,0},
{ "LONGTEXT", SYM(LONGTEXT),0,0},
{ "LOW_PRIORITY", SYM(LOW_PRIORITY),0,0},
{ "MASTER", SYM(MASTER_SYM),0,0},
@@ -285,6 +295,7 @@ static SYMBOL symbols[] = {
{ "OPTIONALLY", SYM(OPTIONALLY),0,0},
{ "OR", SYM(OR),0,0},
{ "ORDER", SYM(ORDER_SYM),0,0},
+ { "OUT", SYM(OUT_SYM),0,0},
{ "OUTER", SYM(OUTER),0,0},
{ "OUTFILE", SYM(OUTFILE),0,0},
{ "PACK_KEYS", SYM(PACK_KEYS_SYM),0,0},
@@ -314,6 +325,7 @@ static SYMBOL symbols[] = {
{ "REPAIR", SYM(REPAIR),0,0},
{ "REPLACE", SYM(REPLACE),0,0},
{ "REPLICATION", SYM(REPLICATION),0,0},
+ { "REPEAT", SYM(REPEAT_SYM),0,0},
{ "REPEATABLE", SYM(REPEATABLE_SYM),0,0},
{ "REQUIRE", SYM(REQUIRE_SYM),0,0},
{ "RESET", SYM(RESET_SYM),0,0},
@@ -331,6 +343,7 @@ static SYMBOL symbols[] = {
{ "RTREE", SYM(RTREE_SYM),0,0},
{ "SECOND", SYM(SECOND_SYM),0,0},
{ "SELECT", SYM(SELECT_SYM),0,0},
+ { "SENSITIVE", SYM(SENSITIVE_SYM),0,0},
{ "SERIAL", SYM(SERIAL_SYM),0,0},
{ "SERIALIZABLE", SYM(SERIALIZABLE_SYM),0,0},
{ "SESSION", SYM(SESSION_SYM),0,0},
@@ -345,6 +358,7 @@ static SYMBOL symbols[] = {
{ "SOME", SYM(ANY_SYM),0,0},
{ "SONAME", SYM(UDF_SONAME_SYM),0,0},
{ "SPATIAL", SYM(SPATIAL_SYM),0,0},
+ { "SPECIFIC", SYM(SPECIFIC_SYM),0,0},
{ "SQL_BIG_RESULT", SYM(SQL_BIG_RESULT),0,0},
{ "SQL_BUFFER_RESULT", SYM(SQL_BUFFER_RESULT),0,0},
{ "SQL_CACHE", SYM(SQL_CACHE_SYM), 0, 0},
@@ -387,6 +401,7 @@ static SYMBOL symbols[] = {
{ "UNIQUE", SYM(UNIQUE_SYM),0,0},
{ "UNLOCK", SYM(UNLOCK_SYM),0,0},
{ "UNSIGNED", SYM(UNSIGNED),0,0},
+ { "UNTIL", SYM(UNTIL_SYM),0,0},
{ "USE", SYM(USE_SYM),0,0},
{ "USE_FRM", SYM(USE_FRM),0,0},
{ "USING", SYM(USING),0,0},
@@ -405,6 +420,7 @@ static SYMBOL symbols[] = {
{ "WRITE", SYM(WRITE_SYM),0,0},
{ "WHEN", SYM(WHEN_SYM),0,0},
{ "WHERE", SYM(WHERE),0,0},
+ { "WHILE", SYM(WHILE_SYM),0,0},
{ "XOR", SYM(XOR),0,0},
{ "X509", SYM(X509_SYM),0,0},
{ "YEAR", SYM(YEAR_SYM),0,0},
@@ -555,7 +571,6 @@ static SYMBOL sql_functions[] = {
{ "RADIANS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_radians)},
{ "RAND", SYM(RAND),0,0},
{ "RELEASE_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_release_lock)},
- { "REPEAT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_repeat)},
{ "REVERSE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_reverse)},
{ "ROUND", SYM(ROUND),0,0},
{ "RPAD", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_rpad)},
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 5bf7e6e6951..b3457db07c5 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -361,7 +361,7 @@ extern "C" pthread_handler_decl(handle_one_connection,arg);
extern "C" pthread_handler_decl(handle_bootstrap,arg);
void end_thread(THD *thd,bool put_in_cache);
void flush_thread_cache();
-void mysql_execute_command(THD *thd);
+int mysql_execute_command(THD *thd);
bool do_command(THD *thd);
bool dispatch_command(enum enum_server_command command, THD *thd,
char* packet, uint packet_length);
diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt
index 6c3196bfeba..dd2df4c5243 100644
--- a/sql/share/czech/errmsg.txt
+++ b/sql/share/czech/errmsg.txt
@@ -259,4 +259,14 @@ v/*
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt
index dcc016511dd..3c66c5a64f2 100644
--- a/sql/share/danish/errmsg.txt
+++ b/sql/share/danish/errmsg.txt
@@ -253,4 +253,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt
index 6091616fc4a..cdae9092602 100644
--- a/sql/share/dutch/errmsg.txt
+++ b/sql/share/dutch/errmsg.txt
@@ -261,4 +261,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt
index 954b7cd2fb3..6aa45c2ced2 100644
--- a/sql/share/english/errmsg.txt
+++ b/sql/share/english/errmsg.txt
@@ -250,4 +250,14 @@
"Every derived table must have it's own alias",
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt
index 43eb5de89a5..af32e4cc630 100644
--- a/sql/share/estonian/errmsg.txt
+++ b/sql/share/estonian/errmsg.txt
@@ -255,4 +255,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt
index d7bb19c2876..147948d567f 100644
--- a/sql/share/french/errmsg.txt
+++ b/sql/share/french/errmsg.txt
@@ -250,4 +250,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt
index 765fbd875e2..c3b4713241a 100644
--- a/sql/share/german/errmsg.txt
+++ b/sql/share/german/errmsg.txt
@@ -260,4 +260,14 @@
"Für jede abgeleitete Tabelle muss ein eigener Alias angegeben werden.",
"Select %u wurde während der Optimierung reduziert.",
"Tabelle '%-.64s', die in einem der SELECT-Befehle verwendet wurde kann nicht in %-.32s verwendet werden."
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt
index 8831d4e47b9..43ba3c3b173 100644
--- a/sql/share/greek/errmsg.txt
+++ b/sql/share/greek/errmsg.txt
@@ -250,4 +250,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt
index 8d6c321d316..9355daa634e 100644
--- a/sql/share/hungarian/errmsg.txt
+++ b/sql/share/hungarian/errmsg.txt
@@ -252,4 +252,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt
index 451ad3e058b..aee2c229f80 100644
--- a/sql/share/italian/errmsg.txt
+++ b/sql/share/italian/errmsg.txt
@@ -250,4 +250,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt
index 70ab2d6d42d..2b7515c12d1 100644
--- a/sql/share/japanese/errmsg.txt
+++ b/sql/share/japanese/errmsg.txt
@@ -252,4 +252,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt
index c18c3ed3873..b8e0e7a4f25 100644
--- a/sql/share/korean/errmsg.txt
+++ b/sql/share/korean/errmsg.txt
@@ -250,4 +250,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt
index 9cd99613f52..15894decc4a 100644
--- a/sql/share/norwegian-ny/errmsg.txt
+++ b/sql/share/norwegian-ny/errmsg.txt
@@ -252,4 +252,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt
index 32fe6c30b34..01ce52ec060 100644
--- a/sql/share/norwegian/errmsg.txt
+++ b/sql/share/norwegian/errmsg.txt
@@ -252,4 +252,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt
index 4b59a62f991..a2440d5928e 100644
--- a/sql/share/polish/errmsg.txt
+++ b/sql/share/polish/errmsg.txt
@@ -254,4 +254,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt
index 7236bd86652..86b44f4d97d 100644
--- a/sql/share/portuguese/errmsg.txt
+++ b/sql/share/portuguese/errmsg.txt
@@ -250,4 +250,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt
index 0b8bbe1c219..f6cc343a70d 100644
--- a/sql/share/romanian/errmsg.txt
+++ b/sql/share/romanian/errmsg.txt
@@ -254,4 +254,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt
index 2f1eedd207c..33dc4e5d3b8 100644
--- a/sql/share/russian/errmsg.txt
+++ b/sql/share/russian/errmsg.txt
@@ -253,4 +253,14 @@
"Every derived table must have it's own alias"
"Select %u ÂÙÌ ÕÐÒÁÚÄÎÅÎ × ÐÒÏÃÅÓÓÅ ÏÐÔÉÍÉÚÁÃÉÉ",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt
index 75cfd73f3f0..eb699fc812c 100644
--- a/sql/share/serbian/errmsg.txt
+++ b/sql/share/serbian/errmsg.txt
@@ -246,4 +246,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt
index de354f234c7..b1253642081 100644
--- a/sql/share/slovak/errmsg.txt
+++ b/sql/share/slovak/errmsg.txt
@@ -258,4 +258,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt
index a528c3e6b36..6be74571317 100644
--- a/sql/share/spanish/errmsg.txt
+++ b/sql/share/spanish/errmsg.txt
@@ -251,4 +251,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt
index 5473f4e8e42..512314cf856 100644
--- a/sql/share/swedish/errmsg.txt
+++ b/sql/share/swedish/errmsg.txt
@@ -250,4 +250,14 @@
"Every derived table must have it's own alias"
"Select %u was reduced during optimisation",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt
index 0b91786d1f3..337157829a9 100644
--- a/sql/share/ukrainian/errmsg.txt
+++ b/sql/share/ukrainian/errmsg.txt
@@ -255,4 +255,14 @@
"Every derived table must have it's own alias"
"Select %u was ÓËÁÓÏ×ÁÎÏ ÐÒÉ ÏÐÔÉÍiÚÁÃii",
"Table '%-.64s' from one of SELECT's can not be used in %-.32s"
-"Client does not support authentication protocol requested by server. Consider upgrading MySQL client" \ No newline at end of file
+"Client does not support authentication protocol requested by server. Consider upgrading MySQL client"
+"Can't create a PROCEDURE from within a PROCEDURE"
+"PROCEDURE already exists"
+"PROCEDURE does not exist"
+"Failed to DROP PROCEDURE"
+"Failed to CREATE PROCEDURE"
+"%s with no matching label"
+"Redefining label"
+"End-label without match"
+"Referring to uninitialized variable"
+"SELECT in a stored procedure must have INTO"
diff --git a/sql/sp.cc b/sql/sp.cc
new file mode 100644
index 00000000000..42b7248aa80
--- /dev/null
+++ b/sql/sp.cc
@@ -0,0 +1,125 @@
+/* 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"
+#include "sp.h"
+#include "sp_head.h"
+
+// Finds the SP 'name'. Currently this always reads from the database
+// and prepares (parse) it, but in the future it will first look in
+// the in-memory cache for SPs. (And store newly prepared SPs there of
+// course.)
+sp_head *
+sp_find_procedure(THD *thd, Item_string *iname)
+{
+ DBUG_ENTER("sp_find_procedure");
+ extern int yyparse(void *thd);
+ LEX *tmplex;
+ TABLE *table;
+ TABLE_LIST tables;
+ const char *defstr;
+ String *name;
+ sp_head *sp = NULL;
+
+ name = iname->const_string();
+ DBUG_PRINT("enter", ("name: %*s", name->length(), name->c_ptr()));
+ memset(&tables, 0, sizeof(tables));
+ tables.db= (char*)"mysql";
+ tables.real_name= tables.alias= (char*)"proc";
+ if (! (table= open_ltable(thd, &tables, TL_READ)))
+ DBUG_RETURN(NULL);
+
+ if (table->file->index_read_idx(table->record[0], 0,
+ (byte*)name->c_ptr(), name->length(),
+ HA_READ_KEY_EXACT))
+ goto done;
+
+ if ((defstr= get_field(&thd->mem_root, table, 1)) == NULL)
+ goto done;
+
+ // QQ Set up our own mem_root here???
+ tmplex= lex_start(thd, (uchar*)defstr, strlen(defstr));
+ if (yyparse(thd) || thd->fatal_error || tmplex->sphead == NULL)
+ goto done; // Error
+ else
+ sp = tmplex->sphead;
+
+ done:
+ if (table)
+ close_thread_tables(thd);
+ DBUG_RETURN(sp);
+}
+
+int
+sp_create_procedure(THD *thd, char *name, uint namelen, char *def, uint deflen)
+{
+ DBUG_ENTER("sp_create_procedure");
+ DBUG_PRINT("enter", ("name: %*s def: %*s", namelen, name, deflen, def));
+ int ret= 0;
+ TABLE *table;
+ TABLE_LIST tables;
+
+ memset(&tables, 0, sizeof(tables));
+ tables.db= (char*)"mysql";
+ tables.real_name= tables.alias= (char*)"proc";
+ /* Allow creation of procedures even if we can't open proc table */
+ if (! (table= open_ltable(thd, &tables, TL_WRITE)))
+ {
+ ret= -1;
+ goto done;
+ }
+
+ restore_record(table, 2); // Get default values for fields
+
+ table->field[0]->store(name, namelen, default_charset_info);
+ table->field[1]->store(def, deflen, default_charset_info);
+
+ ret= table->file->write_row(table->record[0]);
+
+ done:
+ close_thread_tables(thd);
+ DBUG_RETURN(ret);
+}
+
+int
+sp_drop_procedure(THD *thd, char *name, uint namelen)
+{
+ DBUG_ENTER("sp_drop_procedure");
+ DBUG_PRINT("enter", ("name: %*s", namelen, name));
+ TABLE *table;
+ TABLE_LIST tables;
+
+ tables.db= (char *)"mysql";
+ tables.real_name= tables.alias= (char *)"proc";
+ if (! (table= open_ltable(thd, &tables, TL_WRITE)))
+ goto err;
+ if (! table->file->index_read_idx(table->record[0], 0,
+ (byte *)name, namelen,
+ HA_READ_KEY_EXACT))
+ {
+ int error;
+
+ if ((error= table->file->delete_row(table->record[0])))
+ table->file->print_error(error, MYF(0));
+ }
+ close_thread_tables(thd);
+ DBUG_RETURN(0);
+
+ err:
+ close_thread_tables(thd);
+ DBUG_RETURN(-1);
+}
diff --git a/sql/sp.h b/sql/sp.h
new file mode 100644
index 00000000000..99ea97cba8f
--- /dev/null
+++ b/sql/sp.h
@@ -0,0 +1,44 @@
+/* -*- C++ -*- */
+/* 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 */
+
+#ifndef _SP_H_
+#define _SP_H_
+
+//
+// Finds a stored procedure given its name. Returns NULL if not found.
+//
+sp_head *
+sp_find_procedure(THD *thd, Item_string *name);
+
+int
+sp_create_procedure(THD *thd, char *name, uint namelen, char *def, uint deflen);
+
+int
+sp_drop_procedure(THD *thd, char *name, uint namelen);
+
+#if 0
+sp_head *
+sp_find_function(THD *thd, Item_string *name);
+
+int
+sp_create_function(THD *thd, char *name, uint namelen, char *def, uint deflen);
+
+int
+sp_drop_function(THD *thd, char *name, uint namelen);
+#endif
+
+#endif /* _SP_H_ */
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
new file mode 100644
index 00000000000..ff487429ec7
--- /dev/null
+++ b/sql/sp_head.cc
@@ -0,0 +1,422 @@
+/* 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 */
+
+#ifdef __GNUC__
+#pragma implementation
+#endif
+
+#include "mysql_priv.h"
+#include "sp_head.h"
+#include "sp.h"
+#include "sp_pcontext.h"
+#include "sp_rcontext.h"
+
+/* Evaluate a (presumed) func item. Always returns an item, the parameter
+** if nothing else.
+*/
+static Item *
+eval_func_item(THD *thd, Item *it, enum enum_field_types type)
+{
+ it= it->this_item();
+
+ if (it->fix_fields(thd, 0, NULL))
+ return it; // Shouldn't happen?
+
+ /* QQ How do we do this? Is there some better way? */
+ switch (type)
+ {
+ case MYSQL_TYPE_TINY:
+ case MYSQL_TYPE_SHORT:
+ case MYSQL_TYPE_LONG:
+ case MYSQL_TYPE_LONGLONG:
+ case MYSQL_TYPE_INT24:
+ it= new Item_int(it->val_int());
+ break;
+ case MYSQL_TYPE_DECIMAL:
+ case MYSQL_TYPE_FLOAT:
+ case MYSQL_TYPE_DOUBLE:
+ it= new Item_real(it->val());
+ break;
+ case MYSQL_TYPE_VAR_STRING:
+ case MYSQL_TYPE_STRING:
+ case MYSQL_TYPE_TIMESTAMP:
+ case MYSQL_TYPE_DATE:
+ case MYSQL_TYPE_TIME:
+ case MYSQL_TYPE_DATETIME:
+ case MYSQL_TYPE_YEAR:
+ case MYSQL_TYPE_NEWDATE:
+ {
+ char buffer[MAX_FIELD_WIDTH];
+ String tmp(buffer, sizeof(buffer), default_charset_info);
+ String *s= it->val_str(&tmp);
+
+ it= new Item_string(s->c_ptr_quick(), s->length(), default_charset_info);
+ break;
+ }
+ case MYSQL_TYPE_NULL:
+ it= new Item_null(); // A NULL is a NULL is a NULL...
+ break;
+ case MYSQL_TYPE_ENUM:
+ case MYSQL_TYPE_SET:
+ case MYSQL_TYPE_TINY_BLOB:
+ case MYSQL_TYPE_MEDIUM_BLOB:
+ case MYSQL_TYPE_LONG_BLOB:
+ case MYSQL_TYPE_BLOB:
+ case MYSQL_TYPE_GEOMETRY:
+ /* QQ Don't know what to do with the rest. */
+ break;
+ }
+
+ return it;
+}
+
+sp_head::sp_head(LEX_STRING *name, LEX *lex)
+ : m_simple_case(FALSE)
+{
+ const char *dstr = (const char*)lex->buf;
+
+ m_call_lex= lex;
+ m_name= new Item_string(name->str, name->length, default_charset_info);
+ m_defstr= new Item_string(dstr, lex->end_of_query - lex->buf,
+ default_charset_info);
+ my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
+ m_backpatch.empty();
+}
+
+int
+sp_head::create(THD *thd)
+{
+ DBUG_ENTER("sp_head::create");
+ String *name= m_name->const_string();
+ String *def= m_defstr->const_string();
+
+ DBUG_PRINT("info", ("name: %s def: %s", name->c_ptr(), def->c_ptr()));
+ DBUG_RETURN(sp_create_procedure(thd,
+ name->c_ptr(), name->length(),
+ def->c_ptr(), def->length()));
+}
+
+int
+sp_head::execute(THD *thd)
+{
+ DBUG_ENTER("sp_head::execute");
+ DBUG_PRINT("executing", ("procedure %s", ((String *)m_name->const_string())->c_ptr()));
+ int ret= 0;
+ sp_instr *p;
+ sp_pcontext *pctx = m_call_lex->spcont;
+ uint csize = pctx->max_framesize();
+ uint params = pctx->params();
+ sp_rcontext *octx = thd->spcont;
+ sp_rcontext *nctx = NULL;
+ my_bool tmp_octx = FALSE; // True if we have allocated a temporary octx
+
+ if (csize > 0)
+ {
+ uint i;
+ List_iterator_fast<Item> li(m_call_lex->value_list);
+ Item *it = li++; // Skip first one, it's the procedure name
+
+ nctx = new sp_rcontext(csize);
+ if (! octx)
+ { // Create a temporary old context
+ octx = new sp_rcontext(csize);
+ tmp_octx = TRUE;
+ }
+ // QQ: No error checking whatsoever right now. Should do type checking?
+ for (i = 0 ; (it= li++) && i < params ; i++)
+ {
+ sp_pvar_t *pvar = pctx->find_pvar(i);
+
+ if (! pvar)
+ nctx->set_oindex(i, -1); // Shouldn't happen
+ else
+ {
+ if (pvar->mode == sp_param_out)
+ nctx->push_item(it->this_item()); // OUT
+ else
+ nctx->push_item(eval_func_item(thd, it, pvar->type)); // IN or INOUT
+ // Note: If it's OUT or INOUT, it must be a variable.
+ // QQ: Need to handle "global" user/host variables too!!!
+ if (pvar->mode == sp_param_in)
+ nctx->set_oindex(i, -1); // IN
+ else // OUT or INOUT
+ nctx->set_oindex(i, static_cast<Item_splocal *>(it)->get_offset());
+ }
+ }
+ // The rest of the frame are local variables which are all IN.
+ // QQ We haven't found any hint of what the value is when unassigned,
+ // so we set it to NULL for now. It's an error to refer to an
+ // unassigned variable anyway (which should be detected by the parser).
+ for (; i < csize ; i++)
+ nctx->push_item(NULL);
+ thd->spcont= nctx;
+ }
+
+ { // Execute instructions...
+ uint ip= 0;
+
+ while (ret == 0)
+ {
+ sp_instr *i;
+
+ i = get_instr(ip); // Returns NULL when we're done.
+ if (i == NULL)
+ break;
+ DBUG_PRINT("execute", ("Instruction %u", ip));
+ ret= i->execute(thd, &ip);
+ }
+ }
+
+ // Don't copy back OUT values if we got an error
+ if (ret == 0 && csize > 0)
+ {
+ List_iterator_fast<Item> li(m_call_lex->value_list);
+ Item *it = li++; // Skip first one, it's the procedure name
+
+ // Copy back all OUT or INOUT values to the previous frame, or
+ // set global user variables
+ for (uint i = 0 ; (it= li++) && i < params ; i++)
+ {
+ int oi = nctx->get_oindex(i);
+
+ if (oi >= 0)
+ {
+ if (! tmp_octx)
+ octx->set_item(nctx->get_oindex(i), nctx->get_item(i));
+ else
+ { // A global user variable
+#if 0
+ // QQ This works if the parameter really is a user variable, but
+ // for the moment we can't assure that, so it will crash if it's
+ // something else. So for now, we just do nothing, to avoid a crash.
+ // Note: This also assumes we have a get_name() method in
+ // the Item_func_get_user_var class.
+ Item *item= nctx->get_item(i);
+ Item_func_set_user_var *suv;
+ Item_func_get_user_var *guv= static_cast<Item_func_get_user_var*>(it);
+
+ suv= new Item_func_set_user_var(guv->get_name(), item);
+ suv->fix_fields(thd, NULL, &item);
+ suv->fix_length_and_dec();
+ suv->update();
+#endif
+ }
+ }
+ }
+
+ if (tmp_octx)
+ thd->spcont= NULL;
+ else
+ thd->spcont= octx;
+ }
+
+ DBUG_RETURN(ret);
+}
+
+
+// Reset lex during parsing, before we parse a sub statement.
+void
+sp_head::reset_lex(THD *thd)
+{
+ memcpy(&m_lex, &thd->lex, sizeof(LEX)); // Save old one
+ /* Reset most stuff. The length arguments doesn't matter here. */
+ lex_start(thd, m_lex.buf, m_lex.end_of_query - m_lex.ptr);
+ /* We must reset ptr and end_of_query again */
+ thd->lex.ptr= m_lex.ptr;
+ thd->lex.end_of_query= m_lex.end_of_query;
+ /* And keep the SP stuff too */
+ thd->lex.sphead = m_lex.sphead;
+ thd->lex.spcont = m_lex.spcont;
+ /* Clear all lists. (QQ Why isn't this reset by lex_start()?).
+ We may be overdoing this, but we know for sure that value_list must
+ be cleared at least. */
+ thd->lex.col_list.empty();
+ thd->lex.ref_list.empty();
+ thd->lex.drop_list.empty();
+ thd->lex.alter_list.empty();
+ thd->lex.interval_list.empty();
+ thd->lex.users_list.empty();
+ thd->lex.columns.empty();
+ thd->lex.key_list.empty();
+ thd->lex.create_list.empty();
+ thd->lex.insert_list= NULL;
+ thd->lex.field_list.empty();
+ thd->lex.value_list.empty();
+ thd->lex.many_values.empty();
+ thd->lex.var_list.empty();
+ thd->lex.param_list.empty();
+ thd->lex.proc_list.empty();
+ thd->lex.auxilliary_table_list.empty();
+}
+
+// Restore lex during parsing, after we have parsed a sub statement.
+void
+sp_head::restore_lex(THD *thd)
+{
+ // Update some state in the old one first
+ m_lex.ptr= thd->lex.ptr;
+ m_lex.next_state= thd->lex.next_state;
+
+ // Collect some data from the sub statement lex.
+ if (thd->lex.sql_command == SQLCOM_CALL)
+ {
+ // We know they are Item_strings (since we put them there ourselves)
+ // It would be slightly faster to keep the list sorted, but we need
+ // an "insert before" method to do that.
+ Item_string *proc= static_cast<Item_string*>(thd->lex.value_list.head());
+ String *snew= proc->val_str(NULL);
+ List_iterator_fast<Item_string> li(m_calls);
+ Item_string *it;
+
+ while ((it= li++))
+ {
+ String *sold= it->val_str(NULL);
+
+ if (stringcmp(snew, sold) == 0)
+ break;
+ }
+ if (! it)
+ m_calls.push_back(proc);
+
+ }
+ // Merge used tables
+ // QQ ...or just open tables in thd->open_tables?
+ // This is not entirerly clear at the moment, but for now, we collect
+ // tables here.
+ for (SELECT_LEX *sl= thd->lex.all_selects_list ;
+ sl ;
+ sl= sl->next_select())
+ {
+ for (TABLE_LIST *tables= sl->get_table_list() ;
+ tables ;
+ tables= tables->next)
+ {
+ List_iterator_fast<char *> li(m_tables);
+ char **tb;
+
+ while ((tb= li++))
+ if (strcasecmp(tables->real_name, *tb) == 0)
+ break;
+ if (! tb)
+ m_tables.push_back(&tables->real_name);
+ }
+ }
+
+ memcpy(&thd->lex, &m_lex, sizeof(LEX)); // Restore lex
+}
+
+void
+sp_head::push_backpatch(sp_instr *i, sp_label_t *lab)
+{
+ bp_t *bp= (bp_t *)my_malloc(sizeof(bp_t), MYF(MY_WME));
+
+ if (bp)
+ {
+ bp->lab= lab;
+ bp->instr= i;
+ (void)m_backpatch.push_front(bp);
+ }
+}
+
+void
+sp_head::backpatch(sp_label_t *lab)
+{
+ bp_t *bp;
+ uint dest= instructions();
+ List_iterator_fast<bp_t> li(m_backpatch);
+
+ while ((bp= li++))
+ if (bp->lab == lab)
+ {
+ sp_instr_jump *i= static_cast<sp_instr_jump *>(bp->instr);
+
+ i->set_destination(dest);
+ }
+}
+
+
+// ------------------------------------------------------------------
+
+//
+// sp_instr_stmt
+//
+int
+sp_instr_stmt::execute(THD *thd, uint *nextp)
+{
+ DBUG_ENTER("sp_instr_stmt::execute");
+ DBUG_PRINT("info", ("command: %d", m_lex.sql_command));
+ LEX olex; // The other lex
+ int res;
+
+ memcpy(&olex, &thd->lex, sizeof(LEX)); // Save the other lex
+
+ memcpy(&thd->lex, &m_lex, sizeof(LEX)); // Use my own lex
+ thd->lex.thd = thd;
+
+ res= mysql_execute_command(thd);
+
+ memcpy(&thd->lex, &olex, sizeof(LEX)); // Restore the other lex
+
+ *nextp = m_ip+1;
+ DBUG_RETURN(res);
+}
+
+//
+// sp_instr_set
+//
+int
+sp_instr_set::execute(THD *thd, uint *nextp)
+{
+ DBUG_ENTER("sp_instr_set::execute");
+ DBUG_PRINT("info", ("offset: %u", m_offset));
+ thd->spcont->set_item(m_offset, eval_func_item(thd, m_value, m_type));
+ *nextp = m_ip+1;
+ DBUG_RETURN(0);
+}
+
+//
+// sp_instr_jump_if
+//
+int
+sp_instr_jump_if::execute(THD *thd, uint *nextp)
+{
+ DBUG_ENTER("sp_instr_jump_if::execute");
+ DBUG_PRINT("info", ("destination: %u", m_dest));
+ Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
+
+ if (it->val_int())
+ *nextp = m_dest;
+ else
+ *nextp = m_ip+1;
+ DBUG_RETURN(0);
+}
+
+//
+// sp_instr_jump_if_not
+//
+int
+sp_instr_jump_if_not::execute(THD *thd, uint *nextp)
+{
+ DBUG_ENTER("sp_instr_jump_if_not::execute");
+ DBUG_PRINT("info", ("destination: %u", m_dest));
+ Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
+
+ if (! it->val_int())
+ *nextp = m_dest;
+ else
+ *nextp = m_ip+1;
+ DBUG_RETURN(0);
+}
diff --git a/sql/sp_head.h b/sql/sp_head.h
new file mode 100644
index 00000000000..820193e8184
--- /dev/null
+++ b/sql/sp_head.h
@@ -0,0 +1,306 @@
+/* -*- C++ -*- */
+/* 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 */
+
+#ifndef _SP_HEAD_H_
+#define _SP_HEAD_H_
+
+#ifdef __GNUC__
+#pragma interface /* gcc class implementation */
+#endif
+
+#include <stddef.h>
+
+struct sp_label;
+
+class sp_instr;
+
+class sp_head : public Sql_alloc
+{
+ sp_head(const sp_head &); /* Prevent use of these */
+ void operator=(sp_head &);
+
+public:
+
+ my_bool m_simple_case; // TRUE if parsing simple case, FALSE otherwise
+ List<Item_string> m_calls; // Called procedures.
+ List<char *> m_tables; // Used tables.
+
+ static void *operator new(size_t size)
+ {
+ return (void*) sql_alloc((uint) size);
+ }
+
+ static void operator delete(void *ptr, size_t size)
+ {
+ /* Empty */
+ }
+
+ sp_head(LEX_STRING *name, LEX* lex);
+
+ int
+ create(THD *thd);
+
+ int
+ execute(THD *thd);
+
+ inline void
+ add_instr(sp_instr *i)
+ {
+ insert_dynamic(&m_instr, (gptr)&i);
+ }
+
+ inline uint
+ instructions()
+ {
+ return m_instr.elements;
+ }
+
+ // Resets lex in 'thd' and keeps a copy of the old one.
+ void
+ reset_lex(THD *thd);
+
+ // Restores lex in 'thd' from our copy, but keeps some status from the
+ // one in 'thd', like ptr, tables, fields, etc.
+ void
+ restore_lex(THD *thd);
+
+ // Put the instruction on the backpatch list, associated with the label.
+ void
+ push_backpatch(sp_instr *, struct sp_label *);
+
+ // Update all instruction with this label in the backpatch list to
+ // the current position.
+ void
+ backpatch(struct sp_label *);
+
+private:
+
+ Item_string *m_name;
+ Item_string *m_defstr;
+ LEX *m_call_lex; // The CALL's own lex
+ LEX m_lex; // Temp. store for the other lex
+ DYNAMIC_ARRAY m_instr; // The "instructions"
+ typedef struct
+ {
+ struct sp_label *lab;
+ sp_instr *instr;
+ } bp_t;
+ List<bp_t> m_backpatch; // Instructions needing backpaching
+
+ inline sp_instr *
+ get_instr(uint i)
+ {
+ sp_instr *in= NULL;
+
+ get_dynamic(&m_instr, (gptr)&in, i);
+ return in;
+ }
+
+}; // class sp_head : public Sql_alloc
+
+
+//
+// "Instructions"...
+//
+
+class sp_instr : public Sql_alloc
+{
+ sp_instr(const sp_instr &); /* Prevent use of these */
+ void operator=(sp_instr &);
+
+public:
+
+ // Should give each a name or type code for debugging purposes?
+ sp_instr(uint ip)
+ : Sql_alloc(), m_ip(ip)
+ {}
+
+ virtual ~sp_instr()
+ {}
+
+ // Execute this instrution. '*nextp' will be set to the index of the next
+ // instruction to execute. (For most instruction this will be the
+ // instruction following this one.)
+ // Returns 0 on success, non-zero if some error occured.
+ virtual int
+ execute(THD *thd, uint *nextp)
+ { // Default is a no-op.
+ *nextp = m_ip+1; // Next instruction
+ return 0;
+ }
+
+protected:
+
+ uint m_ip; // My index
+
+}; // class sp_instr : public Sql_alloc
+
+
+//
+// Call out to some prepared SQL statement.
+//
+class sp_instr_stmt : public sp_instr
+{
+ sp_instr_stmt(const sp_instr_stmt &); /* Prevent use of these */
+ void operator=(sp_instr_stmt &);
+
+public:
+
+ sp_instr_stmt(uint ip)
+ : sp_instr(ip)
+ {}
+
+ virtual ~sp_instr_stmt()
+ {}
+
+ virtual int execute(THD *thd, uint *nextp);
+
+ inline void
+ set_lex(LEX *lex)
+ {
+ memcpy(&m_lex, lex, sizeof(LEX));
+ }
+
+ inline LEX *
+ get_lex()
+ {
+ return &m_lex;
+ }
+
+private:
+
+ LEX m_lex; // My own lex
+
+}; // class sp_instr_stmt : public sp_instr
+
+
+class sp_instr_set : public sp_instr
+{
+ sp_instr_set(const sp_instr_set &); /* Prevent use of these */
+ void operator=(sp_instr_set &);
+
+public:
+
+ sp_instr_set(uint ip, uint offset, Item *val, enum enum_field_types type)
+ : sp_instr(ip), m_offset(offset), m_value(val), m_type(type)
+ {}
+
+ virtual ~sp_instr_set()
+ {}
+
+ virtual int execute(THD *thd, uint *nextp);
+
+private:
+
+ uint m_offset; // Frame offset
+ Item *m_value;
+ enum enum_field_types m_type; // The declared type
+
+}; // class sp_instr_set : public sp_instr
+
+
+class sp_instr_jump : public sp_instr
+{
+ sp_instr_jump(const sp_instr_jump &); /* Prevent use of these */
+ void operator=(sp_instr_jump &);
+
+public:
+
+ sp_instr_jump(uint ip)
+ : sp_instr(ip)
+ {}
+
+ sp_instr_jump(uint ip, uint dest)
+ : sp_instr(ip), m_dest(dest)
+ {}
+
+ virtual ~sp_instr_jump()
+ {}
+
+ virtual int execute(THD *thd, uint *nextp)
+ {
+ *nextp= m_dest;
+ return 0;
+ }
+
+ virtual void
+ set_destination(uint dest)
+ {
+ m_dest= dest;
+ }
+
+protected:
+
+ int m_dest; // Where we will go
+
+}; // class sp_instr_jump : public sp_instr
+
+
+class sp_instr_jump_if : public sp_instr_jump
+{
+ sp_instr_jump_if(const sp_instr_jump_if &); /* Prevent use of these */
+ void operator=(sp_instr_jump_if &);
+
+public:
+
+ sp_instr_jump_if(uint ip, Item *i)
+ : sp_instr_jump(ip), m_expr(i)
+ {}
+
+ sp_instr_jump_if(uint ip, Item *i, uint dest)
+ : sp_instr_jump(ip, dest), m_expr(i)
+ {}
+
+ virtual ~sp_instr_jump_if()
+ {}
+
+ virtual int execute(THD *thd, uint *nextp);
+
+private:
+
+ Item *m_expr; // The condition
+
+}; // class sp_instr_jump_if : public sp_instr_jump
+
+
+class sp_instr_jump_if_not : public sp_instr_jump
+{
+ sp_instr_jump_if_not(const sp_instr_jump_if_not &); /* Prevent use of these */
+ void operator=(sp_instr_jump_if_not &);
+
+public:
+
+ sp_instr_jump_if_not(uint ip, Item *i)
+ : sp_instr_jump(ip), m_expr(i)
+ {}
+
+ sp_instr_jump_if_not(uint ip, Item *i, uint dest)
+ : sp_instr_jump(ip, dest), m_expr(i)
+ {}
+
+ virtual ~sp_instr_jump_if_not()
+ {}
+
+ virtual int execute(THD *thd, uint *nextp);
+
+private:
+
+ Item *m_expr; // The condition
+
+}; // class sp_instr_jump_if_not : public sp_instr_jump
+
+#endif /* _SP_HEAD_H_ */
diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc
new file mode 100644
index 00000000000..407151c3e38
--- /dev/null
+++ b/sql/sp_pcontext.cc
@@ -0,0 +1,120 @@
+/* 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 */
+
+#ifdef __GNUC__
+#pragma implementation
+#endif
+
+#if defined(WIN32) || defined(__WIN__)
+#undef SAFEMALLOC /* Problems with threads */
+#endif
+
+#include "mysql_priv.h"
+#include "sp_pcontext.h"
+#include "sp_head.h"
+
+sp_pcontext::sp_pcontext()
+ : m_params(0), m_framesize(0), m_i(0), m_genlab(0)
+{
+ m_pvar_size = 16;
+ m_pvar = (sp_pvar_t *)my_malloc(m_pvar_size * sizeof(sp_pvar_t), MYF(MY_WME));
+ if (m_pvar)
+ memset(m_pvar, 0, m_pvar_size * sizeof(sp_pvar_t));
+ m_label.empty();
+}
+
+void
+sp_pcontext::grow()
+{
+ uint sz = m_pvar_size + 8;
+ sp_pvar_t *a = (sp_pvar_t *)my_realloc((char *)m_pvar,
+ sz * sizeof(sp_pvar_t),
+ MYF(MY_WME | MY_ALLOW_ZERO_PTR));
+
+ if (a)
+ {
+ m_pvar_size = sz;
+ m_pvar = a;
+ }
+}
+
+/* This does a linear search (from newer to older variables, in case
+** we have shadowed names).
+** It's possible to have a more efficient allocation and search method,
+** but it might not be worth it. The typical number of parameters and
+** variables will in most cases be low (a handfull).
+** And this is only called during parsing.
+*/
+sp_pvar_t *
+sp_pcontext::find_pvar(LEX_STRING *name)
+{
+ String n(name->str, name->length, default_charset_info);
+ uint i = m_i;
+
+ while (i-- > 0)
+ {
+ if (stringcmp(&n, m_pvar[i].name->const_string()) == 0)
+ return m_pvar + i;
+ }
+ return NULL;
+}
+
+void
+sp_pcontext::push(LEX_STRING *name, enum enum_field_types type,
+ sp_param_mode_t mode)
+{
+ if (m_i >= m_pvar_size)
+ grow();
+ if (m_i < m_pvar_size)
+ {
+ if (m_i == m_framesize)
+ m_framesize += 1;
+ m_pvar[m_i].name= new Item_string(name->str, name->length,
+ default_charset_info);
+ m_pvar[m_i].type= type;
+ m_pvar[m_i].mode= mode;
+ m_pvar[m_i].offset= m_i;
+ m_pvar[m_i].isset= (mode == sp_param_out ? FALSE : TRUE);
+ m_i += 1;
+ }
+}
+
+sp_label_t *
+sp_pcontext::push_label(char *name, uint ip)
+{
+ sp_label_t *lab = (sp_label_t *)my_malloc(sizeof(sp_label_t), MYF(MY_WME));
+
+ if (lab)
+ {
+ lab->name= name;
+ lab->ip= ip;
+ m_label.push_front(lab);
+ }
+ return lab;
+}
+
+sp_label_t *
+sp_pcontext::find_label(char *name)
+{
+ List_iterator_fast<sp_label_t> li(m_label);
+ sp_label_t *lab;
+
+ while ((lab= li++))
+ if (strcasecmp(name, lab->name) == 0)
+ return lab;
+
+ return NULL;
+}
diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h
new file mode 100644
index 00000000000..6ab38e77017
--- /dev/null
+++ b/sql/sp_pcontext.h
@@ -0,0 +1,155 @@
+/* -*- C++ -*- */
+/* 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 */
+
+#ifndef _SP_PCONTEXT_H_
+#define _SP_PCONTEXT_H_
+
+#ifdef __GNUC__
+#pragma interface /* gcc class implementation */
+#endif
+
+typedef enum
+{
+ sp_param_in,
+ sp_param_out,
+ sp_param_inout
+} sp_param_mode_t;
+
+typedef struct
+{
+ Item_string *name;
+ enum enum_field_types type;
+ sp_param_mode_t mode;
+ uint offset; // Offset in current frame
+ my_bool isset;
+} sp_pvar_t;
+
+typedef struct sp_label
+{
+ char *name;
+ uint ip; // Instruction index
+} sp_label_t;
+
+class sp_pcontext : public Sql_alloc
+{
+ sp_pcontext(const sp_pcontext &); /* Prevent use of these */
+ void operator=(sp_pcontext &);
+
+ public:
+
+ sp_pcontext();
+
+ inline uint
+ max_framesize()
+ {
+ return m_framesize;
+ }
+
+ inline uint
+ current_framesize()
+ {
+ return m_i;
+ }
+
+ inline uint
+ params()
+ {
+ return m_params;
+ }
+
+ // Set the number of parameters to the current esize
+ inline void
+ set_params()
+ {
+ m_params= m_i;
+ }
+
+ inline void
+ set_type(uint i, enum enum_field_types type)
+ {
+ if (i < m_i)
+ m_pvar[i].type= type;
+ }
+
+ inline void
+ set_isset(uint i, my_bool val)
+ {
+ if (i < m_i)
+ m_pvar[i].isset= val;
+ }
+
+ void
+ push(LEX_STRING *name, enum enum_field_types type, sp_param_mode_t mode);
+
+ // Pop the last 'num' slots of the frame
+ inline void
+ pop(uint num = 1)
+ {
+ if (num < m_i)
+ m_i -= num;
+ }
+
+ // Find by name
+ sp_pvar_t *
+ find_pvar(LEX_STRING *name);
+
+ // Find by index
+ sp_pvar_t *
+ find_pvar(uint i)
+ {
+ if (i >= m_i)
+ return NULL;
+ return m_pvar+i;
+ }
+
+ sp_label_t *
+ push_label(char *name, uint ip);
+
+ sp_label_t *
+ find_label(char *name);
+
+ inline sp_label_t *
+ last_label()
+ {
+ return m_label.head();
+ }
+
+ inline sp_label_t *
+ pop_label()
+ {
+ return m_label.pop();
+ }
+
+private:
+
+ uint m_params; // The number of parameters
+ uint m_framesize; // The maximum framesize
+ uint m_i; // The current index (during parsing)
+
+ sp_pvar_t *m_pvar;
+ uint m_pvar_size; // Current size of m_pvar.
+
+ void
+ grow();
+
+ List<sp_label_t> m_label; // The label list
+ uint m_genlab; // Gen. label counter
+
+}; // class sp_pcontext : public Sql_alloc
+
+
+#endif /* _SP_PCONTEXT_H_ */
diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h
new file mode 100644
index 00000000000..5ffbb0266e6
--- /dev/null
+++ b/sql/sp_rcontext.h
@@ -0,0 +1,82 @@
+/* -*- C++ -*- */
+/* 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 */
+
+#ifndef _SP_RCONTEXT_H_
+#define _SP_RCONTEXT_H_
+
+class sp_rcontext : public Sql_alloc
+{
+ sp_rcontext(const sp_rcontext &); /* Prevent use of these */
+ void operator=(sp_rcontext &);
+
+ public:
+
+ sp_rcontext(uint size)
+ : m_count(0), m_size(size)
+ {
+ m_frame = (Item **)sql_alloc(size * sizeof(Item*));
+ m_outs = (int *)sql_alloc(size * sizeof(int));
+ }
+
+ ~sp_rcontext()
+ {
+ // Not needed?
+ //sql_element_free(m_frame);
+ }
+
+ inline void
+ push_item(Item *i)
+ {
+ if (m_count < m_size)
+ m_frame[m_count++] = i;
+ }
+
+ inline void
+ set_item(uint idx, Item *i)
+ {
+ if (idx < m_count)
+ m_frame[idx] = i;
+ }
+
+ inline Item *
+ get_item(uint idx)
+ {
+ return m_frame[idx];
+ }
+
+ inline void
+ set_oindex(uint idx, int oidx)
+ {
+ m_outs[idx] = oidx;
+ }
+
+ inline int
+ get_oindex(uint idx)
+ {
+ return m_outs[idx];
+ }
+
+private:
+
+ uint m_count;
+ uint m_size;
+ Item **m_frame;
+ int *m_outs;
+
+}; // class sp_rcontext : public Sql_alloc
+
+#endif /* _SP_RCONTEXT_H_ */
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 23a8a6fa8f1..5ac904393f5 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -35,6 +35,7 @@
#include <io.h>
#endif
#include <mysys_err.h>
+#include <sp_rcontext.h>
/*****************************************************************************
@@ -80,7 +81,7 @@ extern "C" void free_user_var(user_var_entry *entry)
THD::THD():user_time(0), is_fatal_error(0),
last_insert_id_used(0),
insert_id_used(0), rand_used(0), in_lock_tables(0),
- global_read_lock(0), bootstrap(0)
+ global_read_lock(0), bootstrap(0), spcont(NULL)
{
host=user=priv_user=db=query=ip=0;
host_or_ip="unknown ip";
@@ -967,8 +968,9 @@ bool select_exists_subselect::send_data(List<Item> &items)
int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
{
List_iterator_fast<Item> li(list);
- List_iterator_fast<LEX_STRING> gl(var_list);
+ List_iterator_fast<my_var> gl(var_list);
Item *item;
+ my_var *mv;
LEX_STRING *ls;
if (var_list.elements != list.elements)
{
@@ -978,19 +980,38 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
unit=u;
while ((item=li++))
{
- ls= gl++;
- Item_func_set_user_var *xx = new Item_func_set_user_var(*ls,item);
- xx->fix_fields(thd,(TABLE_LIST*) thd->lex.select_lex.table_list.first,&item);
- xx->fix_length_and_dec();
- vars.push_back(xx);
+ mv=gl++;
+ ls= &mv->s;
+ if (mv->local)
+ {
+ (void)local_vars.push_back(new Item_splocal(mv->offset));
+ }
+ else
+ {
+ Item_func_set_user_var *xx = new Item_func_set_user_var(*ls,item);
+ xx->fix_fields(thd,(TABLE_LIST*) thd->lex.select_lex.table_list.first,&item);
+ xx->fix_length_and_dec();
+ vars.push_back(xx);
+ }
}
return 0;
}
bool select_dumpvar::send_data(List<Item> &items)
{
List_iterator_fast<Item_func_set_user_var> li(vars);
+ List_iterator_fast<Item_splocal> var_li(local_vars);
+ List_iterator_fast<my_var> my_li(var_list);
+ List_iterator_fast<Item> it(items);
Item_func_set_user_var *xx;
+ Item_splocal *yy;
+ Item *item;
+ my_var *zz;
DBUG_ENTER("send_data");
+ if (unit->offset_limit_cnt)
+ { // using limit offset,count
+ unit->offset_limit_cnt--;
+ DBUG_RETURN(0);
+ }
if (unit->offset_limit_cnt)
{ // Using limit offset,count
@@ -1002,8 +1023,21 @@ bool select_dumpvar::send_data(List<Item> &items)
my_error(ER_TOO_MANY_ROWS, MYF(0));
DBUG_RETURN(1);
}
- while ((xx=li++))
- xx->update();
+ while ((zz=my_li++) && (item=it++))
+ {
+ if (zz->local)
+ {
+ if ((yy=var_li++))
+ {
+ thd->spcont->set_item(yy->get_offset(), item);
+ }
+ }
+ else
+ {
+ if ((xx=li++))
+ xx->update();
+ }
+ }
DBUG_RETURN(0);
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index ccbd7a194f2..f316272ff0e 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -26,6 +26,7 @@
class Query_log_event;
class Load_log_event;
class Slave_log_event;
+class sp_rcontext;
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY };
@@ -551,6 +552,7 @@ public:
bool volatile killed;
bool prepare_command;
bool tmp_table_used;
+ sp_rcontext *spcont; // SP runtime context
/*
If we do a purge of binary logs, log index info of the threads
@@ -1018,13 +1020,22 @@ public:
bool send_eof();
};
+class my_var : public Sql_alloc {
+public:
+ LEX_STRING s;
+ bool local;
+ uint offset;
+ my_var (LEX_STRING& j, bool i, uint o) : s(j), local(i), offset(o) {}
+ ~my_var() {}
+};
class select_dumpvar :public select_result {
ha_rows row_count;
public:
- List<LEX_STRING> var_list;
+ List<my_var> var_list;
List<Item_func_set_user_var> vars;
- select_dumpvar(void) { var_list.empty(); vars.empty(); row_count=0;}
+ List<Item_splocal> local_vars;
+ select_dumpvar(void) { var_list.empty(); local_vars.empty(); vars.empty(); row_count=0;}
~select_dumpvar() {}
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_fields(List<Item> &list, uint flag) {return 0;}
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 779a109367c..5bd5e69cdb8 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -157,6 +157,7 @@ LEX *lex_start(THD *thd, uchar *buf,uint length)
{
LEX *lex= &thd->lex;
lex->next_state=STATE_START;
+ lex->buf= buf;
lex->end_of_query=(lex->ptr=buf)+length;
lex->yylineno = 1;
lex->select_lex.create_refs=lex->in_comment=0;
@@ -171,6 +172,8 @@ LEX *lex_start(THD *thd, uchar *buf,uint length)
lex->yacc_yyss=lex->yacc_yyvs=0;
lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE);
lex->sql_command=SQLCOM_END;
+ lex->sphead= NULL;
+ lex->spcont= NULL;
return lex;
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 60f48f293e4..5e3a0a5762b 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -21,6 +21,9 @@
class Table_ident;
class sql_exchange;
class LEX_COLUMN;
+class sp_head;
+class sp_instr;
+class sp_pcontext;
/*
The following hack is needed because mysql_yacc.cc does not define
@@ -72,6 +75,8 @@ enum enum_sql_command {
SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
SQLCOM_SHOW_COLUMN_TYPES, SQLCOM_SHOW_TABLE_TYPES, SQLCOM_SHOW_PRIVILEGES,
SQLCOM_HELP,
+ SQLCOM_CREATE_PROCEDURE, SQLCOM_CALL, SQLCOM_DROP_PROCEDURE,
+ SQLCOM_ALTER_PROCEDURE,
/* This should be the last !!! */
SQLCOM_END
@@ -419,6 +424,7 @@ typedef struct st_lex
SELECT_LEX_NODE *current_select;
/* list of all SELECT_LEX */
SELECT_LEX *all_selects_list;
+ uchar *buf; /* The beginning of string, used by SPs */
uchar *ptr,*tok_start,*tok_end,*end_of_query;
char *length,*dec,*change,*name;
char *backup_dir; /* For RESTORE/BACKUP */
@@ -477,6 +483,8 @@ typedef struct st_lex
uint slave_thd_opt;
CHARSET_INFO *charset;
char *help_arg;
+ sp_head *sphead;
+ sp_pcontext *spcont;
inline void uncacheable()
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index d69f95e7248..5d82877d1b3 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -26,6 +26,9 @@
#include "ha_innodb.h"
#endif
+#include "sp_head.h"
+#include "sp.h"
+
#ifdef HAVE_OPENSSL
/*
Without SSL the handshake consists of one packet. This packet
@@ -1570,7 +1573,7 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length)
** Execute command saved in thd and current_lex->sql_command
****************************************************************************/
-void
+int
mysql_execute_command(THD *thd)
{
int res= 0;
@@ -1602,7 +1605,7 @@ mysql_execute_command(THD *thd)
given and the table list says the query should not be replicated
*/
if (table_rules_on && tables && !tables_ok(thd,tables))
- DBUG_VOID_RETURN;
+ DBUG_RETURN(0);
#ifndef TO_BE_DELETED
/*
This is a workaround to deal with the shortcoming in 3.23.44-3.23.46
@@ -1637,7 +1640,7 @@ mysql_execute_command(THD *thd)
{
if (res < 0 || thd->net.report_error)
send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN : 0);
- DBUG_VOID_RETURN;
+ DBUG_RETURN(res);
}
}
}
@@ -1650,7 +1653,7 @@ mysql_execute_command(THD *thd)
!tables_ok(thd,tables))
#endif
)
- DBUG_VOID_RETURN;
+ DBUG_RETURN(0);
statistic_increment(com_stat[lex->sql_command],&LOCK_status);
switch (lex->sql_command) {
@@ -1689,7 +1692,7 @@ mysql_execute_command(THD *thd)
if (!(result= new select_send()))
{
send_error(thd, ER_OUT_OF_RESOURCES);
- DBUG_VOID_RETURN;
+ goto error;
}
else
thd->send_explain_fields(result);
@@ -1943,7 +1946,7 @@ mysql_execute_command(THD *thd)
find_real_table_in_list(tables->next, tables->db, tables->real_name))
{
net_printf(thd,ER_UPDATE_TABLE_USED,tables->real_name);
- DBUG_VOID_RETURN;
+ DBUG_RETURN(-1);
}
if (tables->next)
{
@@ -2024,7 +2027,7 @@ mysql_execute_command(THD *thd)
if (thd->locked_tables || thd->active_transaction())
{
send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
- break;
+ goto error;
}
{
LOCK_ACTIVE_MI;
@@ -2037,7 +2040,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_ALTER_TABLE:
#if defined(DONT_ALLOW_SHOW_COMMANDS)
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- break;
+ goto error;
#else
{
ulong priv=0;
@@ -2129,7 +2132,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_BINLOGS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- DBUG_VOID_RETURN;
+ goto error;
#else
{
if (check_global_access(thd, SUPER_ACL))
@@ -2142,7 +2145,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_CREATE:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- DBUG_VOID_RETURN;
+ goto error;
#else
{
if (check_db_used(thd, tables) ||
@@ -2214,7 +2217,7 @@ mysql_execute_command(THD *thd)
if (select_lex->item_list.elements != lex->value_list.elements)
{
send_error(thd,ER_WRONG_VALUE_COUNT);
- DBUG_VOID_RETURN;
+ goto error;
}
res= mysql_update(thd,tables,
select_lex->item_list,
@@ -2235,7 +2238,7 @@ mysql_execute_command(THD *thd)
if (select_lex->item_list.elements != lex->value_list.elements)
{
send_error(thd,ER_WRONG_VALUE_COUNT);
- DBUG_VOID_RETURN;
+ goto error;
}
{
const char *msg= 0;
@@ -2271,7 +2274,7 @@ mysql_execute_command(THD *thd)
if (select_lex->item_list.elements != lex->value_list.elements)
{
send_error(thd,ER_WRONG_VALUE_COUNT);
- DBUG_VOID_RETURN;
+ goto error;
}
res = mysql_insert(thd,tables,lex->field_list,lex->many_values,
select_lex->item_list, lex->value_list,
@@ -2310,8 +2313,7 @@ mysql_execute_command(THD *thd)
if (find_real_table_in_list(tables->next, tables->db, tables->real_name))
{
- net_printf(thd,ER_UPDATE_TABLE_USED,tables->real_name);
- DBUG_VOID_RETURN;
+ lex->select_lex.options |= OPTION_BUFFER_RESULT;
}
/* Skip first table, which is the table we are inserting in */
@@ -2471,7 +2473,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_DATABASES:
#if defined(DONT_ALLOW_SHOW_COMMANDS)
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- DBUG_VOID_RETURN;
+ goto error;
#else
if ((specialflag & SPECIAL_SKIP_SHOW_DB) &&
check_global_access(thd, SHOW_DB_ACL))
@@ -2505,7 +2507,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_LOGS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- DBUG_VOID_RETURN;
+ goto error;
#else
{
if (grant_option && check_access(thd, FILE_ACL, any_db))
@@ -2518,7 +2520,7 @@ mysql_execute_command(THD *thd)
/* FALL THROUGH */
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- DBUG_VOID_RETURN;
+ goto error;
#else
{
char *db=select_lex->db ? select_lex->db : thd->db;
@@ -2554,7 +2556,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_FIELDS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- DBUG_VOID_RETURN;
+ goto error;
#else
{
char *db=tables->db;
@@ -2579,7 +2581,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_KEYS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- DBUG_VOID_RETURN;
+ goto error;
#else
{
char *db=tables->db;
@@ -2949,16 +2951,113 @@ mysql_execute_command(THD *thd)
res= -1;
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
break;
+ case SQLCOM_CREATE_PROCEDURE:
+ if (!lex->sphead)
+ {
+ send_error(thd, ER_SP_NO_RECURSIVE_CREATE);
+ goto error;
+ }
+ else
+ {
+ res= lex->sphead->create(thd);
+ if (res != 0)
+ {
+ send_error(thd, ER_SP_ALREADY_EXISTS);
+ goto error;
+ }
+ send_ok(thd);
+ }
+ break;
+ case SQLCOM_CALL:
+ {
+ Item_string *s;
+ sp_head *sp;
+
+ s= (Item_string*)lex->value_list.head();
+ sp= sp_find_procedure(thd, s);
+ if (! sp)
+ {
+ send_error(thd, ER_SP_DOES_NOT_EXIST);
+ goto error;
+ }
+ else
+ {
+ // When executing substatements, they're assumed to send_error when
+ // it happens, but not to send_ok.
+ my_bool nsok= thd->net.no_send_ok;
+
+ thd->net.no_send_ok= TRUE;
+ res= sp->execute(thd);
+ thd->net.no_send_ok= nsok;
+
+ if (res == 0)
+ send_ok(thd);
+ else
+ goto error; // Substatement should already have sent error
+ }
+ }
+ break;
+ case SQLCOM_ALTER_PROCEDURE:
+ {
+ Item_string *s;
+ sp_head *sp;
+
+ s= (Item_string*)lex->value_list.head();
+ sp= sp_find_procedure(thd, s);
+ if (! sp)
+ {
+ send_error(thd, ER_SP_DOES_NOT_EXIST);
+ goto error;
+ }
+ else
+ {
+ /* QQ This is an no-op right now, since we haven't
+ put the characteristics in yet. */
+ send_ok(thd);
+ }
+ }
+ break;
+ case SQLCOM_DROP_PROCEDURE:
+ {
+ Item_string *s;
+ sp_head *sp;
+
+ s = (Item_string*)lex->value_list.head();
+ sp = sp_find_procedure(thd, s);
+ if (! sp)
+ {
+ send_error(thd, ER_SP_DOES_NOT_EXIST);
+ goto error;
+ }
+ else
+ {
+ String *name = s->const_string();
+
+ res= sp_drop_procedure(thd, name->c_ptr(), name->length());
+ if (res != 0)
+ {
+ send_error(thd, ER_SP_DROP_FAILED);
+ goto error;
+ }
+ send_ok(thd);
+ }
+ }
+ break;
default: /* Impossible */
send_ok(thd);
break;
}
thd->proc_info="query end"; // QQ
+
+ // We end up here if res == 0 and send_ok() has been done,
+ // or res != 0 and no send_error() has yet been done.
if (res < 0)
send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN : 0);
+ DBUG_RETURN(res);
error:
- DBUG_VOID_RETURN;
+ // We end up here if send_error() has already been done.
+ DBUG_RETURN(-1);
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index b9c0167bc05..269bd9143b8 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -35,6 +35,8 @@
#include "sql_acl.h"
#include "lex_symbol.h"
#include "item_create.h"
+#include "sp_head.h"
+#include "sp_pcontext.h"
#include <myisam.h>
#include <myisammrg.h>
@@ -121,6 +123,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token AVG_SYM
%token BEGIN_SYM
%token BINLOG_SYM
+%token CALL_SYM
%token CHANGE
%token CLIENT_SYM
%token COMMENT_SYM
@@ -201,6 +204,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token CONVERT_SYM
%token DATABASES
%token DATA_SYM
+%token DECLARE_SYM
%token DEFAULT
%token DELAYED_SYM
%token DELAY_KEY_WRITE_SYM
@@ -246,6 +250,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token INFILE
%token INNER_SYM
%token INNOBASE_SYM
+%token INOUT_SYM
%token INTO
%token IN_SYM
%token ISOLATION
@@ -260,6 +265,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token LIKE
%token LINES
%token LOCAL_SYM
+%token LOCATOR_SYM
%token LOG_SYM
%token LOGS_SYM
%token LONG_NUM
@@ -300,6 +306,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token OR
%token OR_OR_CONCAT
%token ORDER_SYM
+%token OUT_SYM
%token OUTER
%token OUTFILE
%token DUMPFILE
@@ -338,6 +345,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token SIMPLE_SYM
%token SHUTDOWN
%token SPATIAL_SYM
+%token SPECIFIC_SYM
%token SSL_SYM
%token STARTING
%token STATUS_SYM
@@ -526,6 +534,18 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token SQL_SMALL_RESULT
%token SQL_BUFFER_RESULT
+%token CURSOR_SYM
+%token ELSEIF_SYM
+%token ITERATE_SYM
+%token LEAVE_SYM
+%token LOOP_SYM
+%token REPEAT_SYM
+%token UNTIL_SYM
+%token WHILE_SYM
+%token ASENSITIVE_SYM
+%token INSENSITIVE_SYM
+%token SENSITIVE_SYM
+
%token ISSUER_SYM
%token SUBJECT_SYM
%token CIPHER_SYM
@@ -673,8 +693,12 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
union_clause union_list union_option
precision subselect_start opt_and
subselect_end select_var_list select_var_list_init help opt_len
+ statement
END_OF_INPUT
+%type <NONE> call sp_proc_stmts sp_proc_stmt
+%type <num> sp_decls sp_decl sp_decl_idents sp_opt_inout
+
%type <NONE>
'-' '+' '*' '/' '%' '(' ')'
',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
@@ -700,10 +724,16 @@ query:
| verb_clause END_OF_INPUT {};
verb_clause:
+ statement
+ | begin
+ ;
+
+/* Verb clauses, except begin */
+statement:
alter
| analyze
| backup
- | begin
+ | call
| change
| check
| commit
@@ -885,7 +915,405 @@ create:
lex->udf.returns=(Item_result) $7;
lex->udf.dl=$9.str;
}
- ;
+ | CREATE PROCEDURE ident
+ {
+ LEX *lex= Lex;
+
+ lex->spcont = new sp_pcontext();
+ lex->sphead = new sp_head(&$3, lex);
+ }
+ '(' sp_dparam_list ')'
+ {
+ Lex->spcont->set_params();
+ }
+ sp_proc_stmt
+ {
+ Lex->sql_command= SQLCOM_CREATE_PROCEDURE;
+ }
+ ;
+
+call:
+ CALL_SYM ident
+ {
+ LEX *lex = Lex;
+
+ lex->sql_command= SQLCOM_CALL;
+ lex->value_list.empty();
+ lex->value_list.push_back(
+ (Item*)new Item_string($2.str, $2.length, default_charset_info));
+ }
+ '(' sp_cparam_list ')' {}
+ ;
+
+/* CALL parameters */
+sp_cparam_list:
+ /* Empty */
+ | sp_cparams
+ ;
+
+sp_cparams:
+ sp_cparams ',' expr
+ {
+ Lex->value_list.push_back($3);
+ }
+ | expr
+ {
+ Lex->value_list.push_back($1);
+ }
+ ;
+
+/* SP parameter declaration list */
+sp_dparam_list:
+ /* Empty */
+ | sp_dparams
+ ;
+
+sp_dparams:
+ sp_dparams ',' sp_dparam
+ | sp_dparam
+ ;
+
+sp_dparam:
+ sp_opt_inout ident type sp_opt_locator
+ {
+ Lex->spcont->push(&$2,
+ (enum enum_field_types)$3,
+ (sp_param_mode_t)$1);
+ }
+ ;
+
+sp_opt_inout:
+ /* Empty */ { $$= sp_param_in; }
+ | IN_SYM { $$= sp_param_in; }
+ | OUT_SYM { $$= sp_param_out; }
+ | INOUT_SYM { $$= sp_param_inout; }
+ ;
+
+sp_opt_locator:
+ /* Empty */
+ | AS LOCATOR_SYM
+ ;
+
+sp_proc_stmts:
+ sp_proc_stmt ';'
+ | sp_proc_stmts sp_proc_stmt ';'
+ ;
+
+sp_decls:
+ /* Empty */
+ {
+ $$= 0;
+ }
+ | sp_decls sp_decl ';'
+ {
+ $$= $1 + $2;
+ }
+ ;
+
+sp_decl:
+ DECLARE_SYM sp_decl_idents type
+ {
+ LEX *lex= Lex;
+ uint max= lex->spcont->current_framesize();
+
+ for (uint i = max-$2 ; i < max ; i++)
+ {
+ lex->spcont->set_type(i, (enum enum_field_types)$3);
+ lex->spcont->set_isset(i, FALSE);
+ }
+ $$= $2;
+ }
+ ;
+
+sp_decl_idents:
+ ident
+ {
+ Lex->spcont->push(&$1, (enum_field_types)0, sp_param_in);
+ $$= 1;
+ }
+ | sp_decl_idents ',' ident
+ {
+ Lex->spcont->push(&$3, (enum_field_types)0, sp_param_in);
+ $$= $1 + 1;
+ }
+ ;
+
+sp_proc_stmt:
+ {
+ Lex->sphead->reset_lex(YYTHD);
+ }
+ statement
+ {
+ LEX *lex= Lex;
+
+ if (lex->sql_command == SQLCOM_SELECT && !lex->result)
+ {
+ send_error(YYTHD, ER_SP_BADSELECT);
+ YYABORT;
+ }
+ else
+ {
+ /* Don't add an instruction for empty SET statements.
+ ** (This happens if the SET only contained local variables,
+ ** which get their set instructions generated separately.)
+ */
+ if (lex->sql_command != SQLCOM_SET_OPTION ||
+ !lex->var_list.is_empty())
+ {
+ sp_instr_stmt *i= new sp_instr_stmt(lex->sphead->instructions());
+
+ i->set_lex(lex);
+ lex->sphead->add_instr(i);
+ }
+ lex->sphead->restore_lex(YYTHD);
+ }
+ }
+ | IF sp_if END IF {}
+ | CASE_SYM WHEN_SYM
+ {
+ Lex->sphead->m_simple_case= FALSE;
+ }
+ sp_case END CASE_SYM {}
+ | CASE_SYM expr WHEN_SYM
+ {
+ /* We "fake" this by using an anonymous variable which we
+ set to the expression. Note that all WHENs are evaluate
+ at the same frame level, so we then know that it's the
+ top-most variable in the frame. */
+ LEX *lex= Lex;
+ uint offset= lex->spcont->current_framesize();
+ sp_instr_set *i = new sp_instr_set(lex->sphead->instructions(),
+ offset, $2, MYSQL_TYPE_STRING);
+ LEX_STRING dummy;
+
+ dummy.str= (char *)"";
+ dummy.length= 0;
+ lex->spcont->push(&dummy, MYSQL_TYPE_STRING, sp_param_in);
+ lex->sphead->add_instr(i);
+ lex->sphead->m_simple_case= TRUE;
+ }
+ sp_case END CASE_SYM
+ {
+ Lex->spcont->pop();
+ }
+ | sp_labeled_control
+ {}
+ | { /* Unlabeled controls get a secret label. */
+ LEX *lex= Lex;
+
+ lex->spcont->push_label((char *)"", lex->sphead->instructions());
+ }
+ sp_unlabeled_control
+ {
+ LEX *lex= Lex;
+
+ lex->sphead->backpatch(lex->spcont->pop_label());
+ }
+ | LEAVE_SYM IDENT
+ {
+ LEX *lex= Lex;
+ sp_head *sp = lex->sphead;
+ sp_label_t *lab= lex->spcont->find_label($2.str);
+
+ if (! lab)
+ {
+ send_error(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE");
+ YYABORT;
+ }
+ else
+ {
+ sp_instr_jump *i= new sp_instr_jump(sp->instructions());
+
+ sp->push_backpatch(i, lab); /* Jumping forward */
+ sp->add_instr(i);
+ }
+ }
+ | ITERATE_SYM IDENT
+ {
+ LEX *lex= Lex;
+ sp_label_t *lab= lex->spcont->find_label($2.str);
+
+ if (! lab)
+ {
+ send_error(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE");
+ YYABORT;
+ }
+ else
+ {
+ uint ip= lex->sphead->instructions();
+ sp_instr_jump *i= new sp_instr_jump(ip, lab->ip); /* Jump back */
+
+ lex->sphead->add_instr(i);
+ }
+ }
+ ;
+
+sp_if:
+ expr THEN_SYM
+ {
+ sp_head *sp= Lex->sphead;
+ sp_pcontext *ctx= Lex->spcont;
+ uint ip= sp->instructions();
+ sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, $1);
+
+ sp->push_backpatch(i, ctx->push_label((char *)"", 0));
+ sp->add_instr(i);
+ }
+ sp_proc_stmts
+ {
+ sp_head *sp= Lex->sphead;
+ sp_pcontext *ctx= Lex->spcont;
+ uint ip= sp->instructions();
+ sp_instr_jump *i = new sp_instr_jump(ip);
+
+ sp->add_instr(i);
+ sp->backpatch(ctx->pop_label());
+ sp->push_backpatch(i, ctx->push_label((char *)"", 0));
+ }
+ sp_elseifs
+ {
+ LEX *lex= Lex;
+
+ lex->sphead->backpatch(lex->spcont->pop_label());
+ }
+ ;
+
+sp_elseifs:
+ /* Empty */
+ | ELSEIF_SYM sp_if
+ | ELSE sp_proc_stmts
+ ;
+
+sp_case:
+ expr THEN_SYM
+ {
+ sp_head *sp= Lex->sphead;
+ sp_pcontext *ctx= Lex->spcont;
+ uint ip= sp->instructions();
+ sp_instr_jump_if_not *i;
+
+ if (! sp->m_simple_case)
+ i= new sp_instr_jump_if_not(ip, $1);
+ else
+ { /* Simple case: <caseval> = <whenval> */
+ Item *var= (Item*) new Item_splocal(ctx->current_framesize()-1);
+ Item *expr= Item_bool_func2::eq_creator(var, $1);
+
+ i= new sp_instr_jump_if_not(ip, expr);
+ }
+ sp->push_backpatch(i, ctx->push_label((char *)"", 0));
+ sp->add_instr(i);
+ }
+ sp_proc_stmts
+ {
+ sp_head *sp= Lex->sphead;
+ sp_pcontext *ctx= Lex->spcont;
+ uint ip= sp->instructions();
+ sp_instr_jump *i = new sp_instr_jump(ip);
+
+ sp->add_instr(i);
+ sp->backpatch(ctx->pop_label());
+ sp->push_backpatch(i, ctx->push_label((char *)"", 0));
+ }
+ sp_whens
+ {
+ LEX *lex= Lex;
+
+ lex->sphead->backpatch(lex->spcont->pop_label());
+ }
+ ;
+
+sp_whens:
+ /* Empty */
+ | WHEN_SYM sp_case
+ | ELSE sp_proc_stmts
+ ;
+
+sp_labeled_control:
+ IDENT ':'
+ {
+ LEX *lex= Lex;
+ sp_label_t *lab= lex->spcont->find_label($1.str);
+
+ if (lab)
+ {
+ send_error(YYTHD, ER_SP_LABEL_REDEFINE);
+ YYABORT;
+ }
+ else
+ {
+ lex->spcont->push_label($1.str,
+ lex->sphead->instructions());
+ }
+ }
+ sp_unlabeled_control IDENT
+ {
+ LEX *lex= Lex;
+ sp_label_t *lab= lex->spcont->find_label($5.str);
+
+ if (! lab || strcasecmp($5.str, lab->name) != 0)
+ {
+ send_error(YYTHD, ER_SP_LABEL_MISMATCH);
+ YYABORT;
+ }
+ else
+ {
+ lex->spcont->pop_label();
+ lex->sphead->backpatch(lab);
+ }
+ }
+ ;
+
+sp_unlabeled_control:
+ BEGIN_SYM
+ sp_decls
+ sp_proc_stmts
+ END
+ { /* QQ This is just a dummy for grouping declarations and statements
+ together. No [[NOT] ATOMIC] yet, and we need to figure out how
+ make it coexist with the existing BEGIN COMMIT/ROLLBACK. */
+ Lex->spcont->pop($2);
+ }
+ | LOOP_SYM
+ sp_proc_stmts END LOOP_SYM
+ {
+ LEX *lex= Lex;
+ uint ip= lex->sphead->instructions();
+ sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */
+ sp_instr_jump *i = new sp_instr_jump(ip, lab->ip);
+
+ lex->sphead->add_instr(i);
+ }
+ | WHILE_SYM expr DO_SYM
+ {
+ LEX *lex= Lex;
+ sp_head *sp= lex->sphead;
+ uint ip= sp->instructions();
+ sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, $2);
+
+ /* Jumping forward */
+ sp->push_backpatch(i, lex->spcont->last_label());
+ sp->add_instr(i);
+ }
+ sp_proc_stmts END WHILE_SYM
+ {
+ LEX *lex= Lex;
+ uint ip= lex->sphead->instructions();
+ sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */
+ sp_instr_jump *i = new sp_instr_jump(ip, lab->ip);
+
+ lex->sphead->add_instr(i);
+ }
+ | REPEAT_SYM sp_proc_stmts UNTIL_SYM expr END REPEAT_SYM
+ {
+ LEX *lex= Lex;
+ uint ip= lex->sphead->instructions();
+ sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */
+ sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, $4, lab->ip);
+
+ lex->sphead->add_instr(i);
+ }
+ ;
create2:
'(' field_list ')' opt_create_table_options create3 {}
@@ -1457,8 +1885,27 @@ alter:
LEX *lex=Lex;
lex->sql_command=SQLCOM_ALTER_DB;
lex->name=$3.str;
- };
+ }
+ | ALTER PROCEDURE opt_specific ident
+ /* QQ Characteristics missing for now */
+ opt_restrict
+ {
+ LEX *lex=Lex;
+ /* This is essensially an no-op right now, since we haven't
+ put the characteristics in yet. */
+ lex->sql_command= SQLCOM_ALTER_PROCEDURE;
+ lex->value_list.empty();
+ lex->value_list.push_back(
+ (Item*)new Item_string($4.str, $4.length, default_charset_info));
+ }
+ ;
+
+opt_specific:
+ /* Empty */
+ |
+ SPECIFIC_SYM
+ ;
alter_list:
| alter_list_item
@@ -2134,6 +2581,8 @@ simple_expr:
{ $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);}
| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
{ $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);}
+ | REPEAT_SYM '(' expr ',' expr ')'
+ { $$= new Item_func_repeat($3,$5); }
| ATAN '(' expr ')'
{ $$= new Item_func_atan($3); }
| ATAN '(' expr ',' expr ')'
@@ -2989,10 +3438,29 @@ select_var_list:
| select_var_ident {}
;
-select_var_ident: '@' ident_or_text
+select_var_ident:
+ '@' ident_or_text
+ {
+ LEX *lex=Lex;
+ if (lex->result)
+ ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0));
+ else
+ YYABORT;
+ }
+ | ident_or_text
{
LEX *lex=Lex;
- if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
+ if (!lex->spcont)
+ YYABORT;
+ sp_pvar_t *t;
+ if (!(t=lex->spcont->find_pvar(&$1)))
+ {
+ send_error(lex->thd, ER_SYNTAX_ERROR);
+ YYABORT;
+ }
+ if (lex->result)
+ ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($1,1,t->offset));
+ else
YYABORT;
}
;
@@ -3077,7 +3545,16 @@ drop:
LEX *lex=Lex;
lex->sql_command = SQLCOM_DROP_FUNCTION;
lex->udf.name = $3;
- };
+ }
+ | DROP PROCEDURE ident opt_restrict
+ {
+ LEX *lex=Lex;
+ lex->sql_command = SQLCOM_DROP_PROCEDURE;
+ lex->value_list.empty();
+ lex->value_list.push_back(
+ (Item*)new Item_string($3.str, $3.length, default_charset_info));
+ }
+ ;
table_list:
@@ -3134,7 +3611,6 @@ replace:
}
insert_field_spec
{}
- {}
;
insert_lock_option:
@@ -3835,8 +4311,25 @@ order_ident:
simple_ident:
ident
{
- SELECT_LEX_NODE *sel=Select;
- $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,NullS,$1.str) : (Item*) new Item_ref(NullS,NullS,$1.str);
+ sp_pvar_t *spv;
+ LEX *lex = Lex;
+ sp_pcontext *spc = lex->spcont;
+
+ if (spc && (spv = spc->find_pvar(&$1)))
+ { /* We're compiling a stored procedure and found a variable */
+ if (lex->sql_command != SQLCOM_CALL && ! spv->isset)
+ {
+ send_error(YYTHD, ER_SP_UNINIT_VAR);
+ YYABORT;
+ }
+ else
+ $$ = (Item*) new Item_splocal(spv->offset);
+ }
+ else
+ {
+ SELECT_LEX_NODE *sel=Select;
+ $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,NullS,$1.str) : (Item*) new Item_ref(NullS,NullS,$1.str);
+ }
}
| ident '.' ident
{
@@ -4145,15 +4638,12 @@ opt_var_ident_type:
;
option_value:
- '@' ident_or_text equal expr
- {
- Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
- }
- | internal_variable_name equal set_expr_or_default
+ '@' ident_or_text equal expr
{
- LEX *lex=Lex;
- lex->var_list.push_back(new set_var(lex->option_type, $1, $3));
+ Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
}
+ | internal_or_splocal
+ {}
| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
{
LEX *lex=Lex;
@@ -4167,12 +4657,12 @@ option_value:
new Item_int((int32) $4)));
}
| CHAR_SYM SET opt_equal set_expr_or_default
- {
- LEX *lex=Lex;
- lex->var_list.push_back(new set_var(lex->option_type,
- find_sys_var("convert_character_set"),
- $4));
- }
+ {
+ LEX *lex=Lex;
+ lex->var_list.push_back(new set_var(lex->option_type,
+ find_sys_var("convert_character_set"),
+ $4));
+ }
| PASSWORD equal text_or_password
{
THD *thd=YYTHD;
@@ -4199,6 +4689,32 @@ internal_variable_name:
}
;
+internal_or_splocal:
+ ident equal set_expr_or_default
+ {
+ LEX *lex= Lex;
+ sp_pcontext *spc= lex->spcont;
+ sp_pvar_t *spv;
+
+ if (!spc || !(spv = spc->find_pvar(&$1)))
+ { /* Not an SP local variable */
+ sys_var *tmp= find_sys_var($1.str, $1.length);
+
+ if (!tmp)
+ YYABORT;
+ lex->var_list.push_back(new set_var(lex->option_type, tmp, $3));
+ }
+ else
+ { /* An SP local variable */
+ sp_instr_set *i= new sp_instr_set(lex->sphead->instructions(),
+ spv->offset, $3, spv->type);
+
+ lex->sphead->add_instr(i);
+ spv->isset= TRUE;
+ }
+ }
+ ;
+
isolation_types:
READ_SYM UNCOMMITTED_SYM { $$= ISO_READ_UNCOMMITTED; }
| READ_SYM COMMITTED_SYM { $$= ISO_READ_COMMITTED; }