Created
October 11, 2023 12:05
-
-
Save NielsLiisberg/54019313fe6189884131eda78b7934c6 to your computer and use it in GitHub Desktop.
SQL - Delete (unlink) a IFS file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SQL Scalar function to delete ( unlink) a IFS files | |
-- this is a wrapper for unlink (delete IFS files) system / unix API | |
-- Simply paste this gist into ACS SQL and run it to create the UDTF. | |
-- Note: I am using library QUSRSYS. I suggest you put it into your own tool library | |
-- It is a cool example how far you can go with SQL: Have fun - | |
-- (C) Niels Liisberg 2023 | |
-- This gist is distributed on an "as is" basis, without warranties | |
-- or conditions of any kind, either express or implied. | |
---------------------------------------------------------------------------------------------- | |
call qcmdexc ('addlible qsysinc'); | |
call qcmdexc ('dltf FILE(QTEMP/C) '); | |
call qcmdexc ('crtsrcpf FILE(QTEMP/C) MBR(C) rcdlen(256)'); | |
truncate qtemp.c; | |
insert into qtemp.c (srcdta) values | |
('#include <unistd.h>'), | |
('IFS_DELETE_FILE.FILE_NAME.DAT[IFS_DELETE_FILE.FILE_NAME.LEN] = 0;'), | |
('MAIN.RC = unlink ( IFS_DELETE_FILE.FILE_NAME.DAT);') | |
; | |
create or replace function qusrsys.ifs_delete_file ( | |
file_name varchar(256) | |
) | |
returns int | |
specific IFS_DLTFIL | |
no external action | |
set option output=*print, commit=*none, dbgview = *source | |
main: | |
begin | |
declare rc int default 0; | |
include qtemp/c(c); | |
return rc; | |
end; | |
stop; | |
-- Test and usecase from here: | |
------------------------------ | |
values qusrsys.ifs_delete_file ( | |
file_name => '/tmp/b.txt' | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment