From dfae5296a8cdbfe08d4241621cb9ad663b0176cf Mon Sep 17 00:00:00 2001
From: Bertrand Gauthier <bertrand.gauthier@unicaen.fr>
Date: Mon, 1 Jul 2019 11:43:12 +0200
Subject: [PATCH] =?UTF-8?q?Correction=20de=20l'erreur=20lors=20de=20la=20g?=
 =?UTF-8?q?=C3=A9n=C3=A9ration=20du=20SQL=20:=20ORA-01789:=20query=20block?=
 =?UTF-8?q?=20has=20incorrect=20number=20of=20result=20columns?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/UnicaenOracle/Service/SchemaService.php | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/UnicaenOracle/Service/SchemaService.php b/src/UnicaenOracle/Service/SchemaService.php
index 8056a54..e9750fd 100644
--- a/src/UnicaenOracle/Service/SchemaService.php
+++ b/src/UnicaenOracle/Service/SchemaService.php
@@ -302,7 +302,7 @@ EOS;
 
         $refConstraintsSql = NULL;
         if ($refConstraintsIncluded) {
-            $refConstraintsSql = $this->generateSQLForRefConstraintsCreation($connection);
+            $refConstraintsSql = $this->generateSQLForRefConstraintsCreation($connection, true);
             $refConstraintsSql = <<<EOS
     UNION ALL
 
@@ -448,16 +448,14 @@ EOS;
 
     /**
      * @param Connection $connection
+     * @param bool       $innerSQLOnly
      * @return string
      */
-    function generateSQLForRefConstraintsCreation(Connection $connection)
+    function generateSQLForRefConstraintsCreation(Connection $connection, $innerSQLOnly = false)
     {
         $schemaName = $this->extractSchemaNameFromConnection($connection);
 
-        return <<<EOS
-        
-SELECT sql from (
-    
+        $sql = <<<EOS
     --
     -- reference constraints
     --
@@ -472,9 +470,19 @@ SELECT sql from (
     where owner = '$schemaName'
           and constraint_type = 'R'
 
+EOS;
+
+        if (! $innerSQLOnly) {
+            $sql = <<<EOS
+SELECT sql from (
+    
+    $sql
+
 )
 ORDER BY ORD
 EOS;
+        }
 
+        return $sql;
     }
 }
\ No newline at end of file
-- 
GitLab