From a24cf969aab61d950de916b48de88229b05a00f4 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Sat, 6 Jun 2020 22:23:43 +0200
Subject: Database: make sure we can deal with 'Geog3D to
 Geog2D+GravityRelatedHeight' records as we do with the more common
 'Geographic3D to GravityRelatedHeight'

---
 data/sql/commit.sql | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

(limited to 'data/sql/commit.sql')

diff --git a/data/sql/commit.sql b/data/sql/commit.sql
index d090ccb2..55df332f 100644
--- a/data/sql/commit.sql
+++ b/data/sql/commit.sql
@@ -32,9 +32,20 @@ FOR EACH ROW BEGIN
 
     -- test to check that our custom grid transformation overrides are really needed
     SELECT RAISE(ABORT, 'PROJ grid_transformation defined whereas EPSG has one')
-        WHERE EXISTS (SELECT 1 FROM grid_transformation g1, grid_transformation g2 WHERE
-            lower(g1.grid_name) = lower(g2.grid_name) AND
-            g1.auth_name = 'PROJ' AND g2.auth_name = 'EPSG');
+        WHERE EXISTS (SELECT 1 FROM grid_transformation g1
+                      JOIN grid_transformation g2
+                      ON g1.source_crs_auth_name = g2.source_crs_auth_name
+                      AND g1.source_crs_code = g2.source_crs_code
+                      AND g1.target_crs_auth_name = g2.target_crs_auth_name
+                      AND g1.target_crs_code = g2.target_crs_code
+                      WHERE g1.auth_name = 'PROJ' AND g2.auth_name = 'EPSG')
+        OR EXISTS (SELECT 1 FROM grid_transformation g1
+                      JOIN grid_transformation g2
+                      ON g1.source_crs_auth_name = g2.target_crs_auth_name
+                      AND g1.source_crs_code = g2.target_crs_code
+                      AND g1.target_crs_auth_name = g1.source_crs_auth_name
+                      AND g1.target_crs_code = g1.source_crs_code
+                      WHERE g1.auth_name = 'PROJ' AND g2.auth_name = 'EPSG');
 
     SELECT RAISE(ABORT, 'Arg! there is now a EPSG:102100 object. Hack in createFromUserInput() will no longer work')
         WHERE EXISTS(SELECT 1 FROM crs_view WHERE auth_name = 'EPSG' AND code = '102100');
-- 
cgit v1.2.3

