Skip to content

Instantly share code, notes, and snippets.

Scott Forstie forstie

Block or report user

Report or block forstie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@forstie
forstie / JSON_TABLE and survival tips for shredding JSON with SQL
Created Aug 1, 2019
This example shows how to overcome what seems to be commonplace: JSON Web Services that return an invalid JSON document.
View JSON_TABLE and survival tips for shredding JSON with SQL
-- This fails to return data....why?
SELECT cusip, issueDate, bidToCoverRatio
FROM JSON_TABLE(
SYSTOOLS.HTTPGETCLOB('https://www.treasurydirect.gov/TA_WS/securities/announced?format=json&type=FRN&pagesize=5', null),
'$.root[*]'
COLUMNS(cusip VARCHAR(10) PATH '$.cusip',
issueDate Timestamp PATH '$.issueDate',
bidToCoverRatio double PATH '$.bidToCoverRatio')
) AS X;
stop;
@forstie
forstie / Publishing file contents using JSON and SQL.sql
Created Jun 15, 2019
Publishing file contents using JSON and SQL
View Publishing file contents using JSON and SQL.sql
stop;
-- Publish the data within a table using SQL
with json_rows (j) as (
select json_object(
key 'EMPNO' value empno, key 'FIRSTNME' value firstnme,
key 'MIDINIT' value midinit, key 'LASTNAME' value lastname,
key 'WORKDEPT' value workdept, key 'PHONENO' value phoneno,
key 'HIREDATE' value hiredate, key 'JOB' value job,
@forstie
forstie / Remove *IOSYSCFG from users and groups
Created Jul 28, 2019
This example shows the power of the REGEXP_REPLACE built-in function, when combined with IBM i Services for security and dynamic SQL.
View Remove *IOSYSCFG from users and groups
-- Author: Scott Forstie
-- Email : forstie@us.ibm.com
-- Date : July 28, 2019
--
-- Subtract '*IOSYSCFG from all users by producing the CHGUSRPRF command
-- necessary to get the job done
--
with iosyscfg_users (user_name) as (
select authorization_name
from qsys2.user_info
@forstie
forstie / Dates and TIMESTAMP_FORMAT
Last active Jul 22, 2019
Formatting date data into true date and time date types
View Dates and TIMESTAMP_FORMAT
-- Author: Scott Forstie
-- Email: forstie@us.ibm.com
create or replace variable coolstuff.decdate dec(6,0);
set coolstuff.decdate = '190718';
-- July 18, 2019 (yes, really!)
values timestamp_format(varchar(coolstuff.decdate), 'YYMMDD');
-- Wow
-- Yowza
@forstie
forstie / User profile ownership and basic authorities.sql
Last active Jul 9, 2019
The first query identifies those users who are lacking authority to use their own *USRPRF. This lack of authority can cause annoying failures in software products. The other queries are used to review whether the *USRPRF ownership implementation matches the strategy.
View User profile ownership and basic authorities.sql
--
-- description: Which users lack basic authority to their own user profile?
--
select *
from qsys2.object_privileges
where object_type = '*USRPRF'
and object_name = authorization_name
and (object_operational <> 'YES'
or object_management <> 'YES'
@forstie
forstie / Restoring libraries that begin with the letter E.sql
Created Jun 15, 2019
Restoring libraries that begin with the letter E
View Restoring libraries that begin with the letter E.sql
-- =================================================
-- author: Scott Forstie
-- date : May 29, 2019
-- email : forstie@us.ibm.com
-- disclaimer - no implied warranties, yada yada
-- =================================================
--
-- Super Fast retrieval of library and schema name
@forstie
forstie / Revieve details for active 5250 sessions.sql
Last active Jun 30, 2019
Use SQL's NETSTAT and ACTIVE_JOB_INFO services to identify and explore active 5250 sessions.
View Revieve details for active 5250 sessions.sql
--
-- description: Find active Telnet or Interactive 5250 sessions
--
-- resource: ibm.biz/WellDefinedIBMiPorts
--
select remote_address, remote_port, authorization_name as user_name, job_name
from qsys2.netstat_job_info n
where local_port in (23,992) and job_type = 'INTERACTIVE';
--
@forstie
forstie / printf to the Joblog using SQL.sql
Created Jun 15, 2019
printf to the Joblog using SQL
View printf to the Joblog using SQL.sql
--
-- description: printf to the Joblog, using SQL
--
cl:addlible qsysinc;
cl:crtsrcpf qtemp/qcsrc;
cl:addpfm file(qtemp/qcsrc) mbr(LPRINTF);
insert into qtemp.qcsrc values
(1,010101,'{'),
(2,010101,'extern int Qp0zLprintf (char *format, ...);'),
@forstie
forstie / GO SAVE Option 21 history via SQL.sql
Created Jun 28, 2019
Use SQL to retrieve the QUSRSYS/QSRSAV21 *DTAARA and transform the detail therewithin into consumable history.
View GO SAVE Option 21 history via SQL.sql
-- Author: Scott Forstie
-- Date : June 28, 2019
-- Email : forstie@us.ibm.com
--
-- ==============
-- Basic Version
-- ==============
--
--
@forstie
forstie / Change trigger programs in production.sql
Created Jun 26, 2019
This example shows how to use the ALLOW_DDL_CHANGES_WHILE_OPEN QAQQINI option within a specific job to avoid the requirement of needing an exlusive lock for the *FILE object, before making a change to a trigger program.
View Change trigger programs in production.sql
--
-- Create, Replace, Delete, or Disable trigger programs
-- without acquiring an exclusive lock over the file
-- =======
--
-- Resource: ibmsystemsmag.com/blogs/i-can/august-2017/manage-trigger-programs-in-productions
-- Prepare to break the rules
call qsys2.override_qaqqini(1, '', '');
-- Rules broken
You can’t perform that action at this time.