Skip to content

Instantly share code, notes, and snippets.

View ghitti's full-sized avatar
🎯
Focusing

Roberto Ghitti ghitti

🎯
Focusing
View GitHub Profile
@ghitti
ghitti / isUniqueKey
Created January 31, 2020 14:16
Determine DDS described physical files with unique keys
-- Determine DDS described physical files with unique Keys
SELECT a.*
FROM QSYS2.SYSPARTITIONINDEXSTAT a
WHERE Table_Schema = 'yourSchema'
AND Index_Type = 'PHYSICAL'
AND UNIQUE = '0';
@ghitti
ghitti / readCsvFromIfs
Last active January 31, 2020 14:16
Read *csv File from IFS (IBM i)
-- Read *csv File from IFS
With x as (-- Split IFS File into Rows (at CRLF)
Select Ordinal_Position as RowKey, Element as RowInfo
from Table(SysTools.Split(Get_Clob_From_File('/home/myFile.csv'), x'0D25')) a
Where Trim(Element) > ''),
y as (-- Split IFS File Rows into Columns (and remove leading/trailing double quotes ")
Select x.*, Ordinal_Position ColKey,
Trim(B '"' from Element) as ColInfo
from x cross join Table(SysTools.Split(RowInfo, ',')) a)
-- Return the Result as Table
@ghitti
ghitti / whichFilesAreJournaledOnIBMi
Created January 31, 2020 14:09
Which files in a library, are journaled?
WITH FILES(
objLib,
objName,
objSize,
objText,
journalLibrary,
journalName)
AS (
SELECT OBJLIB,
OBJNAME,
@ghitti
ghitti / sendEmail.sql
Created July 23, 2019 12:17
send email via sql
-- setup
cl: STRTCPSVR SERVER(*SMTP) ;
cl: ADDUSRSMTP USRPRF(SCOTTF);
cl: ADDUSRSMTP USRPRF(TIMMR);
-- Send SMTP E-mail Message (SNDSMTPEMM)
cl:SNDSMTPEMM RCP(('forstie@us.ibm.com' *pri)) SUBJECT('hello world again') NOTE('this is a new note');
cl:SNDSMTPEMM RCP(('forstie@us.ibm.com' *pri)) SUBJECT('hello world again') NOTE('this is a new note');
select * from SQLISFUN00.may17objs;
@ghitti
ghitti / bootstrap.sql
Created July 23, 2019 12:10
Bootstrap Python on IBM i
create or replace table qtemp.ftpcmd(cmd char(240)) on replace delete rows;
create or replace table qtemp.ftplog(line char(240)) on replace delete rows;
insert into qtemp.ftpcmd(CMD) values
('anonymous anonymous@example.com')
,('namefmt 1')
,('lcd /tmp')
,('cd /software/ibmi/products/pase/rpms')
,('bin')
,('get README.md (replace')