1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-11 06:24:35 +00:00

fix: adding constraint_order to mp_getconstraints

This commit is contained in:
munja
2021-12-04 14:54:18 +00:00
parent 6056b739bf
commit 8c21b9397f

View File

@@ -22,6 +22,8 @@
@param [out] outds= (mp_getconstraints) the output dataset
<h4> SAS Macros </h4>
@li mf_getuniquename.sas
@li mp_dropmembers.sas
@version 9.2
@author Allan Bowe
@@ -36,6 +38,27 @@
%let lib=%upcase(&lib);
%let ds=%upcase(&ds);
/**
* Neither dictionary tables nor sashelp provides a constraint order column,
* however they DO arrive in the correct order. So, create the col.
**/
%local vw;
%let vw=%mf_getuniquename(prefix=mp_getconstraints_vw_);
data &vw /view=&vw;
set sashelp.vcncolu;
where TABLE_CATALOG="&lib";
/* use retain approach to reset the constraint order with each constraint */
length tmp $1000;
retain tmp;
drop tmp;
if tmp ne catx('|',libref,table_name,constraint_type,constraint_name) then do;
constraint_order=1;
end;
else constraint_order+1;
tmp=catx('|',libref, table_name, constraint_type,constraint_name);
run;
/* must use SQL as proc datasets does not support length changes */
proc sql noprint;
create table &outds as
@@ -44,8 +67,9 @@ create table &outds as
,a.constraint_type
,a.constraint_name
,b.column_name
,b.constraint_order
from dictionary.TABLE_CONSTRAINTS a
left join dictionary.constraint_column_usage b
left join &vw b
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
@@ -58,6 +82,13 @@ create table &outds as
and upcase(a.TABLE_NAME)="&ds"
and upcase(b.TABLE_NAME)="&ds"
%end;
order by libref, table_name, constraint_name, constraint_order
;
/* tidy up */
%mp_dropmembers(
&vw,
iftrue=(&mdebug=0)
)
%mend mp_getconstraints;