触发未知列' OLD'在'字段列表'

时间:2016-01-04 13:51:59

标签: mysql triggers

我试图在表UsefulResources上创建触发器。

触发器代码如下所示:

create trigger TBD_UsefulResources before delete
on UsefulResources for each row
begin
    Update SystemCycle set CurrentCycle=CurrentCycle+1;

    INSERT INTO DeletedPhysically (TableName, PKName, PKValue, DelAtRowCycle, RowCycle, Created)
    VALUES ("UsefulResources", "Ufr_GUID", OLD.Ufr_GUID, (Select CurrentCycle From `SystemCycle` where Syc_ID=1), (Select CurrentCycle From `SystemCycle` where Syc_ID=1), now());
end;

但是,如果我想通过mysql客户端执行它,我会收到以下错误:

mysql> create trigger TBD_UsefulResources before delete
    -> on UsefulResources for each row
    -> begin
    ->     Update SystemCycle set CurrentCycle=CurrentCycle+1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
mysql>
mysql>     INSERT INTO DeletedPhysically (TableName, PKName, PKValue, DelAtRowCycle, RowCycle, Created)
    ->     VALUES ("UsefulResources", "Ufr_GUID", OLD.Ufr_GUID, (Select CurrentCycle From `SystemCycle` where Syc_ID=1), (Select CurrentCycle From `SystemCycle` where Syc_ID=1), now());
ERROR 1054 (42S22): Unknown column 'OLD.Ufr_GUID' in 'field list'
mysql> end;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end' at line 1
mysql>

当我通过我的客户端执行创建触发器时,它在执行之前没有检查sql语法,它在服务器上工作正常。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

感谢@Mihai

像这样的代码解决了这个问题。我们需要更改结束行分隔符以停止每个“;”上的执行命令。这只是一个客户问题。当我通过#m.pyz import numpy as np cimport numpy as np from cython.view cimport array as cvarray cdef extern from 'cm.h': double per(double **marr,int rows,int cols); def test(double[:,::1] x): cdef int rows = x.shape[0] cdef int cols = x.shape[1] per(x,rows,cols) for i in range(rows): for j in range(cols): print x[i,j] 执行代码块时,它起作用,因为系统将整个查询视为一件事。

所以正确的代码应如下所示:

Error compiling Cython file:
------------------------------------------------------------
...
    double per(double **marr,int rows,int cols);

def test(double[:,::1] x):
    cdef int rows = x.shape[0]
    cdef int cols = x.shape[1]
    per(x,rows,cols)
        ^
------------------------------------------------------------

m.pyx:12:9: Cannot assign type 'double[:, ::1]' to 'double **'