Files
dc/sas/sasjs/services/admin/exportdb.sas
T
dc 05f3f49e0c
Build / Build-and-ng-test (pull_request) Failing after 1m47s
Build / Build-and-test-development (pull_request) Skipped
Lighthouse Checks / lighthouse (pull_request) Failing after 4m46s
feat(system): export the DC library DDL from the system screen
Adds a fourth admin action to the System information screen - Export DC
Library DDL - with a secondary flavour chooser (SAS, PGSQL, TSQL) and an
optional schema box for the DB flavours. The selection is passed to the
existing services/admin/exportdb service in a new window as URL params.

Also bumps @sasjs/adapter to ^4.19.1, adds a Cypress spec for the three
flavour states, and adds a TSQL case to the exportdb SAS test.

Closes #179
2026-10-02 14:03:53 +00:00

71 lines
1.7 KiB
SAS

/**
@file
@brief Exports the data controller library in DB specific DDL
@details If user is in the administrator group, they can call this
service directly adding the following URL params:
@li &flavour= (SAS, PGSQL or TSQL - defaults to SAS)
@li &schema= (optional, if target schema is needed)
Data inserts are generated for the SAS and PGSQL flavours only; the TSQL
export contains DDL without inserts.
<h4> SAS Macros </h4>
@li mf_getuser.sas
@li mp_abort.sas
@li mp_ds2ddl.sas
@li mp_lib2inserts.sas
@li mp_streamfile.sas
@li mpe_getgroups.sas
@version 9.2
@author 4GL Apps Ltd
@copyright 4GL Apps Ltd. This code may only be used within Data Controller
and may not be re-distributed or re-sold without the express permission of
4GL Apps Ltd.
**/
%mpeinit()
%global flavour schema;
/* if no flavour is specified, default to SAS */
%let flavour=%sysfunc(coalescec(&flavour,SAS));
/* if no schema var provided, DC Libref is used */
%let schema=%sysfunc(coalescec(&schema,&dc_libref));
/* check user is in admin group */
%mpe_getgroups(user=%mf_getuser(),outds=work.usergroups)
data work.admins;
set work.usergroups;
put (_all_)(=);
run;
%let cnt=0;
proc sql noprint;
select count(*) into:cnt
from usergroups
where groupname="&mpeadmins";
%put &=cnt;
%mp_abort(iftrue= (&cnt=0)
,mac=&_program
,msg=%str(The &DC_LIBREF library can only be exported by &mpeadmins members)
)
%mp_ds2ddl(&DC_LIBREF
,flavour=&flavour
,schema=&schema
,applydttm=YES
,showlog=NO
,fref=tmpref
)
%mp_lib2inserts(&DC_LIBREF,flavour=&flavour,schema=&schema, outref=tmpref)
%mp_streamfile(contenttype=TEXT
,inref=tmpref
,outname=&dc_libref..ddl
)