sp.h 3.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* -*- 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_

21
// Return codes from sp_create_*, sp_drop_*, and sp_show_*:
22 23 24 25 26 27 28
#define SP_OK                 0
#define SP_KEY_NOT_FOUND     -1
#define SP_OPEN_TABLE_FAILED -2
#define SP_WRITE_ROW_FAILED  -3
#define SP_DELETE_ROW_FAILED -4
#define SP_GET_FIELD_FAILED  -5
#define SP_PARSE_ERROR       -6
29
#define SP_INTERNAL_ERROR    -7
30
#define SP_NO_DB_ERROR       -8
31
#define SP_BAD_IDENTIFIER    -9
32
#define SP_BODY_TOO_LONG    -10
33

34 35 36 37
/* Drop all routines in database 'db' */
int
sp_drop_db_routines(THD *thd, char *db);

38
sp_head *
39
sp_find_procedure(THD *thd, sp_name *name, bool cache_only = 0);
40

41 42 43
int
sp_exists_routine(THD *thd, TABLE_LIST *procs, bool any, bool no_error);

44
int
45
sp_create_procedure(THD *thd, sp_head *sp);
46 47

int
48
sp_drop_procedure(THD *thd, sp_name *name);
49

50

unknown's avatar
unknown committed
51
int
52
sp_update_procedure(THD *thd, sp_name *name, st_sp_chistics *chistics);
unknown's avatar
unknown committed
53 54

int
55
sp_show_create_procedure(THD *thd, sp_name *name);
unknown's avatar
unknown committed
56 57

int
58
sp_show_status_procedure(THD *thd, const char *wild);
unknown's avatar
unknown committed
59

60
sp_head *
61
sp_find_function(THD *thd, sp_name *name, bool cache_only = 0);
62 63

int
64
sp_create_function(THD *thd, sp_head *sp);
65 66

int
67
sp_drop_function(THD *thd, sp_name *name);
68

unknown's avatar
unknown committed
69
int
70
sp_update_function(THD *thd, sp_name *name, st_sp_chistics *chistics);
unknown's avatar
unknown committed
71 72

int
73
sp_show_create_function(THD *thd, sp_name *name);
unknown's avatar
unknown committed
74 75

int
76
sp_show_status_function(THD *thd, const char *wild);
unknown's avatar
unknown committed
77

78

79
/*
80 81 82
  Procedures for pre-caching of stored routines and building table list
  for prelocking.
*/
83 84
void sp_get_prelocking_info(THD *thd, bool *need_prelocking, 
                            bool *first_no_prelocking);
85
void sp_add_used_routine(LEX *lex, Query_arena *arena,
86
                         sp_name *rt, char rt_type);
87
void sp_remove_not_own_routines(LEX *lex);
88
void sp_update_sp_used_routines(HASH *dst, HASH *src);
89 90
bool sp_cache_routines_and_add_tables(THD *thd, LEX *lex, 
                                      bool first_no_prelock);
91 92 93 94 95 96
void sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex,
                                               LEX *aux_lex);
void sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex,
                                         Table_triggers_list *triggers);

extern "C" byte* sp_sroutine_key(const byte *ptr, uint *plen, my_bool first);
97

98 99 100 101 102 103 104
/*
  Routines which allow open/lock and close mysql.proc table even when
  we already have some tables open and locked.
*/
TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup);
void close_proc_table(THD *thd, Open_tables_state *backup);

105 106 107 108 109 110
//
// Utilities...
//

// Do a "use newdb". The current db is stored at olddb.
// If newdb is the same as the current one, nothing is changed.
111
// dbchangedp is set to true if the db was actually changed.
112 113
int
sp_use_new_db(THD *thd, char *newdb, char *olddb, uint olddbmax,
114
	      bool no_access_check, bool *dbchangedp);
115

116
#endif /* _SP_H_ */