From 35ddccaa16546577be5e8e5a39787b43e6020352 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Fri, 1 Oct 2021 13:04:26 +0100 Subject: [PATCH] fix: refactored mp_getconstraints due to apparent bug in dictionary.table_constraints. Added test. Closes #83 --- all.sas | 7 +++-- base/mp_getconstraints.sas | 7 +++-- sasjs/sasjsconfig.json | 5 +++- .../crossplatform/mp_getconstraints.test.sas | 29 +++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 tests/crossplatform/mp_getconstraints.test.sas diff --git a/all.sas b/all.sas index ae4a4c2..753f915 100644 --- a/all.sas +++ b/all.sas @@ -4466,8 +4466,11 @@ create table &outds as on upcase(a.TABLE_CATALOG)=upcase(b.TABLE_CATALOG) and upcase(a.TABLE_NAME)=upcase(b.TABLE_NAME) and a.constraint_name=b.constraint_name - where upcase(a.TABLE_CATALOG)="&lib" - and upcase(b.TABLE_CATALOG)="&lib" +/** + * We cannot apply this clause to the underlying dictionary table. See: + * https://communities.sas.com/t5/SAS-Programming/Unexpected-Where-Clause-behaviour-in-dictionary-TABLE/m-p/771554#M244867 + */ + where calculated libref="&lib" %if "&ds" ne "" %then %do; and upcase(a.TABLE_NAME)="&ds" and upcase(b.TABLE_NAME)="&ds" diff --git a/base/mp_getconstraints.sas b/base/mp_getconstraints.sas index c3f6434..3963cf6 100644 --- a/base/mp_getconstraints.sas +++ b/base/mp_getconstraints.sas @@ -49,8 +49,11 @@ create table &outds as on upcase(a.TABLE_CATALOG)=upcase(b.TABLE_CATALOG) and upcase(a.TABLE_NAME)=upcase(b.TABLE_NAME) and a.constraint_name=b.constraint_name - where upcase(a.TABLE_CATALOG)="&lib" - and upcase(b.TABLE_CATALOG)="&lib" +/** + * We cannot apply this clause to the underlying dictionary table. See: + * https://communities.sas.com/t5/SAS-Programming/Unexpected-Where-Clause-behaviour-in-dictionary-TABLE/m-p/771554#M244867 + */ + where calculated libref="&lib" %if "&ds" ne "" %then %do; and upcase(a.TABLE_NAME)="&ds" and upcase(b.TABLE_NAME)="&ds" diff --git a/sasjs/sasjsconfig.json b/sasjs/sasjsconfig.json index 2a885b8..d94f3fd 100644 --- a/sasjs/sasjsconfig.json +++ b/sasjs/sasjsconfig.json @@ -50,7 +50,10 @@ "appLoc": "/Shared Data/temp/macrocore", "macroFolders": [ "tests/sas9only" - ] + ], + "deployConfig": { + "deployServicePack": true + } }, { "name": "docsonly", diff --git a/tests/crossplatform/mp_getconstraints.test.sas b/tests/crossplatform/mp_getconstraints.test.sas new file mode 100644 index 0000000..1da4ebd --- /dev/null +++ b/tests/crossplatform/mp_getconstraints.test.sas @@ -0,0 +1,29 @@ +/** + @file + @brief Testing mp_getconstraints.sas macro + +

SAS Macros

+ @li mf_nobs.sas + @li mp_getconstraints.sas + @li mp_assert.sas + +**/ + +proc sql; +create table work.example( + TX_FROM float format=datetime19., + DD_TYPE char(16), + DD_SOURCE char(2048), + DD_SHORTDESC char(256), + constraint pk primary key(tx_from, dd_type,dd_source), + constraint unq unique(tx_from, dd_type), + constraint nnn not null(DD_SHORTDESC) +); + +%mp_getconstraints(lib=work,ds=example,outds=work.constraints) + +%mp_assert( + iftrue=(%mf_nobs(work.constraints)=6), + desc=Output table work.constraints created with correct number of records, + outds=work.test_results +) \ No newline at end of file