Skip to content

Instantly share code, notes, and snippets.

@MichaelDelk
MichaelDelk / sql-snippets-db2-2025.sql
Last active May 5, 2025 15:29
SQL Snippets for DB2 (IBMi) 2025
--
-- @document sql-snippets-2025
--
--
-- @desc Select/Delete Spooled Files in Output queue
--
-- @parms delete-older-than A timestamp value that defines the starting point
-- for deleting spooled files. Any spooled file older than this
-- timestamp is eligible for deletion. The default is
<?php
$sql="SELECT
CAST(1 as smallint) as smallint,
CAST(2 as INTEGER) as INTEGER,
CAST(3 as BIGINT) as BIGINT,
CAST(4. as real) as real,
CAST(5.1 as FLOAT) as FLOAT,
CAST(6.1 as DOUBLE) as DOUBLE,
CAST(7.1 as DECIMAL) as DECIMAL,
CAST(8.1 as NUMERIC) as NUMERIC,
@MichaelDelk
MichaelDelk / DB2ErrorHandler.php
Created January 25, 2024 22:41 — forked from phpdave/DB2ErrorHandler.php
A PHP error handler to dump out what happened on the #IBMi #DB2 before an error occured.
<?
//only output the error if we're in the development environment
$APPLICATION_ENV="dev";
//set error handler to the callback function defined later
set_error_handler("myErrorHandler");
//connect to db
$db2Connection = db2_connect( '', '' , '',array('i5_lib' => 'QSYS'));
if (!$db2Connection)
@MichaelDelk
MichaelDelk / Retrieve details for active 5250 sessions.sql
Created January 25, 2024 22:34 — forked from forstie/Retrieve details for active 5250 sessions.sql
Use SQL's NETSTAT and ACTIVE_JOB_INFO services to identify and explore active 5250 sessions.
--
-- 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';
--
@MichaelDelk
MichaelDelk / Who am i.sql
Last active January 25, 2024 22:24 — forked from forstie/Who am i.sql
Basic identity detail for the IBM i: Incorporated columns recommended in comments on Scott Forstie's original gist.
--
-- Who am i?
--
SELECT s.host_name, e.host_name, 'IBM i ' CONCAT os_version CONCAT '.' CONCAT os_release AS ibmi_level
, serial_number, machine_type, machine_model
, (SELECT Processor_Group FROM Qsys2.License_Info FETCH FIRST ROW ONLY) AS P_Group
, ipl_mode, ipl_type, attention_light
, total_cpus, e.configured_cpus
, configured_memory, total_memory
, (SELECT MAX(PTF_IDENTIFIER) FROM QSYS2.PTF_INFO WHERE PTF_TECHNOLOGY_REFRESH_PTF = 'YES' AND PTF_LOADED_STATUS ='PERMANENTLY APPLIED') AS TR_PTF
--
-- @document sql-snippets-2024
--
--
-- @desc Invoke IBMi CL command from SQL.
-- While this example shows a single invocation of ADDLIBLE to
-- illustrate use, library list and enviroment setup would
-- normally be handled by using QCMDEXC to call an IBMi program,
-- passing an environment paramaeter so that multiple libraries