【发布时间】:2016-06-24 00:40:01
【问题描述】:
我正在使用 Laravel 迁移来创建/管理我的所有数据库脚本,并且我有一个用于创建触发器的迁移。
在这里
DB::unprepared(
'create trigger update_points_aft_insert
after insert on votes
for each row
begin
declare u_id integer;
if NEW.votable_type = "App\\Comment" then
set u_id = (select user_id from comments where id = NEW.votable_id);
update users set points=points+NEW.vote where id = u_id;
end if;
end;'
);
问题是当我运行show triggers; 我得到:
*************************** 1. row ***************************
Trigger: update_points_aft_insert
Event: INSERT
Table: votes
Statement: begin
declare u_id integer;
if NEW.votable_type = "AppComment" then
set u_id = (select user_id from comments where id = NEW.votable_id);
update users set points=points+NEW.vote where id = u_id;
end if;
end
Timing: AFTER
Created: NULL
sql_mode: NO_ENGINE_SUBSTITUTION
Definer: root@localhost
character_set_client: utf8 collation_connection:utf8_unicode_ci 数据库整理:latin1_swedish_ci
如您所见,mysql 读取的是if NEW.votable_type = "AppComment" then 而不是我想要的:if NEW.votable_type = "App\Comment" then ...
有谁知道我如何告诉 mysql 读取反斜杠?
编辑:有效的是使用三个反斜杠
【问题讨论】:
-
你试过三引号
if NEW.votable_type = """App\\Comment""" then -
现在试了一下,结果是mysql:
if NEW.votable_type = ""AppComment"" then
标签: php mysql laravel laravel-5