mirror of
https://github.com/sasjs/core.git
synced 2026-04-10 18:33:14 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78287ed5d3 | ||
|
|
5944619488 | ||
|
|
df0c9899cf | ||
|
|
737eb65251 | ||
|
|
c50555a6e2 | ||
|
|
c69639a228 | ||
|
|
9930b84785 | ||
|
|
7686b7fb99 | ||
|
|
def0514731 |
57
all.sas
57
all.sas
@@ -1018,8 +1018,9 @@ or %index(&pgm,/tests/testteardown)
|
|||||||
%local dsid vnum rc schema;
|
%local dsid vnum rc schema;
|
||||||
/* in case the parameter is a libref.tablename, pull off just the libref */
|
/* in case the parameter is a libref.tablename, pull off just the libref */
|
||||||
%let libref = %upcase(%scan(&libref, 1, %str(.)));
|
%let libref = %upcase(%scan(&libref, 1, %str(.)));
|
||||||
|
/* sysname can be 'Schema/Owner' or just 'Schema' (eg snowflake) */
|
||||||
%let dsid=%sysfunc(open(sashelp.vlibnam(where=(
|
%let dsid=%sysfunc(open(sashelp.vlibnam(where=(
|
||||||
libname="%upcase(&libref)" and sysname='Schema/Owner'
|
libname="%upcase(&libref)" and sysname=:'Schema'
|
||||||
)),i));
|
)),i));
|
||||||
%if (&dsid ^= 0) %then %do;
|
%if (&dsid ^= 0) %then %do;
|
||||||
%let vnum=%sysfunc(varnum(&dsid,SYSVALUE));
|
%let vnum=%sysfunc(varnum(&dsid,SYSVALUE));
|
||||||
@@ -15372,7 +15373,8 @@ run;
|
|||||||
%else %if &engine=ODBC %then %do;
|
%else %if &engine=ODBC %then %do;
|
||||||
%&mD.put NOTE: Retrieving ODBC connection details;
|
%&mD.put NOTE: Retrieving ODBC connection details;
|
||||||
data _null_;
|
data _null_;
|
||||||
length connx_uri conprop_uri value datasource up_uri schema domprop_uri authdomain $256.;
|
length connx_uri conprop_uri value datasource up_uri schema domprop_uri
|
||||||
|
authdomain $256.;
|
||||||
call missing (of _all_);
|
call missing (of _all_);
|
||||||
/* get source connection ID */
|
/* get source connection ID */
|
||||||
rc=metadata_getnasn("&liburi",'LibraryConnection',1,connx_uri);
|
rc=metadata_getnasn("&liburi",'LibraryConnection',1,connx_uri);
|
||||||
@@ -15572,6 +15574,55 @@ run;
|
|||||||
|
|
||||||
libname &libref SQLSVR datasrc=&path schema=&schema user="&user" pass="&pass";
|
libname &libref SQLSVR datasrc=&path schema=&schema user="&user" pass="&pass";
|
||||||
%end;
|
%end;
|
||||||
|
%else %if &engine=SASIOSNF or &engine=SNOW %then %do;
|
||||||
|
%&mD.put NOTE: Retrieving SNOW connection details;
|
||||||
|
data _null_;
|
||||||
|
length connx_uri conprop_uri value server up_uri schema domprop_uri
|
||||||
|
authdomain database $256.;
|
||||||
|
call missing (of _all_);
|
||||||
|
/* get source connection ID */
|
||||||
|
rc=metadata_getnasn("&liburi",'LibraryConnection',1,connx_uri);
|
||||||
|
/* get connection properties */
|
||||||
|
i=0;
|
||||||
|
do until (rc2<0);
|
||||||
|
i+1;
|
||||||
|
rc2=metadata_getnasn(connx_uri,'Properties',i,conprop_uri);
|
||||||
|
rc3=metadata_getattr(conprop_uri,'Name',value);
|
||||||
|
if value='Connection.DBMS.Property.SERVER.Name.xmlKey.txt' then do;
|
||||||
|
rc4=metadata_getattr(conprop_uri,'DefaultValue',server);
|
||||||
|
rc2=-1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
/* get auth domain */
|
||||||
|
autrc=metadata_getnasn(connx_uri,"Domain",1,domprop_uri);
|
||||||
|
arc=metadata_getattr(domprop_uri,"Name",authdomain);
|
||||||
|
if not missing(authdomain) then authdomain=cats('AUTHDOMAIN=',authdomain);
|
||||||
|
call symputx('authdomain',authdomain,'l');
|
||||||
|
|
||||||
|
/* get SCHEMA */
|
||||||
|
rc6=metadata_getnasn("&liburi",'UsingPackages',1,up_uri);
|
||||||
|
rc7=metadata_getattr(up_uri,'SchemaName',schema);
|
||||||
|
&mD.put rc= connx_uri= rc2= conprop_uri= rc3= value= rc4= server=
|
||||||
|
rc6= up_uri= rc7= schema=;
|
||||||
|
|
||||||
|
/* get database value */
|
||||||
|
prop='Connection.DBMS.Property.DB.Name.xmlKey.txt';
|
||||||
|
rc=metadata_getprop("&liburi",prop,database,"");
|
||||||
|
if database^='' then database='database='!!quote(trim(database));
|
||||||
|
call symputx('database',database,'l');
|
||||||
|
|
||||||
|
call symputx('snow_schema',schema,'l');
|
||||||
|
call symputx('snow_server',server,'l');
|
||||||
|
run;
|
||||||
|
|
||||||
|
libname &libref SNOW SERVER="&snow_server" SCHEMA=&snow_schema &authdomain
|
||||||
|
&database;
|
||||||
|
%if %length(&open_passthrough)>0 %then %do;
|
||||||
|
proc sql;
|
||||||
|
connect using &libref as &open_passthrough;
|
||||||
|
%end;
|
||||||
|
%end;
|
||||||
%else %if &engine=TERADATA %then %do;
|
%else %if &engine=TERADATA %then %do;
|
||||||
%put NOTE: Obtaining &engine library details;
|
%put NOTE: Obtaining &engine library details;
|
||||||
data _null;
|
data _null;
|
||||||
@@ -26427,7 +26478,7 @@ libname &libref1a JSON fileref=&fname1a;
|
|||||||
%let found=0;
|
%let found=0;
|
||||||
/* %put Getting object uri from &libref1a..items; */
|
/* %put Getting object uri from &libref1a..items; */
|
||||||
data _null_;
|
data _null_;
|
||||||
length contenttype name $1000;
|
length contenttype name uri $1000;
|
||||||
call missing(of _all_);
|
call missing(of _all_);
|
||||||
set &libref1a..items;
|
set &libref1a..items;
|
||||||
if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do;
|
if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do;
|
||||||
|
|||||||
@@ -25,8 +25,9 @@
|
|||||||
%local dsid vnum rc schema;
|
%local dsid vnum rc schema;
|
||||||
/* in case the parameter is a libref.tablename, pull off just the libref */
|
/* in case the parameter is a libref.tablename, pull off just the libref */
|
||||||
%let libref = %upcase(%scan(&libref, 1, %str(.)));
|
%let libref = %upcase(%scan(&libref, 1, %str(.)));
|
||||||
|
/* sysname can be 'Schema/Owner' or just 'Schema' (eg snowflake) */
|
||||||
%let dsid=%sysfunc(open(sashelp.vlibnam(where=(
|
%let dsid=%sysfunc(open(sashelp.vlibnam(where=(
|
||||||
libname="%upcase(&libref)" and sysname='Schema/Owner'
|
libname="%upcase(&libref)" and sysname=:'Schema'
|
||||||
)),i));
|
)),i));
|
||||||
%if (&dsid ^= 0) %then %do;
|
%if (&dsid ^= 0) %then %do;
|
||||||
%let vnum=%sysfunc(varnum(&dsid,SYSVALUE));
|
%let vnum=%sysfunc(varnum(&dsid,SYSVALUE));
|
||||||
|
|||||||
52
meta/mm_assigndirectlib.sas
Executable file → Normal file
52
meta/mm_assigndirectlib.sas
Executable file → Normal file
@@ -213,7 +213,8 @@ run;
|
|||||||
%else %if &engine=ODBC %then %do;
|
%else %if &engine=ODBC %then %do;
|
||||||
%&mD.put NOTE: Retrieving ODBC connection details;
|
%&mD.put NOTE: Retrieving ODBC connection details;
|
||||||
data _null_;
|
data _null_;
|
||||||
length connx_uri conprop_uri value datasource up_uri schema domprop_uri authdomain $256.;
|
length connx_uri conprop_uri value datasource up_uri schema domprop_uri
|
||||||
|
authdomain $256.;
|
||||||
call missing (of _all_);
|
call missing (of _all_);
|
||||||
/* get source connection ID */
|
/* get source connection ID */
|
||||||
rc=metadata_getnasn("&liburi",'LibraryConnection',1,connx_uri);
|
rc=metadata_getnasn("&liburi",'LibraryConnection',1,connx_uri);
|
||||||
@@ -413,6 +414,55 @@ run;
|
|||||||
|
|
||||||
libname &libref SQLSVR datasrc=&path schema=&schema user="&user" pass="&pass";
|
libname &libref SQLSVR datasrc=&path schema=&schema user="&user" pass="&pass";
|
||||||
%end;
|
%end;
|
||||||
|
%else %if &engine=SASIOSNF or &engine=SNOW %then %do;
|
||||||
|
%&mD.put NOTE: Retrieving SNOW connection details;
|
||||||
|
data _null_;
|
||||||
|
length connx_uri conprop_uri value server up_uri schema domprop_uri
|
||||||
|
authdomain database $256.;
|
||||||
|
call missing (of _all_);
|
||||||
|
/* get source connection ID */
|
||||||
|
rc=metadata_getnasn("&liburi",'LibraryConnection',1,connx_uri);
|
||||||
|
/* get connection properties */
|
||||||
|
i=0;
|
||||||
|
do until (rc2<0);
|
||||||
|
i+1;
|
||||||
|
rc2=metadata_getnasn(connx_uri,'Properties',i,conprop_uri);
|
||||||
|
rc3=metadata_getattr(conprop_uri,'Name',value);
|
||||||
|
if value='Connection.DBMS.Property.SERVER.Name.xmlKey.txt' then do;
|
||||||
|
rc4=metadata_getattr(conprop_uri,'DefaultValue',server);
|
||||||
|
rc2=-1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
/* get auth domain */
|
||||||
|
autrc=metadata_getnasn(connx_uri,"Domain",1,domprop_uri);
|
||||||
|
arc=metadata_getattr(domprop_uri,"Name",authdomain);
|
||||||
|
if not missing(authdomain) then authdomain=cats('AUTHDOMAIN=',authdomain);
|
||||||
|
call symputx('authdomain',authdomain,'l');
|
||||||
|
|
||||||
|
/* get SCHEMA */
|
||||||
|
rc6=metadata_getnasn("&liburi",'UsingPackages',1,up_uri);
|
||||||
|
rc7=metadata_getattr(up_uri,'SchemaName',schema);
|
||||||
|
&mD.put rc= connx_uri= rc2= conprop_uri= rc3= value= rc4= server=
|
||||||
|
rc6= up_uri= rc7= schema=;
|
||||||
|
|
||||||
|
/* get database value */
|
||||||
|
prop='Connection.DBMS.Property.DB.Name.xmlKey.txt';
|
||||||
|
rc=metadata_getprop("&liburi",prop,database,"");
|
||||||
|
if database^='' then database='database='!!quote(trim(database));
|
||||||
|
call symputx('database',database,'l');
|
||||||
|
|
||||||
|
call symputx('snow_schema',schema,'l');
|
||||||
|
call symputx('snow_server',server,'l');
|
||||||
|
run;
|
||||||
|
|
||||||
|
libname &libref SNOW SERVER="&snow_server" SCHEMA=&snow_schema &authdomain
|
||||||
|
&database;
|
||||||
|
%if %length(&open_passthrough)>0 %then %do;
|
||||||
|
proc sql;
|
||||||
|
connect using &libref as &open_passthrough;
|
||||||
|
%end;
|
||||||
|
%end;
|
||||||
%else %if &engine=TERADATA %then %do;
|
%else %if &engine=TERADATA %then %do;
|
||||||
%put NOTE: Obtaining &engine library details;
|
%put NOTE: Obtaining &engine library details;
|
||||||
data _null;
|
data _null;
|
||||||
|
|||||||
30
tests/sas9only/mm_assigndirectlib.test.sas
Normal file
30
tests/sas9only/mm_assigndirectlib.test.sas
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mm_assigndirectlib macro
|
||||||
|
@details A valid library must first be configured in metadata.
|
||||||
|
To test success, also define a table for which we can test the existence.
|
||||||
|
This is a unit test - not part of the full test run, as it would be a
|
||||||
|
lot of overhead to create an external DB and metadata setup each time.
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_existds.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
@li mp_assertscope.sas
|
||||||
|
@li mm_assigndirectlib.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%let runtest=0;
|
||||||
|
%let libref=XXX;
|
||||||
|
%let ds=XXXX;
|
||||||
|
|
||||||
|
|
||||||
|
%mp_assertscope(SNAPSHOT)
|
||||||
|
%mm_assigndirectlib(&libref)
|
||||||
|
%mp_assertscope(COMPARE)
|
||||||
|
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&runtest=1 and %mf_existds(&libref..&ds)),
|
||||||
|
desc=Check if &libref..&ds exists
|
||||||
|
)
|
||||||
@@ -117,7 +117,7 @@ libname &libref1a JSON fileref=&fname1a;
|
|||||||
%let found=0;
|
%let found=0;
|
||||||
/* %put Getting object uri from &libref1a..items; */
|
/* %put Getting object uri from &libref1a..items; */
|
||||||
data _null_;
|
data _null_;
|
||||||
length contenttype name $1000;
|
length contenttype name uri $1000;
|
||||||
call missing(of _all_);
|
call missing(of _all_);
|
||||||
set &libref1a..items;
|
set &libref1a..items;
|
||||||
if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do;
|
if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do;
|
||||||
|
|||||||
Reference in New Issue
Block a user