| 798 | */ |
| 799 | |
| 800 | static void build_trig_stmt_query(THD *thd, TABLE_LIST *tables, |
| 801 | String *stmt_query, String *trigger_def, |
| 802 | LEX_CSTRING *trg_definer, |
| 803 | char trg_definer_holder[]) |
| 804 | { |
| 805 | LEX_CSTRING stmt_definition; |
| 806 | LEX *lex= thd->lex; |
| 807 | size_t prefix_trimmed, suffix_trimmed; |
| 808 | size_t original_length; |
| 809 | |
| 810 | /* |
| 811 | Create a query with the full trigger definition. |
| 812 | The original query is not appropriate, as it can miss the DEFINER=XXX part. |
| 813 | */ |
| 814 | stmt_query->append(STRING_WITH_LEN("CREATE ")); |
| 815 | |
| 816 | trigger_def->copy(*stmt_query); |
| 817 | |
| 818 | if (lex->create_info.or_replace()) |
| 819 | stmt_query->append(STRING_WITH_LEN("OR REPLACE ")); |
| 820 | |
| 821 | if (lex->sphead->suid() != SP_IS_NOT_SUID) |
| 822 | { |
| 823 | /* SUID trigger */ |
| 824 | lex->definer->set_lex_string(trg_definer, trg_definer_holder); |
| 825 | append_definer(thd, stmt_query, &lex->definer->user, &lex->definer->host); |
| 826 | append_definer(thd, trigger_def, &lex->definer->user, &lex->definer->host); |
| 827 | } |
| 828 | else |
| 829 | { |
| 830 | *trg_definer= empty_clex_str; |
| 831 | } |
| 832 | |
| 833 | |
| 834 | /* Create statement for binary logging */ |
| 835 | stmt_definition.str= lex->stmt_definition_begin; |
| 836 | stmt_definition.length= (lex->stmt_definition_end - |
| 837 | lex->stmt_definition_begin); |
| 838 | original_length= stmt_definition.length; |
| 839 | trim_whitespace(thd->charset(), &stmt_definition, &prefix_trimmed); |
| 840 | suffix_trimmed= original_length - stmt_definition.length - prefix_trimmed; |
| 841 | |
| 842 | stmt_query->append(stmt_definition.str, stmt_definition.length); |
| 843 | |
| 844 | /* Create statement for storing trigger (without trigger order) */ |
| 845 | if (lex->trg_chistics.ordering_clause == TRG_ORDER_NONE) |
| 846 | { |
| 847 | /* |
| 848 | Not that here stmt_definition doesn't end with a \0, which is |
| 849 | normally expected from a LEX_CSTRING |
| 850 | */ |
| 851 | trigger_def->append(stmt_definition.str, stmt_definition.length); |
| 852 | } |
| 853 | else |
| 854 | { |
| 855 | /* Copy data before FOLLOWS/PRECEDES trigger_name */ |
| 856 | trigger_def->append(stmt_definition.str, |
| 857 | (lex->trg_chistics.ordering_clause_begin - |
no test coverage detected