在触发器中测试空值的正确方法是什么?

时间:2016-07-11 00:42:29

标签: mysql

我有一个触发器设置在更新时触发。我之前正在使用旧版本的mysql,因为它支持引发错误,因此我调用了一个不存在的" raise_error"结束触发器的函数。如果字段不为空,我试图阻止更新字段。我的触发器如下所示:

Sub Test()
Dim Wkb As Workbook

Set Wkb = ActiveWorkbook
notepadID = Shell("C:\Program Files\Default Company Name\TestInstaller\TestApp.exe")

SendKeys "admin", True
SendKeys "{TAB}", True
SendKeys "nothing", True

SendKeys "{ENTER}", True
SendKeys "{ENTER}", True
SendKeys "{LEFT}", True
SendKeys ("^C")

Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(0, 0).Select
Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.PasteSpecial
Application.Wait (Now + TimeValue("0:00:01"))
AppActivate "Inventory"
SendKeys "{TAB}", True
SendKeys ("^C")
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste

End Sub

这不起作用,因为以下成功完成:

Sub Test()
Dim Wkb As Workbook

Set Wkb = ActiveWorkbook
notepadID = Shell("C:\Program Files\Default Company Name\TestInstaller\TestApp.exe")

SendKeys "admin", True
SendKeys "{TAB}", True
SendKeys "nothing", True

SendKeys "{ENTER}", True
SendKeys "{ENTER}", True



Dim i As Integer
Dim j As Integer

i = 1
j = 1


SendKeys ("^C")
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(1, 1).Select
'Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.PasteSpecial
Application.Wait (Now + TimeValue("0:00:01"))
AppActivate "Inventory"
SendKeys "{TAB}", True



If Not IsEmpty(ActiveCell.Value) Then
Do While Cells(i, j).Value = Cells(i, j + 3).Value
j = j + 1
SendKeys ("^C")
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(i, j).Select
'Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.PasteSpecial
Application.Wait (Now + TimeValue("0:00:01"))
AppActivate "Inventory"
SendKeys "{TAB}", True

If i = 4 Then
i = i = 0
j = j + 1
End If
Loop
End If
End Sub

出了什么问题?

1 个答案:

答案 0 :(得分:0)

使用mysql的null-safe comparison operator <=>,它将两个空值视为“相等”:

IF (new.Value <=> old.Value AND old.Value IS NOT NULL) THEN
    CALL raise_error;
END IF;
相关问题