1
/* Copyright (C) 2004-2005 MySQL AB
2
Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
3
4
This program is free software; you can redistribute it and/or modify
4
5
it under the terms of the GNU General Public License as published by
12
13
You should have received a copy of the GNU General Public License
13
14
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
19
#define MYSQL_LEX 1
299
An error handler that catches all non-OOM errors which can occur during
300
parsing of trigger body. Such errors are ignored and corresponding error
301
message is used to construct a more verbose error message which contains
302
name of problematic trigger. This error message is later emitted when
303
one tries to perform DML or some of DDL on this table.
304
Also, if possible, grabs name of the trigger being parsed so it can be
305
used to correctly drop problematic trigger.
307
class Deprecated_trigger_syntax_handler : public Internal_error_handler
311
char m_message[MYSQL_ERRMSG_SIZE];
312
LEX_STRING *m_trigger_name;
316
Deprecated_trigger_syntax_handler() : m_trigger_name(NULL) {}
318
virtual bool handle_error(uint sql_errno, const char *message,
319
MYSQL_ERROR::enum_warning_level level, THD *thd)
321
if (sql_errno != EE_OUTOFMEMORY &&
322
sql_errno != ER_OUT_OF_RESOURCES)
325
m_trigger_name= &thd->lex->spname->m_name;
327
my_snprintf(m_message, sizeof(m_message),
328
"Trigger '%s' has an error in its body: '%s'",
329
m_trigger_name->str, message);
331
my_snprintf(m_message, sizeof(m_message),
332
"Unknown trigger has an error in its body: '%s'",
339
LEX_STRING *get_trigger_name() { return m_trigger_name; }
340
char *get_error_message() { return m_message; }
296
345
Create or drop trigger for table.
298
347
@param thd current thread context (including trigger definition in LEX)
575
624
LEX_STRING *trg_connection_cl_name;
576
625
LEX_STRING *trg_db_cl_name;
627
if (check_for_broken_triggers())
579
630
/* Trigger must be in the same schema as target table. */
580
631
if (my_strcasecmp(table_alias_charset, table->s->db.str,
848
899
@param path char buffer of size FN_REFLEN to be used
849
900
for constructing path to .TRN file.
850
901
@param db trigger's database name
851
@param table_name trigger's name
902
@param trigger_name trigger's name
1312
1363
lex_start(thd);
1313
1364
thd->spcont= NULL;
1315
if (parse_sql(thd, & parser_state, creation_ctx))
1317
/* Currently sphead is always deleted in case of a parse error */
1318
DBUG_ASSERT(lex.sphead == 0);
1319
goto err_with_lex_cleanup;
1366
Deprecated_trigger_syntax_handler error_handler;
1367
thd->push_internal_handler(&error_handler);
1368
bool parse_error= parse_sql(thd, & parser_state, creation_ctx);
1369
thd->pop_internal_handler();
1322
1372
Not strictly necessary to invoke this method here, since we know
1323
1373
that we've parsed CREATE TRIGGER and not an
1329
1379
lex.set_trg_event_type_for_tables();
1383
if (!triggers->m_has_unparseable_trigger)
1384
triggers->set_parse_error_message(error_handler.get_error_message());
1385
/* Currently sphead is always set to NULL in case of a parse error */
1386
DBUG_ASSERT(lex.sphead == 0);
1387
if (error_handler.get_trigger_name())
1389
LEX_STRING *trigger_name;
1390
const LEX_STRING *orig_trigger_name= error_handler.get_trigger_name();
1392
if (!(trigger_name= alloc_lex_string(&table->mem_root)) ||
1393
!(trigger_name->str= strmake_root(&table->mem_root,
1394
orig_trigger_name->str,
1395
orig_trigger_name->length)))
1396
goto err_with_lex_cleanup;
1398
trigger_name->length= orig_trigger_name->length;
1400
if (triggers->names_list.push_back(trigger_name,
1402
goto err_with_lex_cleanup;
1407
The Table_triggers_list is not constructed as a list of
1408
trigger objects as one would expect, but rather of lists of
1409
properties of equal length. Thus, even if we don't get the
1410
trigger name, we still fill all in all the lists with
1411
placeholders as we might otherwise create a skew in the
1412
lists. Obviously, this has to be refactored.
1414
LEX_STRING *empty= alloc_lex_string(&table->mem_root);
1416
goto err_with_lex_cleanup;
1418
empty->str= const_cast<char*>("");
1420
if (triggers->names_list.push_back(empty, &table->mem_root))
1421
goto err_with_lex_cleanup;
1331
1427
lex.sphead->set_info(0, 0, &lex.sp_chistics, (ulong) *trg_sql_mode);
1333
1429
int event= lex.trg_chistics.event;
1369
1465
if (triggers->names_list.push_back(&lex.sphead->m_name,
1370
1466
&table->mem_root))
1371
goto err_with_lex_cleanup;
1467
goto err_with_lex_cleanup;
1373
1469
if (!(on_table_name= alloc_lex_string(&table->mem_root)))
1374
1470
goto err_with_lex_cleanup;
1394
1490
char fname[NAME_LEN + 1];
1395
1491
DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->db, db) ||
1396
1492
(check_n_cut_mysql50_prefix(db, fname, sizeof(fname)) &&
1397
!my_strcasecmp(table_alias_charset, lex.query_tables->db, fname))) &&
1398
(!my_strcasecmp(table_alias_charset, lex.query_tables->table_name,
1493
!my_strcasecmp(table_alias_charset, lex.query_tables->db, fname))));
1494
DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->table_name, table_name) ||
1400
1495
(check_n_cut_mysql50_prefix(table_name, fname, sizeof(fname)) &&
1401
1496
!my_strcasecmp(table_alias_charset, lex.query_tables->table_name, fname))));
1681
1776
while ((trigger= it_name++))
1779
Trigger, which body we failed to parse during call
1780
Table_triggers_list::check_n_load(), might be missing name.
1781
Such triggers have zero-length name and are skipped here.
1783
if (trigger->length == 0)
1683
1785
if (rm_trigname_file(path, db, trigger->str))
2183
Signals to the Table_triggers_list that a parse error has occured when
2184
reading a trigger from file. This makes the Table_triggers_list enter an
2185
error state flagged by m_has_unparseable_trigger == true. The error message
2186
will be used whenever a statement invoking or manipulating triggers is
2187
issued against the Table_triggers_list's table.
2189
@param error_message The error message thrown by the parser.
2191
void Table_triggers_list::set_parse_error_message(char *error_message)
2193
m_has_unparseable_trigger= true;
2194
strcpy(m_parse_error_message, error_message);
2073
2199
Trigger BUG#14090 compatibility hook.
2075
2201
@param[in,out] unknown_key reference on the line with unknown