mirror of
https://github.com/sasjs/core.git
synced 2026-01-16 04:50:05 +00:00
fix: adding constraint_order to mp_getconstraints
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
@param [out] outds= (mp_getconstraints) the output dataset
|
@param [out] outds= (mp_getconstraints) the output dataset
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquename.sas
|
||||||
|
@li mp_dropmembers.sas
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -36,6 +38,27 @@
|
|||||||
%let lib=%upcase(&lib);
|
%let lib=%upcase(&lib);
|
||||||
%let ds=%upcase(&ds);
|
%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 */
|
/* must use SQL as proc datasets does not support length changes */
|
||||||
proc sql noprint;
|
proc sql noprint;
|
||||||
create table &outds as
|
create table &outds as
|
||||||
@@ -44,8 +67,9 @@ create table &outds as
|
|||||||
,a.constraint_type
|
,a.constraint_type
|
||||||
,a.constraint_name
|
,a.constraint_name
|
||||||
,b.column_name
|
,b.column_name
|
||||||
|
,b.constraint_order
|
||||||
from dictionary.TABLE_CONSTRAINTS a
|
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)
|
on upcase(a.TABLE_CATALOG)=upcase(b.TABLE_CATALOG)
|
||||||
and upcase(a.TABLE_NAME)=upcase(b.TABLE_NAME)
|
and upcase(a.TABLE_NAME)=upcase(b.TABLE_NAME)
|
||||||
and a.constraint_name=b.constraint_name
|
and a.constraint_name=b.constraint_name
|
||||||
@@ -58,6 +82,13 @@ create table &outds as
|
|||||||
and upcase(a.TABLE_NAME)="&ds"
|
and upcase(a.TABLE_NAME)="&ds"
|
||||||
and upcase(b.TABLE_NAME)="&ds"
|
and upcase(b.TABLE_NAME)="&ds"
|
||||||
%end;
|
%end;
|
||||||
|
order by libref, table_name, constraint_name, constraint_order
|
||||||
;
|
;
|
||||||
|
|
||||||
|
/* tidy up */
|
||||||
|
%mp_dropmembers(
|
||||||
|
&vw,
|
||||||
|
iftrue=(&mdebug=0)
|
||||||
|
)
|
||||||
|
|
||||||
%mend mp_getconstraints;
|
%mend mp_getconstraints;
|
||||||
Reference in New Issue
Block a user