From 43e374548d904b032ce06938bcf482624758e786 Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Mon, 19 Feb 2024 23:03:48 +0800 Subject: [PATCH 1/9] fix?(mssql): address list-all-columns not including table name like mysql and its base SQL command --- src/sources/mssql/sql/list-all-columns.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sources/mssql/sql/list-all-columns.sql b/src/sources/mssql/sql/list-all-columns.sql index 94b15608..3070ccf2 100644 --- a/src/sources/mssql/sql/list-all-columns.sql +++ b/src/sources/mssql/sql/list-all-columns.sql @@ -44,9 +44,9 @@ on c.TABLE_SCHEMA = t.TABLE_SCHEMA and c.TABLE_NAME = t.TABLE_NAME - where c.TABLE_CATALOG = '~a' - and t.TABLE_TYPE = '~a' - ~:[~*~;and (~{~a~^~&~10t or ~})~] - ~:[~*~;and (~{~a~^~&~10t and ~})~] + where c.TABLE_CATALOG = '~a' + and t.TABLE_TYPE = '~a' + ~:[~*~;and (~{table_name ~a~^ or ~})~] + ~:[~*~;and (~{table_name ~a~^ and ~})~] order by c.table_schema, c.table_name, c.ordinal_position; From bc4df4f28ce3cc2511b3db14366222c84df6558d Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Tue, 20 Feb 2024 01:22:14 +0800 Subject: [PATCH 2/9] debug(mssql): output values --- src/sources/mssql/mssql.lisp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index cb650b3a..db33cb2d 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -62,15 +62,23 @@ ;; If asked to MATERIALIZE VIEWS, now is the time to create them in MS ;; SQL, when given definitions rather than existing view names. (when (and materialize-views (not (eq :all materialize-views))) - (create-matviews materialize-views mssql)) + (create-matviews materialize-views mssql) + (format t "[fetch-metadata] Materialize Views: ~A~%" materialize-views) + ) + (format t "[fetch-metadata] Original including: ~A~%" including) (fetch-columns catalog mssql :including including :excluding excluding) ;; fetch view (and their columns) metadata, covering comments too - (let* ((view-names (unless (eq :all materialize-views) - (mapcar #'matview-source-name materialize-views))) + (let* ((view-names (progn + (let ((names (unless (eq :all materialize-views) + (mapcar #'matview-source-name materialize-views)))) + ;; Debugging statement + (format t "[fetch-metadata] Debugging view-names: ~A~%" names) + ;; Return the computed value for the let* binding + names)))) (including (loop :for (schema-name . view-name) :in view-names :do (let* ((schema-name (or schema-name "dbo")) @@ -80,6 +88,7 @@ (assoc schema-name including :test #'string=))))) (push-to-end view-name (cdr schema-entry)))))) + (format t "[fetch-metadata] New including: ~A~%" including) (cond (view-names (fetch-columns catalog mssql :including including From 2f3685e38375315ded29126c12cad90b9d57c4f8 Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Tue, 20 Feb 2024 01:32:59 +0800 Subject: [PATCH 3/9] debug(mssql): correct debug statements --- src/sources/mssql/mssql.lisp | 5 +++-- src/sources/mssql/sql/list-all-columns.sql | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index db33cb2d..2075d681 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -78,7 +78,7 @@ ;; Debugging statement (format t "[fetch-metadata] Debugging view-names: ~A~%" names) ;; Return the computed value for the let* binding - names)))) + names))) (including (loop :for (schema-name . view-name) :in view-names :do (let* ((schema-name (or schema-name "dbo")) @@ -96,7 +96,8 @@ :table-type :view)) ((eq :all materialize-views) - (fetch-columns catalog mssql :table-type :view)))) + (fetch-columns catalog mssql :table-type :view))) + ) (when create-indexes (fetch-indexes catalog mssql diff --git a/src/sources/mssql/sql/list-all-columns.sql b/src/sources/mssql/sql/list-all-columns.sql index 3070ccf2..13294a26 100644 --- a/src/sources/mssql/sql/list-all-columns.sql +++ b/src/sources/mssql/sql/list-all-columns.sql @@ -46,7 +46,7 @@ where c.TABLE_CATALOG = '~a' and t.TABLE_TYPE = '~a' - ~:[~*~;and (~{table_name ~a~^ or ~})~] - ~:[~*~;and (~{table_name ~a~^ and ~})~] + ~:[~*~;and (~{~a~^~&~10t or ~})~] + ~:[~*~;and (~{~a~^~&~10t and ~})~] order by c.table_schema, c.table_name, c.ordinal_position; From 95033bc484786618d9aa5db8bc8c22fc2b185279 Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Tue, 20 Feb 2024 02:44:26 +0800 Subject: [PATCH 4/9] debug(mssql): correct debug statements --- src/sources/mssql/mssql.lisp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index 2075d681..204a7f97 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -84,10 +84,23 @@ :do (let* ((schema-name (or schema-name "dbo")) (schema-entry (or (assoc schema-name including :test #'string=) - (progn (push (cons schema-name nil) including) - (assoc schema-name including - :test #'string=))))) - (push-to-end view-name (cdr schema-entry)))))) + (let ( + (new-entry (cons schema-name nil)); Initially nil, intending to be a list + ) + (push new-entry including) + (format t "[fetch-metadata] Debugging schema-name: ~A~%" schema-name) + new-entry + ) + ) + ) + (setf (cdr schema-entry) (push-to-end view-name (cdr schema-entry))) + (format t "[fetch-metadata] Debugging schema-entry: ~A~%" schema-entry) + ;; (push-to-end view-name (cdr schema-entry)) + ) + ) + ) + ) + ) (format t "[fetch-metadata] New including: ~A~%" including) (cond (view-names (fetch-columns catalog mssql From 50d3c00b3c9c7a58b896f1e6c72c7886793212bb Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Tue, 20 Feb 2024 03:21:33 +0800 Subject: [PATCH 5/9] fix?(mssql): debug statements and attempt to actually set including to a non-nill value --- src/sources/mssql/mssql.lisp | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index 204a7f97..f5b31d21 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -79,29 +79,30 @@ (format t "[fetch-metadata] Debugging view-names: ~A~%" names) ;; Return the computed value for the let* binding names))) - (including - (loop :for (schema-name . view-name) :in view-names - :do (let* ((schema-name (or schema-name "dbo")) - (schema-entry - (or (assoc schema-name including :test #'string=) - (let ( - (new-entry (cons schema-name nil)); Initially nil, intending to be a list - ) - (push new-entry including) - (format t "[fetch-metadata] Debugging schema-name: ~A~%" schema-name) - new-entry - ) - ) - ) - (setf (cdr schema-entry) (push-to-end view-name (cdr schema-entry))) - (format t "[fetch-metadata] Debugging schema-entry: ~A~%" schema-entry) - ;; (push-to-end view-name (cdr schema-entry)) + (including nil) + ) + (loop :for (schema-name . view-name) :in view-names + :do (let* ( + (schema-name (or schema-name "dbo")) + (schema-entry (or + (assoc schema-name including :test #'string=) + (let ( + (new-entry (cons schema-name nil)); Initially nil, intending to be a list + ) + (push new-entry including) + (format t "[fetch-metadata:do] Debugging schema-name: ~A~%" schema-name) + new-entry ) - ) + )) ) - ) + (push-to-end view-name (cdr schema-entry)) + (format t "[fetch-metadata] Debugging schema-entry: ~A~%" schema-entry) + (format t "[fetch-metadata] Debugging schema-name: ~A~%" schema-name) + ;; (push-to-end view-name (cdr schema-entry)) + ) ) (format t "[fetch-metadata] New including: ~A~%" including) + (format t "[fetch-metadata] New view-names: ~A~%" view-names) (cond (view-names (fetch-columns catalog mssql :including including From 337761e6f3c8fdcfaf4f2d72eea782f8c6e71d99 Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Tue, 20 Feb 2024 03:30:46 +0800 Subject: [PATCH 6/9] style: clean up the indentation for readability --- src/sources/mssql/mssql.lisp | 63 ++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index f5b31d21..3d46ab6b 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -72,35 +72,42 @@ :excluding excluding) ;; fetch view (and their columns) metadata, covering comments too - (let* ((view-names (progn - (let ((names (unless (eq :all materialize-views) - (mapcar #'matview-source-name materialize-views)))) - ;; Debugging statement - (format t "[fetch-metadata] Debugging view-names: ~A~%" names) - ;; Return the computed value for the let* binding - names))) - (including nil) - ) - (loop :for (schema-name . view-name) :in view-names - :do (let* ( - (schema-name (or schema-name "dbo")) - (schema-entry (or - (assoc schema-name including :test #'string=) - (let ( - (new-entry (cons schema-name nil)); Initially nil, intending to be a list - ) - (push new-entry including) - (format t "[fetch-metadata:do] Debugging schema-name: ~A~%" schema-name) - new-entry - ) - )) - ) - (push-to-end view-name (cdr schema-entry)) - (format t "[fetch-metadata] Debugging schema-entry: ~A~%" schema-entry) - (format t "[fetch-metadata] Debugging schema-name: ~A~%" schema-name) - ;; (push-to-end view-name (cdr schema-entry)) - ) + (let* ( + (view-names + (progn + (let ((names (unless + (eq :all materialize-views) + (mapcar #'matview-source-name materialize-views) + ))) + ;; Debugging statement + (format t "[fetch-metadata] Debugging view-names: ~A~%" names) + ;; Return the computed value for the let* binding + names ) + ) + ) + (including nil) + ) + (loop :for (schema-name . view-name) :in view-names + :do (let* ( + (schema-name (or schema-name "dbo")) + (schema-entry (or + (assoc schema-name including :test #'string=) + (let ( + (new-entry (cons schema-name nil)); Initially nil, intending to be a list + ) + (push new-entry including) + (format t "[fetch-metadata:do] Debugging schema-name: ~A~%" schema-name) + new-entry + ) + )) + ) + (push-to-end view-name (cdr schema-entry)) + (format t "[fetch-metadata] Debugging schema-entry: ~A~%" schema-entry) + (format t "[fetch-metadata] Debugging schema-name: ~A~%" schema-name) + ;; (push-to-end view-name (cdr schema-entry)) + ) + ) (format t "[fetch-metadata] New including: ~A~%" including) (format t "[fetch-metadata] New view-names: ~A~%" view-names) (cond (view-names From 9516344d044f8896e1ed4833a0577c4c8284d117 Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Thu, 7 Mar 2024 18:15:43 -0800 Subject: [PATCH 7/9] clean: remove debug statements --- src/sources/mssql/mssql.lisp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index 3d46ab6b..8e7e79e3 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -63,10 +63,8 @@ ;; SQL, when given definitions rather than existing view names. (when (and materialize-views (not (eq :all materialize-views))) (create-matviews materialize-views mssql) - (format t "[fetch-metadata] Materialize Views: ~A~%" materialize-views) ) - (format t "[fetch-metadata] Original including: ~A~%" including) (fetch-columns catalog mssql :including including :excluding excluding) @@ -80,7 +78,6 @@ (mapcar #'matview-source-name materialize-views) ))) ;; Debugging statement - (format t "[fetch-metadata] Debugging view-names: ~A~%" names) ;; Return the computed value for the let* binding names ) @@ -97,19 +94,14 @@ (new-entry (cons schema-name nil)); Initially nil, intending to be a list ) (push new-entry including) - (format t "[fetch-metadata:do] Debugging schema-name: ~A~%" schema-name) new-entry ) )) ) (push-to-end view-name (cdr schema-entry)) - (format t "[fetch-metadata] Debugging schema-entry: ~A~%" schema-entry) - (format t "[fetch-metadata] Debugging schema-name: ~A~%" schema-name) ;; (push-to-end view-name (cdr schema-entry)) ) ) - (format t "[fetch-metadata] New including: ~A~%" including) - (format t "[fetch-metadata] New view-names: ~A~%" view-names) (cond (view-names (fetch-columns catalog mssql :including including From e1be97468af96282163e5ffcf952512a14342690 Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Thu, 7 Mar 2024 20:12:41 -0800 Subject: [PATCH 8/9] clean: format parentheses to match LISP style --- src/sources/mssql/mssql.lisp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index 8e7e79e3..c18e98e6 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -62,8 +62,7 @@ ;; If asked to MATERIALIZE VIEWS, now is the time to create them in MS ;; SQL, when given definitions rather than existing view names. (when (and materialize-views (not (eq :all materialize-views))) - (create-matviews materialize-views mssql) - ) + (create-matviews materialize-views mssql)) (fetch-columns catalog mssql :including including @@ -73,16 +72,13 @@ (let* ( (view-names (progn - (let ((names (unless + (let + ((names (unless (eq :all materialize-views) - (mapcar #'matview-source-name materialize-views) - ))) + (mapcar #'matview-source-name materialize-views)))) ;; Debugging statement ;; Return the computed value for the let* binding - names - ) - ) - ) + names))) (including nil) ) (loop :for (schema-name . view-name) :in view-names @@ -90,18 +86,11 @@ (schema-name (or schema-name "dbo")) (schema-entry (or (assoc schema-name including :test #'string=) - (let ( - (new-entry (cons schema-name nil)); Initially nil, intending to be a list - ) + (let + ((new-entry (cons schema-name nil))); Initially nil, intending to be a list (push new-entry including) - new-entry - ) - )) - ) - (push-to-end view-name (cdr schema-entry)) - ;; (push-to-end view-name (cdr schema-entry)) - ) - ) + new-entry)))) + (push-to-end view-name (cdr schema-entry)))) (cond (view-names (fetch-columns catalog mssql :including including From ac5fe29339e0c77bd80bfc3fef9646cea39c6db7 Mon Sep 17 00:00:00 2001 From: Conor McLaughlin Date: Thu, 7 Mar 2024 20:28:27 -0800 Subject: [PATCH 9/9] clean: focus on indents instead of end parentheses. --- src/sources/mssql/mssql.lisp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sources/mssql/mssql.lisp b/src/sources/mssql/mssql.lisp index c18e98e6..159ef0a9 100644 --- a/src/sources/mssql/mssql.lisp +++ b/src/sources/mssql/mssql.lisp @@ -98,8 +98,7 @@ :table-type :view)) ((eq :all materialize-views) - (fetch-columns catalog mssql :table-type :view))) - ) + (fetch-columns catalog mssql :table-type :view)))) (when create-indexes (fetch-indexes catalog mssql