emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/sql-indent 14c3e33 3/4: Fix up bad detection of $$ deli


From: Stefan Monnier
Subject: [elpa] externals/sql-indent 14c3e33 3/4: Fix up bad detection of $$ delimiters in PostgreSQL dialect (#67)
Date: Thu, 25 Oct 2018 08:37:08 -0400 (EDT)

branch: externals/sql-indent
commit 14c3e33ad868bb8592d352c86578b3c05a80edeb
Author: Alex Harsányi <address@hidden>
Commit: GitHub <address@hidden>

    Fix up bad detection of $$ delimiters in PostgreSQL dialect (#67)
    
    this resulted in severe performance degradation for the indent function and
    bad anchor for the $$ blocks.
    
    * sql-indent.el (sqlind-maybe-create-statement): strip off any
    parens off the function name.
    (sqlind-maybe-$$-statement): re-wrote the function to avoid
    calling `sqlind-beginning-of-block` recursively.
    (sqlind-start-block-regexp): fixup $$ matching
---
 sql-indent-test.el     |   3 +
 sql-indent.el          |  51 +++--
 test-data/pr54-syn.eld |  37 ++--
 test-data/pr67-syn.eld | 570 +++++++++++++++++++++++++++++++++++++++++++++++++
 test-data/pr67.sql     | 250 ++++++++++++++++++++++
 5 files changed, 871 insertions(+), 40 deletions(-)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index a5d107d..c9bc933 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -375,4 +375,7 @@ information read from DATA-FILE (as generated by
 (ert-deftest sqlind-ert-pr66 ()
   (sqlind-ert-check-file-syntax "test-data/pr66.sql" "test-data/pr66-syn.eld"))
 
+(ert-deftest sqlind-ert-pr67 ()
+  (sqlind-ert-check-file-syntax "test-data/pr67.sql" "test-data/pr67-syn.eld"))
+
 ;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index 748aae4..5adeb3c 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -702,6 +702,10 @@ See also `sqlind-beginning-of-block'"
                         (progn (sqlind-forward-syntactic-ws) (point))
                         (progn (skip-syntax-forward "w_()") (point))))))
 
+          ;; Keep just the name, not the argument list
+          (when (string-match "\\(.*?\\)(" name)
+            (setq name (match-string 1 name)))
+
          (if (memq what '(procedure function package package-body))
              ;; check is name is in the form user.name, if so then suppress 
user part.
              (progn
@@ -799,31 +803,36 @@ end block and creates the appropiate syntactic context.
 See also `sqlind-beginning-of-block'"
   (when (looking-at "\\$\\$")
     (prog1 t
-      (let* ((saved-pos (point))
-             (previous-block (save-excursion
-                               (ignore-errors (forward-char -1))
-                               (cons (sqlind-beginning-of-block) (point))))
-             (previous-block-kind (nth 0 previous-block)))
-        (goto-char saved-pos)
-        (if (and (listp previous-block-kind)
-                 (eq (nth 0 previous-block-kind) 'defun-start))
-            (progn
-              (when (null sqlind-end-stmt-stack)
-                (throw 'finished (list 'in-begin-block 'defun (nth 1 
previous-block-kind))))
-              (cl-destructuring-bind (pos kind _label) (pop 
sqlind-end-stmt-stack)
-                (unless (eq kind '$$)
-                  (throw 'finished
-                    (list 'syntax-error "bad closing for $$ begin block" 
(point) pos)))
-                (goto-char (cdr previous-block))))
-          ;; Assume it is an "end" statement
-          (push (list (point) '$$ "") sqlind-end-stmt-stack))))))
+      (let* ((saved-pos (point)))
+        (ignore-errors (forward-char -1))
+        (sqlind-backward-syntactic-ws)
+        (cond ((looking-at ";")
+               ;; Assume the $$ is ending a statement (previous line is a ';'
+               ;; which ends another statement)
+               (push (list saved-pos '$$ "") sqlind-end-stmt-stack)
+               (goto-char saved-pos))
+              ((null sqlind-end-stmt-stack)
+               (sqlind-beginning-of-statement)
+               (let ((syntax (catch 'finished
+                               (sqlind-maybe-create-statement)
+                               (sqlind-maybe-defun-statement)
+                               'toplevel)))
+                 (if (and (listp syntax) (eq (nth 0 syntax) 'defun-start))
+                     (throw 'finished (list 'in-begin-block 'defun (nth 1 
syntax)))
+                   (throw 'finished (list 'in-begin-block syntax nil)))))
+              (t
+               (sqlind-beginning-of-statement)
+               (cl-destructuring-bind (pos kind _label) (pop 
sqlind-end-stmt-stack)
+                 (unless (eq kind '$$)
+                   (throw 'finished
+                     (list 'syntax-error "bad closing for $$ begin block" 
(point) pos))))))))))
 
 (defconst sqlind-start-block-regexp
   (concat "\\(\\_<"
          (regexp-opt '("if" "then" "else" "elsif" "loop"
                        "begin" "declare" "create" "alter" "exception"
-                       "procedure" "function" "end" "case" "$$") t)
-         "\\_>\\)\\|)")
+                       "procedure" "function" "end" "case") t)
+         "\\_>\\)\\|)\\|\\$\\$")
   "Regexp to match the start of a block.")
 
 (defun sqlind-beginning-of-block (&optional end-statement-stack)
@@ -2294,7 +2303,7 @@ See also `align' and `align-rules-list'")
 
 (defvar sqlind-minor-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap beginning-of-defun] 'sqlind-beginning-of-statement)
+    (define-key map [remap beginning-of-defun] 'sqlind-beginning-of-block)
     map))
 
 (defvar align-mode-rules-list)
diff --git a/test-data/pr54-syn.eld b/test-data/pr54-syn.eld
index 40abbbe..a1d1977 100644
--- a/test-data/pr54-syn.eld
+++ b/test-data/pr54-syn.eld
@@ -4,47 +4,47 @@
   ((defun-start "foo_1")
    . 1))
  (((in-begin-block defun "foo_1")
-   . 40))
+   . 1))
  (((block-end defun "foo_1")
-   . 40)
+   . 1)
   ((in-begin-block defun "foo_1")
-   . 40))
+   . 1))
  ((toplevel . 1))
  ((toplevel . 1))
  (((in-begin-block defun "foo_2")
-   . 99))
+   . 60))
  (((block-end defun "foo_2")
-   . 99)
+   . 60)
   ((in-begin-block defun "foo_2")
-   . 99))
+   . 60))
  ((toplevel . 1))
  ((toplevel . 1))
  (((block-start is-or-as)
-   . 197)
+   . 119)
   ((defun-start "foo_3")
-   . 197))
+   . 119))
  (((in-begin-block defun "foo_3")
-   . 236))
+   . 119))
  (((block-end defun "foo_3")
-   . 236)
+   . 119)
   ((in-begin-block defun "foo_3")
-   . 236))
+   . 119))
  ((toplevel . 1))
  ((toplevel . 1))
  (((block-start is-or-as)
-   . 262)
+   . 178)
   ((defun-start "foo_4")
-   . 262))
+   . 178))
  (((block-start begin)
-   . 262)
+   . 178)
   ((defun-start "foo_4")
-   . 262))
+   . 178))
  (((in-begin-block defun "foo_4")
-   . 301))
+   . 178))
  (((block-end defun "foo_4")
-   . 301)
+   . 178)
   ((in-begin-block defun "foo_4")
-   . 301))
+   . 178))
  ((toplevel . 1))
  ((toplevel . 1))
  ((toplevel . 1))
