Thursday, March 31, 2022

World backup day

A day like today is a good reminder of the importance of backups. I am sure we have all had to restore data from a backup many times in our lives in IT.

Do you know if your company's backup are valid? It always surprises me how many company's purchase a new device for backups, tape drive or VTL, and never try to do a test restore. Trust me you want to make sure you know how to restore data from the device before your really need to.

Not really part of backups but make sure you only retain backups for the time they might be needed, this varies by industry and would imagine by country too. Once the backup has passed the retention date destroy it. I have been through an e-discovery process, it became an almost full-time job for a month to find every backup that was on premise, off site, and even in the IT members cars and homes. It gets expensive too when you are asked to restore data from tapes you no longer have a tape drive for, and you have to contract with a third party to do it on your behalf. It is so much easier to tell the auditors that, in agreement with your company's legal department and the written company policy, all backups are destroyed after the designated period of time.

Wednesday, March 30, 2022

SQL indexes suggested from the job log

sql ddl indexes advised by debug

I have written before about how Db2 for i will suggest indexes, using the SYSIXADV view or Navigator for i, that will improve the performance of your SQL programs, etc. There are times I need to know if any indexes are advised when a program has run just once.

Fortunately this information is written to the job log, when the statement is executed in the program.

Before I demonstrate that I need a SQL DDL table I can use:

CREATE OR REPLACE TABLE MYLIB.TABLE1
(FIRST VARCHAR(20),
 SECOND VARCHAR(20))
ON REPLACE DELETE ROWS

Notice that the table does not have a key.

Thursday, March 24, 2022

Changes to the RFE process

new rfe process

This morning I received an email from IBM informing that there are changes coming to the RFE, Request For Enhancement, process.

IBM uses the RFE process to drive a lot of the enhancements they add to new releases and Technology Refreshes to all of their products, including IBM i. If you have an idea you think would be a valid improvement to IBM i you would a submit an RFE. Other people can vote on the RFE if they agree it would be a worthwhile enhancement.

I am not going to repeat what IBM has already published on their Community web site. What I am going to do is to give you this link to it here.

If you have a bookmark in your browser to the RFE old web page you will need to delete your existing one and create a new one as it is now found at a different URL.

I encourage you all to submit RFEs if you have any ideas, and vote on others. If you don't IBM will never know that wonderful idea you just came up with.

Wednesday, March 23, 2022

Encrypting data with SQL

encrpyt columns with sql

December 14, 2023 Update:
256 byte enhanced version of AES encryption is available.


 

There are two ways we can do this, set an encryption password within a program and use that, or give the password with every insert or update. My preference is the first scenario.

Before I start encrypting data, I need a DDL table in which to put it all:

01  CREATE OR REPLACE TABLE MYLIB.TABLE1
02    (UNENCRYPTED VARCHAR(10),
03     TYPE_AES VARCHAR(128) FOR BIT DATA,
04     TYPE_RC2 VARCHAR(128) FOR BIT DATA,
05     TYPE_TDES VARCHAR(128) FOR BIT DATA,
06     PRIMARY KEY(UNENCRYPTED))
07  ON REPLACE DELETE ROWS ;

Monday, March 14, 2022

SQL has a constant for pi

using pi in sql

Today is 3/14 in *MDY format, it is called pi day in recognition of the mathematical constant of the same name. Therefore, I thought that this would be the ideal occasion to write about the SQL scalar function PI().

Many years ago when I was at school, I was taught that pi is the fraction 22/7. This is not exactly true. The ancient Greek mathematician Archimedes stated that pi, or π in Greek, is a number be approximated as being between the fractions 223/71 and 22/7. It is not exactly 22/7, but that is considered the most popular approximation.

SQL does better than any approximation. If I use the scalar function PI() I am given the true value of pi to 15 decimal places.

I say PI() as the function is not passed any parameters. Then why should it as pi is a constant.

How does PI() compare to the approximations? As I am using ACS's Run SQL Scripts I would just use the following statement:

Wednesday, March 9, 2022

Media library information with SQL

media library information and status

A recent upgrade to a new virtual tape library, VTL, product introduced me to the concepts of a tape library and to a new command Work with Media Library Status, WRKMLBSTS. The system admins came to me asked if there was a way I could get to the same information as is displayed by WRKMLBSTS.

They had become frustrated with the command as it did not offer the ability to output its results to an outfile or a spool file, that they would then copy to a file.

"Is there something in SQL you can work your magic with?" they asked.

A quick search of IBM's documentation portal gave me what was needed, a view called MEDIA_LIBRARY_INFO.

Wednesday, March 2, 2022

Finding open cursors within a job

looking for open sql cursors

It is possible to leave a SQL cursor when you exit a program.

Personally I prevent a cursor being left open by use of the SET OPTION SQL statement in my RPG program:

exec sql SET OPTION CLOSQLCSR=*ENDMOD ;

Or when I create the object I make sure that the Close SQL Cursor parameter, CLOSQLCSR, is set to *ENDMOD:

CRTSQLRPGI OBJ(MYLIB/MY_PROGRAM)
            SRCFILE(MYLIB/DEVSRC)
            CLOSQLCSR(*ENDMOD)

Not everyone is as vigilant or as cautious as I am. If a program ends abnormally, or the cursor is not closed with the SQL close statement: