Hallo morphium,
> SELECT
> IF (
> SELECT COUNT(*) FROM mail_virtual WHERE email = '%s' > 0,
> SELECT greylist FROM mail_users WHERE email = (SELECT destination
> FROM mail_virtual WHERE email = '%s'),
> SELECT greylist FROM mail_users WHERE email = (SELECT destination
> FROM mail_virtual WHERE iscatchall = 1 AND email LIKE
> CONCAT('%@',SUBSTRING_INDEX('%s', '@', -1)))
> )
>
wenn ich das so - incl. der Zeilenumbrüche - übertrage, erhalte ich:
" #1064 - 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 COUNT(*) FROM mail_virtual WHERE email = '[email protected]' > 0, SELEC'
at line 3"
Ich habe die drei Expressions mal je mit einfachen Klammern umschlossen und
zumindest im phpMyAdmin mit Emailadressen statt %s funktioniert es:
SELECT IF (
(SELECT COUNT(*) FROM mail_virtual WHERE email = '[email protected]') >
0,
(SELECT policy_greylist FROM mail_users WHERE email = (SELECT
destination FROM mail_virtual WHERE email = '[email protected]')),
(SELECT policy_greylist FROM mail_users WHERE email = (SELECT
destination FROM mail_virtual WHERE iscatchall = 1 AND email LIKE
CONCAT('%@',SUBSTRING_INDEX('[email protected]', '@', -1))))
)
Abgelegt in einer Datei, aufgerufen mit 'postmap -q [email protected]
mysql:/datei' tut es nicht ;-(
ns3:~# postmap -q [email protected] mysql:/root/mysql-morphium
postmap: fatal: db_common_parse: /root/mysql-morphium: Invalid query template:
SELECT IF ( (SELECT COUNT(*) FROM mail_virtual WHERE email = '%s') > 0, (SELECT
policy_greylist FROM mail_users WHERE email = (SELECT destination FROM
mail_virtual WHERE email = '%s')), (SELECT policy_greylist FROM mail_users
WHERE email = (SELECT destination FROM mail_virtual WHERE iscatchall = 1 AND
email LIKE CONCAT('%@',SUBSTRING_INDEX('%s', '@', -1)))))
Das bringt mich zum 'man mysql_table' und dort finde ich u.a.:
%% This is replaced by a literal '%' character.
%d When the input key is an address of the form user@domain, %d is replaced
by
the SQL quoted domain part of the address. Otherwise,
the query is sup‐
pressed and returns no results.
Soll das %@ jetzt %%@ werden und kann man im CONCAT nun mittest des %d
optimieren? Der Versuch mit dem %%@ brachte :
postmap -q [email protected] mysql:/root/mysql-morphium
postmap: warning: table "mysql:/root/mysql-morphium": empty lookup result for:
"[email protected]" -- ignored
Also gleich beides:
SELECT IF (
(SELECT COUNT(*) FROM mail_virtual WHERE email = '%s') > 0,
(SELECT policy_greylist FROM mail_users WHERE email = (SELECT
destination FROM mail_virtual WHERE email = '%s')),
(SELECT policy_greylist FROM mail_users WHERE email = (SELECT
destination FROM mail_virtual WHERE iscatchall = 1 AND email LIKE
CONCAT('%%@','%d')))
)
Und schon geht’s fast.
Zumindest wird die gesetzte policy in allen erdenklichen Kombinationen von
policy und greylist korrekt geliefert, sofern sie gesetzt ist.
Was postfix nun nicht mag, ist ein leeres Resultat und leider kommt das als
Ergebnis, wenn die policy nicht gesetzt ist.
ns3:~# postmap -q [email protected] mysql:/root/mysql-morphium
postmap: warning: table "mysql:/root/mysql-morphium": empty lookup result for:
"[email protected]" -- ignored
Wenn ich mittels postmap mit meiner ursprünglichen und einfachen Abfrage gegen
die nicht gesetzte policy teste liefert postmap korrekt einen exit 0, also
liegt die neue Ausgabe in der neuen Abfrage begründet.
Offenbar nur noch ein bisschen Feintuning.
Mit freundlichen Grüßen / Kind regards
Ronny Seffner
--
Ronny Seffner | Alter Viehweg 1 | 01665 Klipphausen
www.seffner.de | [email protected] | +49 35245 72950
_______________________________________________
Lug-dd maillist - [email protected]
https://ssl.schlittermann.de/mailman/listinfo/lug-dd