Fix transport_maps function for non-existent domains v0.6.x
authormartin f. krafft <madduck@madduck.net>
Sun, 15 Apr 2012 17:51:00 +0200
branchv0.6.x
changeset 550 867d950ce7b7
parent 549 44a808af6cf4
child 551 62f2daff853e
Fix transport_maps function for non-existent domains The postfix_transport_maps function had a bug causing 2012-04-15 17:40:22 CEST LOG: statement: SELECT transport FROM postfix_transport_map('logcheck', 'domine.madduck.net'); 2012-04-15 17:40:22 CEST ERROR: query returned no rows when the domain was not in the database. This would make did be NULL and make the query fail. This patch moves the tid query until after a check for did. If the latter is NULL, the function RETURNs (rather than fails).
pgsql/create_tables-dovecot-1.2.x.pgsql
pgsql/create_tables.pgsql
pgsql/update_tables_0.5.x-0.6-dovecot-1.2.x.pgsql
pgsql/update_tables_0.5.x-0.6.pgsql
--- a/pgsql/create_tables-dovecot-1.2.x.pgsql	Sun Apr 15 17:36:26 2012 +0200
+++ b/pgsql/create_tables-dovecot-1.2.x.pgsql	Sun Apr 15 17:51:00 2012 +0200
@@ -571,9 +571,16 @@
         record recipient_transport;
         recipient varchar(320) := localpart || '@' || the_domain;
         did bigint := (SELECT gid FROM domain_name WHERE domainname = the_domain);
-        transport_id bigint := (SELECT tid FROM users
-                                  WHERE gid = did AND local_part = localpart);
+        transport_id bigint;
     BEGIN
+        IF did IS NULL THEN
+            RETURN;
+        END IF;
+
+        SELECT tid INTO transport_id
+          FROM users
+         WHERE gid = did AND local_part = localpart;
+
         IF transport_id IS NULL THEN
             SELECT tid INTO STRICT transport_id
               FROM domain_data
--- a/pgsql/create_tables.pgsql	Sun Apr 15 17:36:26 2012 +0200
+++ b/pgsql/create_tables.pgsql	Sun Apr 15 17:51:00 2012 +0200
@@ -549,9 +549,16 @@
         record recipient_transport;
         recipient varchar(320) := localpart || '@' || the_domain;
         did bigint := (SELECT gid FROM domain_name WHERE domainname = the_domain);
-        transport_id bigint := (SELECT tid FROM users
-                                  WHERE gid = did AND local_part = localpart);
+        transport_id bigint;
     BEGIN
+        IF did IS NULL THEN
+            RETURN;
+        END IF;
+
+        SELECT tid INTO transport_id
+          FROM users
+         WHERE gid = did AND local_part = localpart;
+
         IF transport_id IS NULL THEN
             SELECT tid INTO STRICT transport_id
               FROM domain_data
--- a/pgsql/update_tables_0.5.x-0.6-dovecot-1.2.x.pgsql	Sun Apr 15 17:36:26 2012 +0200
+++ b/pgsql/update_tables_0.5.x-0.6-dovecot-1.2.x.pgsql	Sun Apr 15 17:51:00 2012 +0200
@@ -496,9 +496,16 @@
         record recipient_transport;
         recipient varchar(320) := localpart || '@' || the_domain;
         did bigint := (SELECT gid FROM domain_name WHERE domainname = the_domain);
-        transport_id bigint := (SELECT tid FROM users
-                                  WHERE gid = did AND local_part = localpart);
+        transport_id bigint;
     BEGIN
+        IF did IS NULL THEN
+            RETURN;
+        END IF;
+
+        SELECT tid INTO transport_id
+          FROM users
+         WHERE gid = did AND local_part = localpart;
+
         IF transport_id IS NULL THEN
             SELECT tid INTO STRICT transport_id
               FROM domain_data
--- a/pgsql/update_tables_0.5.x-0.6.pgsql	Sun Apr 15 17:36:26 2012 +0200
+++ b/pgsql/update_tables_0.5.x-0.6.pgsql	Sun Apr 15 17:51:00 2012 +0200
@@ -475,9 +475,16 @@
         record recipient_transport;
         recipient varchar(320) := localpart || '@' || the_domain;
         did bigint := (SELECT gid FROM domain_name WHERE domainname = the_domain);
-        transport_id bigint := (SELECT tid FROM users
-                                  WHERE gid = did AND local_part = localpart);
+        transport_id bigint;
     BEGIN
+        IF did IS NULL THEN
+            RETURN;
+        END IF;
+
+        SELECT tid INTO transport_id
+          FROM users
+         WHERE gid = did AND local_part = localpart;
+
         IF transport_id IS NULL THEN
             SELECT tid INTO STRICT transport_id
               FROM domain_data