@@ -63,4 +63,3 @@
  ((comment-start . 1)
   (toplevel . 1))
  ((toplevel . 1)))
- 
\ No newline at end of file
diff --git a/test-data/pr67-syn.eld b/test-data/pr67-syn.eld
new file mode 100644
index 0000000..0657beb
--- /dev/null
+++ b/test-data/pr67-syn.eld
@@ -0,0 +1,570 @@
+(((comment-start . 1)
+  (toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((block-start begin)
+   . 1)
+  (toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block toplevel nil)
+   . 79))
+ (((in-begin-block toplevel nil)
+   . 79))
+ (((in-begin-block toplevel nil)
+   . 79))
+ (((in-begin-block nil "")
+   . 129))
+ (((in-begin-block nil "")
+   . 129))
+ (((in-block if "")
+   . 155))
+ (((in-block if "")
+   . 155))
+ (((block-start elsif)
+   . 155)
+  ((in-block if "")
+   . 155))
+ ((select-clause . 231)
+  (nested-statement-continuation . 230)
+  (statement-continuation . 230))
+ (((in-block elsif "")
+   . 224))
+ (((in-block elsif "")
+   . 224))
+ (((block-start elsif)
+   . 224)
+  ((in-block elsif "")
+   . 224))
+ ((select-clause . 347)
+  (nested-statement-continuation . 346)
+  (statement-continuation . 346))
+ ((select-clause . 347)
+  (nested-statement-continuation . 346)
+  (statement-continuation . 346))
+ (((in-block elsif "")
+   . 340))
+ (((in-block elsif "")
+   . 340))
+ (((block-start elsif)
+   . 340)
+  ((in-block elsif "")
+   . 340))
+ ((select-clause . 496)
+  (nested-statement-continuation . 495)
+  (statement-continuation . 495))
+ ((select-table-continuation . 526)
+  (nested-statement-continuation . 495)
+  (statement-continuation . 495))
+ ((select-table-continuation . 526)
+  (nested-statement-continuation . 495)
+  (statement-continuation . 495))
+ ((select-clause . 496)
+  (nested-statement-continuation . 495)
+  (statement-continuation . 495))
+ (((in-block elsif "")
+   . 489))
+ (((in-block elsif "")
+   . 489))
+ (((block-start else)
+   . 489)
+  ((in-block elsif "")
+   . 489))
+ (((in-block else "")
+   . 698))
+ ((statement-continuation . 709))
+ ((statement-continuation . 709))
+ ((statement-continuation . 709))
+ ((statement-continuation . 709))
+ ((statement-continuation . 709))
+ ((statement-continuation . 709))
+ (((in-block loop "")
+   . 709))
+ ((statement-continuation . 877))
+ ((statement-continuation . 877))
+ ((statement-continuation . 877))
+ ((statement-continuation . 877))
+ (((block-end loop "")
+   . 709)
+  ((in-block loop "")
+   . 709))
+ (((block-end if "")
+   . 155)
+  ((in-block else "")
+   . 698))
+ (((block-end nil "")
+   . 129)
+  ((in-begin-block nil "")
+   . 129))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block toplevel nil)
+   . 1113))
+ (((in-begin-block toplevel nil)
+   . 1113))
+ (((in-begin-block toplevel nil)
+   . 1113))
+ (((in-begin-block toplevel nil)
+   . 1113))
+ (((in-begin-block nil "")
+   . 1187))
+ (((in-begin-block nil "")
+   . 1187))
+ (((in-begin-block nil "")
+   . 1187))
+ (((in-block if "")
+   . 1237))
+ (((in-block if "")
+   . 1237))
+ (((block-start elsif)
+   . 1237)
+  ((in-block if "")
+   . 1237))
+ (((in-block elsif "")
+   . 1306))
+ (((in-block elsif "")
+   . 1306))
+ (((block-start elsif)
+   . 1306)
+  ((in-block elsif "")
+   . 1306))
+ ((select-clause . 1388)
+  (nested-statement-continuation . 1387)
+  (statement-continuation . 1387))
+ ((select-clause . 1388)
+  (nested-statement-continuation . 1387)
+  (statement-continuation . 1387))
+ (((in-select-clause "where")
+   . 1443)
+  (nested-statement-continuation . 1387)
+  (statement-continuation . 1387))
+ (((in-block elsif "")
+   . 1381))
+ (((in-block elsif "")
+   . 1381))
+ (((block-start elsif)
+   . 1381)
+  ((in-block elsif "")
+   . 1381))
+ ((select-clause . 1547)
+  (nested-statement-continuation . 1546)
+  (statement-continuation . 1546))
+ ((select-table-continuation . 1577)
+  (nested-statement-continuation . 1546)
+  (statement-continuation . 1546))
+ ((select-table-continuation . 1577)
+  (nested-statement-continuation . 1546)
+  (statement-continuation . 1546))
+ ((select-clause . 1547)
+  (nested-statement-continuation . 1546)
+  (statement-continuation . 1546))
+ (((in-select-clause "where")
+   . 1681)
+  (nested-statement-continuation . 1546)
+  (statement-continuation . 1546))
+ (((in-block elsif "")
+   . 1540))
+ (((in-block elsif "")
+   . 1540))
+ (((block-start elsif)
+   . 1540)
+  ((in-block elsif "")
+   . 1540))
+ ((select-clause . 1785)
+  (nested-statement-continuation . 1784)
+  (statement-continuation . 1784))
+ ((select-table-continuation . 1815)
+  (nested-statement-continuation . 1784)
+  (statement-continuation . 1784))
+ ((select-table-continuation . 1815)
+  (nested-statement-continuation . 1784)
+  (statement-continuation . 1784))
+ ((select-table-continuation . 1815)
+  (nested-statement-continuation . 1784)
+  (statement-continuation . 1784))
+ ((select-clause . 1785)
+  (nested-statement-continuation . 1784)
+  (statement-continuation . 1784))
+ (((in-select-clause "where")
+   . 1959)
+  (nested-statement-continuation . 1784)
+  (statement-continuation . 1784))
+ (((in-block elsif "")
+   . 1778))
+ (((in-block elsif "")
+   . 1778))
+ (((block-start else)
+   . 1778)
+  ((in-block elsif "")
+   . 1778))
+ (((in-block else "")
+   . 2057))
+ ((statement-continuation . 2068))
+ ((statement-continuation . 2068))
+ ((statement-continuation . 2068))
+ ((statement-continuation . 2068))
+ ((statement-continuation . 2068))
+ ((statement-continuation . 2068))
+ (((in-block loop "")
+   . 2068))
+ ((statement-continuation . 2249))
+ ((statement-continuation . 2249))
+ ((statement-continuation . 2249))
+ ((statement-continuation . 2249))
+ (((block-end loop "")
+   . 2068)
+  ((in-block loop "")
+   . 2068))
+ (((block-end if "")
+   . 1237)
+  ((in-block else "")
+   . 2057))
+ (((block-end nil "")
+   . 1187)
+  ((in-begin-block nil "")
+   . 1187))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block toplevel nil)
+   . 2479))
+ (((in-begin-block toplevel nil)
+   . 2479))
+ (((in-begin-block toplevel nil)
+   . 2479))
+ (((in-begin-block nil "")
+   . 2529))
+ (((in-begin-block nil "")
+   . 2529))
+ (((in-block if "")
+   . 2556))
+ (((in-block if "")
+   . 2556))
+ (((block-start elsif)
+   . 2556)
+  ((in-block if "")
+   . 2556))
+ ((select-clause . 2633)
+  (nested-statement-continuation . 2632)
+  (statement-continuation . 2632))
+ (((in-block elsif "")
+   . 2626))
+ (((in-block elsif "")
+   . 2626))
+ (((block-start elsif)
+   . 2626)
+  ((in-block elsif "")
+   . 2626))
+ ((select-clause . 2750)
+  (nested-statement-continuation . 2749)
+  (statement-continuation . 2749))
+ ((select-table-continuation . 2780)
+  (nested-statement-continuation . 2749)
+  (statement-continuation . 2749))
+ ((select-clause . 2750)
+  (nested-statement-continuation . 2749)
+  (statement-continuation . 2749))
+ (((in-block elsif "")
+   . 2743))
+ (((in-block elsif "")
+   . 2743))
+ (((block-start else)
+   . 2743)
+  ((in-block elsif "")
+   . 2743))
+ (((in-block else "")
+   . 2913))
+ ((statement-continuation . 2924))
+ ((statement-continuation . 2924))
+ ((statement-continuation . 2924))
+ ((statement-continuation . 2924))
+ ((statement-continuation . 2924))
+ (((in-block loop "")
+   . 2924))
+ ((statement-continuation . 3082))
+ ((statement-continuation . 3082))
+ ((statement-continuation . 3082))
+ ((statement-continuation . 3082))
+ (((block-end loop "")
+   . 2924)
+  ((in-block loop "")
+   . 2924))
+ (((block-end if "")
+   . 2556)
+  ((in-block else "")
+   . 2913))
+ (((block-end nil "")
+   . 2529)
+  ((in-begin-block nil "")
+   . 2529))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block toplevel nil)
+   . 3311))
+ (((in-begin-block toplevel nil)
+   . 3311))
+ (((in-begin-block toplevel nil)
+   . 3311))
+ (((in-begin-block nil "")
+   . 3361))
+ (((in-begin-block nil "")
+   . 3361))
+ (((in-block if "")
+   . 3395))
+ (((in-block if "")
+   . 3395))
+ (((block-start elsif)
+   . 3395)
+  ((in-block if "")
+   . 3395))
+ ((select-clause . 3472)
+  (nested-statement-continuation . 3471)
+  (statement-continuation . 3471))
+ (((in-block elsif "")
+   . 3465))
+ (((in-block elsif "")
+   . 3465))
+ (((block-start elsif)
+   . 3465)
+  ((in-block elsif "")
+   . 3465))
+ ((select-clause . 3589)
+  (nested-statement-continuation . 3588)
+  (statement-continuation . 3588))
+ ((select-table-continuation . 3619)
+  (nested-statement-continuation . 3588)
+  (statement-continuation . 3588))
+ ((select-clause . 3589)
+  (nested-statement-continuation . 3588)
+  (statement-continuation . 3588))
+ (((in-block elsif "")
+   . 3582))
+ (((in-block elsif "")
+   . 3582))
+ (((block-start else)
+   . 3582)
+  ((in-block elsif "")
+   . 3582))
+ (((in-block else "")
+   . 3752))
+ ((statement-continuation . 3763))
+ ((statement-continuation . 3763))
+ ((statement-continuation . 3763))
+ ((statement-continuation . 3763))
+ ((statement-continuation . 3763))
+ (((in-block loop "")
+   . 3763))
+ ((statement-continuation . 3921))
+ ((statement-continuation . 3921))
+ ((statement-continuation . 3921))
+ ((statement-continuation . 3921))
+ (((block-end loop "")
+   . 3763)
+  ((in-block loop "")
+   . 3763))
+ (((block-end if "")
+   . 3395)
+  ((in-block else "")
+   . 3752))
+ (((block-end nil "")
+   . 3361)
+  ((in-begin-block nil "")
+   . 3361))
+ (((block-end toplevel nil)
+   . 3311)
+  ((in-begin-block toplevel nil)
+   . 3311))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block toplevel nil)
+   . 4150))
+ (((in-begin-block toplevel nil)
+   . 4150))
+ (((in-begin-block toplevel nil)
+   . 4150))
+ (((in-begin-block toplevel nil)
+   . 4150))
+ (((in-begin-block nil "")
+   . 4226))
+ (((in-begin-block nil "")
+   . 4226))
+ (((in-begin-block nil "")
+   . 4226))
+ (((in-block if "")
+   . 4273))
+ (((in-block if "")
+   . 4273))
+ (((block-start elsif)
+   . 4273)
+  ((in-block if "")
+   . 4273))
+ (((in-block elsif "")
+   . 4343))
+ (((in-block elsif "")
+   . 4343))
+ (((block-start elsif)
+   . 4343)
+  ((in-block elsif "")
+   . 4343))
+ ((select-clause . 4426)
+  (nested-statement-continuation . 4425)
+  (statement-continuation . 4425))
+ (((in-select-clause "where")
+   . 4468)
+  (nested-statement-continuation . 4425)
+  (statement-continuation . 4425))
+ (((in-block elsif "")
+   . 4419))
+ (((in-block elsif "")
+   . 4419))
+ (((block-start else)
+   . 4419)
+  ((in-block elsif "")
+   . 4419))
+ (((in-block else "")
+   . 4568))
+ ((statement-continuation . 4579))
+ ((statement-continuation . 4579))
+ (((in-block loop "")
+   . 4579))
+ ((statement-continuation . 4670))
+ ((statement-continuation . 4670))
+ (((block-end loop "")
+   . 4579)
+  ((in-block loop "")
+   . 4579))
+ (((block-end if "")
+   . 4273)
+  ((in-block else "")
+   . 4568))
+ (((block-end nil "")
+   . 4226)
+  ((in-begin-block nil "")
+   . 4226))
+ (((block-end toplevel nil)
+   . 4150)
+  ((in-begin-block toplevel nil)
+   . 4150))
+ ((toplevel . 1))
+ (((block-start begin)
+   . 1)
+  (toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block toplevel nil)
+   . 4822))
+ (((in-begin-block toplevel nil)
+   . 4822))
+ (((in-begin-block toplevel nil)
+   . 4822))
+ (((in-begin-block toplevel nil)
+   . 4822))
+ (((in-begin-block toplevel nil)
+   . 4822))
+ (((in-begin-block nil "")
+   . 4928))
+ (((in-begin-block nil "")
+   . 4928))
+ (((in-begin-block nil "")
+   . 4928))
+ (((in-begin-block nil "")
+   . 4928))
+ (((in-begin-block nil "")
+   . 4928))
+ (((in-block if "")
+   . 5047))
+ (((in-block if "")
+   . 5047))
+ (((block-start elsif)
+   . 5047)
+  ((in-block if "")
+   . 5047))
+ (((in-block elsif "")
+   . 5117))
+ (((in-block elsif "")
+   . 5117))
+ (((block-start elsif)
+   . 5117)
+  ((in-block elsif "")
+   . 5117))
+ (((in-block elsif "")
+   . 5193))
+ (((in-block elsif "")
+   . 5193))
+ (((block-start else)
+   . 5193)
+  ((in-block elsif "")
+   . 5193))
+ (((in-block else "")
+   . 5266))
+ ((nested-statement-continuation . 5303)
+  (statement-continuation . 5303))
+ ((nested-statement-continuation . 5303)
+  (statement-continuation . 5303))
+ ((nested-statement-continuation . 5303)
+  (statement-continuation . 5303))
+ ((nested-statement-continuation . 5303)
+  (statement-continuation . 5303))
+ (((in-block else "")
+   . 5266))
+ (((block-end if "")
+   . 5047)
+  ((in-block else "")
+   . 5266))
+ (((block-end nil "")
+   . 4928)
+  ((in-begin-block nil "")
+   . 4928))
+ (((block-end toplevel nil)
+   . 4822)
+  ((in-begin-block toplevel nil)
+   . 4822))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((block-start begin)
+   . 1)
+  (toplevel . 1))
+ ((toplevel . 1))
+ (((in-begin-block toplevel nil)
+   . 5627))
+ (((in-begin-block toplevel nil)
+   . 5627))
+ (((in-begin-block nil "")
+   . 5665))
+ (((in-begin-block nil "")
+   . 5665))
+ (((in-block if "")
+   . 5695))
+ (((in-block if "")
+   . 5695))
+ (((block-start elsif)
+   . 5695)
+  ((in-block if "")
+   . 5695))
+ (((in-block elsif "")
+   . 5802))
+ (((in-block elsif "")
+   . 5802))
+ (((in-block elsif "")
+   . 5802))
+ (((block-start else)
+   . 5802)
+  ((in-block elsif "")
+   . 5802))
+ (((in-block else "")
+   . 5916))
+ (((in-block else "")
+   . 5916))
+ (((block-end if "")
+   . 5695)
+  ((in-block else "")
+   . 5916))
+ (((block-end nil "")
+   . 5665)
+  ((in-begin-block nil "")
+   . 5665))
+ (((block-end toplevel nil)
+   . 5627)
+  ((in-begin-block toplevel nil)
+   . 5627))
+ ((toplevel . 1))
+ ((toplevel . 1)))
\ No newline at end of file
diff --git a/test-data/pr67.sql b/test-data/pr67.sql
new file mode 100644
index 0000000..c5d804c
--- /dev/null
+++ b/test-data/pr67.sql
@@ -0,0 +1,250 @@
+/* -*- sql-product: postgres; -*- */
+set serveroutput on;
+
+begin transaction;
+do $$ DECLARE
+  v1 TABLE1.F1%TYPE;
+  v2 record;
+  BEGIN
+    v1 = :v_v1;
+    if v1 in (NULL, '') then
+      raise 'message1';
+      rollback;
+    elsif (select count(F1) from TABLE1
+            where F1 = v1) = 0 then
+      raise 'message2';
+      rollback;
+    elsif (select count(F2)
+             from TABLE1 natural join TABLE2
+            where F1 = v1) = 0 then
+      raise 'message3';
+      rollback;
+    elsif (select count(F3)
+             from TABLE3
+                    natural join TABLE2
+                    natural join TABLE1
+            where F1 = v1) = 0 then
+      raise 'message4';
+      rollback;
+    else
+      for v2 in 
+        select *
+        from TABLE3 
+        natural join TABLE1
+        natural join TABLE4
+        natural join TABLE2
+        where F1 = v1 loop
+        raise info 'message5',
+          v2.F3, v2.F2, v2.F4 || ' ' ||
+          v2.F9 || case when v2.F5 is NULL then '' else
+          ' ''' || v2.F5 || '''' end, v2.F6,
+          v2.F7, v2.F8;
+      end loop;
+    end if;
+  END; $$;
+commit;
+
+do $$ DECLARE
+  v1 TABLE4.F9%TYPE;
+  prev1 TABLE4.F4%TYPE;
+  v2 record;
+  BEGIN
+    v1 := :v_v1;
+    prev1 := :v_prev1;
+    if v1 in (NULL, '') then
+      raise 'message6';
+      rollback;
+    elsif prev1 in (NULL, '') then
+      raise 'message7';
+      rollback;
+    elsif (select count(F10)
+             from TABLE4
+            where F9 = v1
+              and F4 = prev1) = 0 then
+      raise 'message8';
+      rollback;
+    elsif (select count(F2)
+             from TABLE2
+                    natural join TABLE5
+                    natural join TABLE4
+            where F9 = v1
+              and F4 = prev1) = 0 then
+      raise 'message9';
+      rollback;
+    elsif (select count(F3)
+             from TABLE3
+                    natural join TABLE2
+                    natural join TABLE5
+                    natural join TABLE4
+            where F9 = v1
+              and F4 = prev1) = 0 then
+      raise 'message10';
+      rollback;
+    else
+      for v2 in select *
+        from TABLE4
+        natural join TABLE5
+        natural join TABLE3
+        natural join TABLE2
+        where F9 = v1
+        and F4 = prev1 loop
+        raise info 'message11',
+          v2.F3, v2.F2, v2.F4 || ' ' ||
+          v2.F9 || case when v2.F5 is NULL then '' else
+          ' ''' || v2.F5 || '''' end, v2.F6,
+          v2.F7, v2.F8;
+      end loop;
+    end if;
+  end; $$;
+
+
+do $$ DECLARE
+  v2 record;
+  v3 TABLE2.F6%TYPE;
+  BEGIN
+    v3 := :v_v3;
+    if v3 in ('', NULL) then
+      raise 'message12';
+      rollback;
+    elsif (select count(F6) from TABLE2
+            where F6 = v3) = 0 then
+      raise 'message13';
+      rollback;
+    elsif (select count(F3)
+             from TABLE3
+                    natural join TABLE2
+            where F6 = v3) = 0 then
+      raise 'message14';
+      rollback;
+    else
+      for v2 in select *
+        from TABLE4
+        natural join TABLE5
+        natural join TABLE3
+        natural join TABLE2
+        where F6 = v3 loop
+        raise info 'message15',
+          v2.F3, v2.F2, v2.F4 || ' ' ||
+          v2.F9 || case when v2.F5 is NULL then '' else
+          ' ''' || v2.F5 || '''' end, v2.F6,
+          v2.F7, v2.F8;
+      end loop;
+    end if;
+  END; $$;
+
+do $$ DECLARE
+  v2 record;
+  v3 TABLE2.F2%TYPE;
+  BEGIN
+    v3 := :v_ouv_titre;
+    if v3 in ('', NULL) then
+      raise 'message16';
+      rollback;
+    elsif (select count(F2) from TABLE2
+            where F2 = v3) = 0 then
+      raise 'messaeg17';
+      rollback;
+    elsif (select count(F3)
+             from TABLE3
+                    natural join TABLE2
+            where F2 = v3) = 0 then
+      raise 'message18';
+      rollback;
+    else
+      for v2 in select *
+        from TABLE4
+        natural join TABLE5
+        natural join TABLE3
+        natural join TABLE2
+        where F2 = v3 loop
+        raise info 'message19',
+          v2.F3, v2.F2, v2.F4 || ' ' ||
+          v2.F9 || case when v2.F5 is NULL then '' else
+          ' ''' || v2.F5 || '''' end, v2.F6,
+          v2.F7, v2.F8;
+      end loop;
+    end if;
+  END;
+$$;
+
+do $$ DECLARE
+  v1 TABLE6.F12%TYPE;
+  prev1 TABLE6.F13%TYPE;
+  v2 record;
+  BEGIN
+    v1 := :v_v1;
+    prev1 := :v_v2;
+    if v1 in ('', NULL) then
+      raise 'message20';
+      rollback;
+    elsif prev1 in ('', NULL) then
+      raise 'message21';
+      rollback;
+    elsif (select count(F23) from TABLE6
+            where F12 = v1
+              and F13 = prev1) = 0 then
+      raise 'message22';
+      rollback;
+    else
+      for v2 in select * from TABLE6
+        where F12 = v1
+        and F13 = prev1 loop
+        raise info 'message23',
+          v2.F23, v2.F13 || ' ' || v2.F12,
+          v2.F27, v2.F28;
+      end loop;
+    end if;
+  END;
+$$;
+
+begin transaction;
+do $$ DECLARE
+  v1 TABLE6.F23%TYPE;
+  v1 TABLE6.F12%TYPE;
+  prev1 TABLE6.F13%TYPE;
+  v9 TABLE6.V2%TYPE;
+  BEGIN
+    select max(v2_id)+1 into v1 from t_v2ent;
+    v1 := :v_v2_c2;
+    prev1 := :v_v2_c8;
+    v9 := :v_v2_c9;
+    if v1 in ('', NULL) then
+      raise 'message24';
+      rollback;
+    elsif prev1 in ('', NULL) then
+      raise 'message25';
+      rollback;
+    elsif v9 in ('', NULL) then
+      raise 'message26';
+      rollback;
+    else
+      insert into TABLE6 values (v1, :v19, timestamp 'now',
+                                 v1, prev1, :v_v2_v8,
+                                 :v_v2_c7, :v_v2_v9,
+                                 :v_v2_c8, :v_v2_v10,
+                                 :v_v2_c9, v9);
+      raise notice 'message27', v1;
+    end if;
+  END;
+$$;
+commit;
+
+begin transaction;
+do $$ DECLARE
+  v1 TABLE6.F23%TYPE;
+  BEGIN
+    v1 := :v_v2_id;
+    if (select count(F23) from TABLE6 where F23 = v2_id) = 0 then
+      raise 'message28';
+      rollback;
+    elsif (select F27 from TABLE6 where F23 = v1) is not
+      NULL then
+      raise 'message29';
+      rollback;
+    else
+      delete from TABLE6 where V1 = v1;
+      raise notice 'message 30';
+    end if;
+  END;
+$$;
+commit;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]