mysql 1303,无法从另一个存储的例程中创建触发器-什么是另一个“存储的例程”?...

I'm trying to create a trigger in MySQL using PhpMyAdmin.

CREATE TRIGGER Update_Last_Transit_Status AFTER INSERT ON Delivery

FOR EACH ROW

BEGIN

UPDATE Transportation SET Status="Dispatched" WHERE

EXISTS (SELECT * FROM Transit, Route WHERE Transit.ID=Route.Transit_ID and

Route.Delivery_ID=Delivery.ID and

Transit.Transportation_ID=Transportation.ID) and

Status="In Branch"

END

It says:

MySQL said: #1303 - Can't create a TRIGGER from within another stored routine

I know this error has been addressed before, but this wasn't my intention at all.

Where is "another stored routine" here?

I don't intend to what the error message says.

EDIT:

There are no other triggers defined. There is however one procedure predefined:

begin

select user() as first_col;

select user() as first_col, now() as second_col;

select user() as first_col, now() as second_col, now() as third_col;

end

I don't know what it does, or why it is there, but it was there before.

解决方案

The trigger you show above is fine.

edit: When you create a trigger in the GUI of phpMyAdmin, you only need to enter the body of the trigger in the Definition pane, in other words the part BEGIN...END.

This is because phpMyAdmin is going to try to be clever and write the trigger header for you based on the other elements you enter (name, table, time, event).

Here's the right way to define a trigger in phpMyAdmin:

aK4aR.png

If you write the CREATE TRIGGER... header inside the body, it will confuse MySQL because it'll see CREATE TRIGGER... CREATE TRIGGER... BEGIN...END. This makes MySQL think you are defining a trigger whose first statement is CREATE TRIGGER.

As a side issue from your original question, I'd suggest some changes in the body of the trigger:

CREATE TRIGGER Update_Last_Transit_Status AFTER INSERT ON Delivery

FOR EACH ROW

BEGIN

UPDATE Transportation

INNER JOIN Transit ON Transit.Transportation_ID = Transportation.ID

INNER JOIN Route ON Transit.ID = Route.Transit_ID

SET Transportation.Status = 'Dispatched'

WHERE Route.Delivery_ID = NEW.ID

AND Transportation.Status = 'In Branch';

END

The changes:

Reference NEW.ID instead of Delivery.ID.

Use SQL-92 JOIN syntax instead of SQL-89 "comma style" joins.

Use multi-table UPDATE with joins, instead of EXISTS with correlated subquery.

Use single-quotes for strings instead of double-quotes.

Terminate the UPDATE statement with a semicolon.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的例程,用于在 rk3399 上创建一个字符设备,并利用 dma-buf 机制从网卡读取数据: ```c #include <linux/module.h> #include <linux/init.h> #include <linux/fs.h> #include <linux/miscdevice.h> #include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/dma-mapping.h> #define DEV_NAME "mydev" #define BUF_SIZE 4096 static struct miscdevice my_misc_device; static char *rx_buf; static dma_addr_t rx_buf_dma; static int my_open(struct inode *inode, struct file *file) { return 0; } static int my_release(struct inode *inode, struct file *file) { return 0; } static ssize_t my_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret = 0; if (count > BUF_SIZE) count = BUF_SIZE; if (copy_to_user(buf, rx_buf, count)) ret = -EFAULT; else ret = count; return ret; } static struct file_operations my_fops = { .owner = THIS_MODULE, .open = my_open, .release = my_release, .read = my_read, }; static int my_probe(struct platform_device *pdev) { struct net_device *dev = dev_get_by_name(&init_net, "eth0"); struct sk_buff *skb; struct scatterlist sg; int i, len; if (!dev) { pr_err("Failed to get eth0 device\n"); return -ENODEV; } skb = netdev_alloc_skb(dev, BUF_SIZE, GFP_KERNEL); if (!skb) { pr_err("Failed to allocate skb\n"); return -ENOMEM; } skb_reserve(skb, NET_SKB_PAD); skb_put(skb, BUF_SIZE); sg_init_one(&sg, skb->data, skb->len); if (dma_map_sg(&pdev->dev, &sg, 1, DMA_FROM_DEVICE) != 1) { pr_err("Failed to map SG to DMA buffer\n"); return -ENOMEM; } rx_buf = dma_alloc_coherent(&pdev->dev, BUF_SIZE, &rx_buf_dma, GFP_KERNEL); if (!rx_buf) { pr_err("Failed to allocate DMA buffer\n"); return -ENOMEM; } len = skb->len; for (i = 0; i < len; i += skb_tailroom(skb)) { skb_reset_tail_pointer(skb); skb_set_tail_pointer(skb, skb->len); sg_init_one(&sg, skb->data, skb_tailroom(skb)); dma_sync_sg_for_cpu(&pdev->dev, &sg, 1, DMA_FROM_DEVICE); memcpy(rx_buf + i, skb->data, skb_tailroom(skb)); dma_sync_sg_for_device(&pdev->dev, &sg, 1, DMA_FROM_DEVICE); } netdev_rx(skb); misc_register(&my_misc_device); return 0; } static int my_remove(struct platform_device *pdev) { misc_deregister(&my_misc_device); dma_free_coherent(&pdev->dev, BUF_SIZE, rx_buf, rx_buf_dma); return 0; } static struct platform_driver my_driver = { .driver = { .name = "my_driver", }, .probe = my_probe, .remove = my_remove, }; static int __init my_init(void) { my_misc_device.minor = MISC_DYNAMIC_MINOR; my_misc_device.name = DEV_NAME; my_misc_device.fops = &my_fops; return platform_driver_register(&my_driver); } static void __exit my_exit(void) { platform_driver_unregister(&my_driver); } module_init(my_init); module_exit(my_exit); MODULE_LICENSE("GPL"); ``` 以上代码仅供参考,实际使用时需要根据具体需求进行修改和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值