mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
0521fb5444
Expanded the mysql.proc table, reworked the find/create/drop functions completely, added new functions for FUNCTIONs (lotta functions here :), got rid of some unnecessary use of Item_strings while at it. Extended the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs coexist with UDFs. Can now CREATE and DROP FUNCTIONs. Invoking yet to come... Docs/sp-implemented.txt: Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions. include/mysqld_error.h: New error message for misuse of RETURN. mysql-test/install_test_db.sh: Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE. mysql-test/r/sp.result: New test for creating and dropping FUNCTIONS. mysql-test/t/sp.test: New test for creating and dropping FUNCTIONS. scripts/mysql_install_db.sh: Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE. sql/lex.h: De-UDFed some symbol names, as they are now used for SPs as well. Added RETURN_SYM. sql/share/czech/errmsg.txt: New error message for misuse of RETURN. sql/share/danish/errmsg.txt: New error message for misuse of RETURN. sql/share/dutch/errmsg.txt: New error message for misuse of RETURN. sql/share/english/errmsg.txt: New error message for misuse of RETURN. sql/share/estonian/errmsg.txt: New error message for misuse of RETURN. sql/share/french/errmsg.txt: New error message for misuse of RETURN. sql/share/german/errmsg.txt: New error message for misuse of RETURN. sql/share/greek/errmsg.txt: New error message for misuse of RETURN. sql/share/hungarian/errmsg.txt: New error message for misuse of RETURN. sql/share/italian/errmsg.txt: New error message for misuse of RETURN. sql/share/japanese/errmsg.txt: New error message for misuse of RETURN. sql/share/korean/errmsg.txt: New error message for misuse of RETURN. sql/share/norwegian-ny/errmsg.txt: New error message for misuse of RETURN. sql/share/norwegian/errmsg.txt: New error message for misuse of RETURN. sql/share/polish/errmsg.txt: New error message for misuse of RETURN. sql/share/portuguese/errmsg.txt: New error message for misuse of RETURN. sql/share/romanian/errmsg.txt: New error message for misuse of RETURN. sql/share/russian/errmsg.txt: New error message for misuse of RETURN. sql/share/serbian/errmsg.txt: New error message for misuse of RETURN. sql/share/slovak/errmsg.txt: New error message for misuse of RETURN. sql/share/spanish/errmsg.txt: New error message for misuse of RETURN. sql/share/swedish/errmsg.txt: New error message for misuse of RETURN. sql/share/ukrainian/errmsg.txt: New error message for misuse of RETURN. sql/sp.cc: Major rehack to accomodate FUNCTIONs, and to make it easier to add future in-memory cache of prepared SPs. sql/sp.h: Major rehack to accomodate FUNCTIONs, and to make it easier to add future in-memory cache of prepared SPs. sql/sp_head.cc: Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.) sql/sp_head.h: Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.) sql/sql_lex.h: New stored FUNCTION commands. sql/sql_parse.cc: Added FUNCTION support ("drop" merged with the old UDF code), and made some additional changes for better error handling (following the sp.cc rehacking). sql/sql_yacc.yy: Some former UDF specific symbols renamed. Added CREATE FUNCTION parsing. DROP FUNCTION had to be partly merged with the old UDF code, because of the similar syntax. RETURN statement added, but still a no-op.
322 lines
6.5 KiB
C++
322 lines
6.5 KiB
C++
/* -*- 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>
|
|
|
|
// Values for the type enum. This reflects the order of the enum declaration
|
|
// in the CREATE TABLE command.
|
|
#define TYPE_ENUM_FUNCTION 1
|
|
#define TYPE_ENUM_PROCEDURE 2
|
|
|
|
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:
|
|
|
|
int m_type; // TYPE_ENUM_FUNCTION or TYPE_ENUM_PROCEDURE
|
|
enum enum_field_types m_returns; // For FUNCTIONs only
|
|
my_bool m_simple_case; // TRUE if parsing simple case, FALSE otherwise
|
|
List<char *> 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 *);
|
|
|
|
char *name(uint *lenp = 0) const
|
|
{
|
|
String *n= m_name->const_string();
|
|
|
|
if (lenp)
|
|
*lenp= n->length();
|
|
return n->c_ptr();
|
|
}
|
|
|
|
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 backpatching
|
|
|
|
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_ */
|