1

我想计算后缀 smtp 服务器的别名使用情况。别名是通过 MySQL 使用后缀指令 ' virtual_alias_maps' in查询的main.cf

user = user
password = pwd
hosts = 127.0.0.1
dbname = dbname
query = SELECT destination FROM view_aliases WHERE email='%s'

查找工作顺利,没有什么可抱怨的。我现在需要的是,在 postfix 查找别名的任何时候增加一个计数器(MySQL 表中的列)。我试图像这样链接查询:

query = UPDATE view_aliases SET hitcount = hitcount+1 WHERE email='%s'; SELECT destination FROM view_aliases WHERE email='%s'

但这会导致错误消息和后缀查找问题:

Mar  7 11:04:01 host postfix/trivial-rewrite[32546]: warning: mysql query failed: 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 'SELECT destination FROM view_aliases WHERE email='mydomain.com'' at line 1

有没有办法像我需要的那样为后缀别名使用创建一个计数器?

更新:根据ethrbunny的提示,我尝试编写以下程序(这次是在测试数据库中):

DELIMITER & 
CREATE PROCEDURE mailbox(IN recipient VARCHAR(255)) 
BEGIN
    SELECT * FROM test WHERE email=recipient; 
    UPDATE test SET value=value+1 WHERE email=recipient; 
END & 
DELIMITER ;

当我调用该过程时,CALL mailbox('test@test.com')我从服务器收到一条线程堆栈溢出错误消息......

4

0 回答 0