23
Sat, Nov
1 New Articles

SQL 101: Tools of the Trade - Exploring SQuirreL’s SQL Editor

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Now that you’ve learned how to install this great tool, let’s see what it has to offer via a guided tour of its most interesting functionalities, starting with its SQL Editor.

Last time around, I explained how to install SQuirreL SQL, and most of the readers’ feedback was very positive. For those of you who tried and failed to install this tool, here’s a little tip: Before trying to install this tool, update your Java Runtime Engine (JRE) to the latest available. It’s true that SQuirreL’s documentation says that JRE 1.4 or higher is OK, but there are a lot of threads on the tool’s forums complaining about “unable to find the main class” errors. These errors seem to be related with the JRE version, so update to the latest available and try again. It’ll be worth it, as you’ll see in this TechTip!

Every tour needs to start somewhere, so launch SQuirreL SQL and connect to your IBM i, using the connection you created on the last TechTip of this series. If you haven’t read it, this is a good time to do so, because this is a follow-up to that article. Once the application finishes loading the schemas and other information it needs to work (and this may take a while), you’ll be presented with something similar to Figure 1.

 SQL 101: Tools of the Trade - Exploring SQuirreL’s SQL Editor - Figure 1

Figure 1: SQuirreL SQL’s screen after connecting to a database

Let’s start from the top: just below the customary menu line, there’s a connection menu bar. This bar allows you to use the “Connect to” dropdown menu to quickly connect to one of the databases you configured earlier, to set the global and new session preferences via the two small buttons next to it, and a couple of other things. Just position the mouse over each button and you’ll be presented with a tooltip text explaining what the respective button can be used for.

If you continue down, you’ll see the interesting part—the current connection tab. This tab contains a row of buttons (I’ll explain a few of them in a while, don’t worry) and, if the “SQL” sub-tab is selected, a working space similar to ACS’ Run SQL Scripts main window. However, this editor hides some time-saving goodies! I’ll demonstrate it using a schema I created for my new book, soon to be published by MC Press. You can use one of your own schemas to follow along.

Let’s start with the simplest (and arguably the best) of them: auto-complete. Try typing “sel” and press Ctrl+Space. The auto-complete tool will immediately transform the three letters you typed into SELECT. This simple, yet very useful trick is available to nearly everything, and it’s really smart: If there’s more than one match to what you’ve typed, it’ll present you a list of choices, similar to the one shown in Figure 2.

 SQL 101: Tools of the Trade - Exploring SQuirreL’s SQL Editor - Figure 2

Figure 2: Auto-complete showing a list of tables

Figure 2 shows all the tables in the UMADB_CHP5 schema that start with “tbl.” I typed “SELECT * from UMADB_CHP5.tbl” and pressed Ctrl+Space to get this list. The next step is to use the up and down arrow keys to highlight the appropriate table and press ENTER to select it. Once you have the statement completed, you can format it, just like in ACS, using another key combination: Ctrl+Alt+F.

But there’s a lot more you can do! Just right-click on the workspace and you’ll see a large context menu with the couple of functionalities I mentioned and many others, such as commenting and uncommenting a block of code, validating the SQL statement, and one that I find particularly useful when I’m writing dynamic SQL: the Quote SQL option. This option transforms your SQL statement into a string, ready to use in a stored procedure as dynamic SQL. For instance, let’s say I have the following SQL statement:

SELECT PERSON_ID, HOME_ADDRESS, HOME_PHONE_NBR, MOBILE_NBR, EMAIL_ADDRESS from umadb_chp5.TBL_PERSONS

Now I want to transform it in order to use it in a stored procedure. I follow a two-step process: first, I format the statement so that the column list is isolated in a line that I can easily manipulate, using the aforementioned “Format SQL” option. Here’s the output:

select

PERSON_ID,HOME_ADDRESS,HOME_PHONE_NBR,MOBILE_NBR,EMAIL_ADDRESS

from umadb_chp5.TBL_PERSONS

Then I right-click the block of code (a blue rectangle that delimits my statement is added by SQuirreL SQL) and select the “Quote SQL” option. The result is shown below:

"select " +

"PERSON_ID,HOME_ADDRESS,HOME_PHONE_NBR,MOBILE_NBR,EMAIL_ADDRESS " +

"from umadb_chp5.TBL_PERSONS ";

This may seem trivial, but it’s very useful, especially when you need to test long and complex statements before converting them to dynamic SQL. The process itself is simple but very prone to error. Forgetting a quotation mark (“) or a plus sign (+) can lead to annoying errors that will likely cost you precious time. Allowing this tool to do the work for you will surely save time (and give you some piece of mind)!

Let’s go back to our “regular” SQL statement and run it. You can press the icon with the running man that you’ll find in the icon strip just below the tab title (or press Ctrl+Enter) to run the currently highlighted statement. You don’t need to select the statement; just place the cursor somewhere on it and a blue rectangle will appear, delimiting the complete statement. Alternatively, you can run all the statements of the current editor by clicking on the other, smaller running dude icon (positioned to the right of the one I mentioned a moment ago) or press Alt+Shift+Enter. Figure 3, shown below, shows the result of the execution of the SQL statement I’ve been playing with, as well as the aforementioned blue rectangle and the two buttons you can use to run your statements. For your convenience, I’ve drawn a red rectangle over the two buttons.

 SQL 101: Tools of the Trade - Exploring SQuirreL’s SQL Editor - Figure 3

Figure 3: SQuirreL’s SQL editor after running a statement

But there’s more! The results pane also harbors some useful functionalities, which I’ll explain in the next TechTip, as I’m running out of space here. Until then, feel free to comment/suggest/criticize using the Comments section below.

Rafael Victoria-Pereira

Rafael Victória-Pereira has more than 20 years of IBM i experience as a programmer, analyst, and manager. Over that period, he has been an active voice in the IBM i community, encouraging and helping programmers transition to ILE and free-format RPG. Rafael has written more than 100 technical articles about topics ranging from interfaces (the topic for his first book, Flexible Input, Dazzling Output with IBM i) to modern RPG and SQL in his popular RPG Academy and SQL 101 series on mcpressonline.com and in his books Evolve Your RPG Coding and SQL for IBM i: A Database Modernization Guide. Rafael writes in an easy-to-read, practical style that is highly popular with his audience of IBM technology professionals.

Rafael is the Deputy IT Director - Infrastructures and Services at the Luis Simões Group in Portugal. His areas of expertise include programming in the IBM i native languages (RPG, CL, and DB2 SQL) and in "modern" programming languages, such as Java, C#, and Python, as well as project management and consultancy.


MC Press books written by Rafael Victória-Pereira available now on the MC Press Bookstore.

Evolve Your RPG Coding: Move from OPM to ILE...and Beyond Evolve Your RPG Coding: Move from OPM to ILE...and Beyond
Transition to modern RPG programming with this step-by-step guide through ILE and free-format RPG, SQL, and modernization techniques.
List Price $79.95

Now On Sale

Flexible Input, Dazzling Output with IBM i Flexible Input, Dazzling Output with IBM i
Uncover easier, more flexible ways to get data into your system, plus some methods for exporting and presenting the vital business data it contains.
List Price $79.95

Now On Sale

SQL for IBM i: A Database Modernization Guide SQL for IBM i: A Database Modernization Guide
Learn how to use SQL’s capabilities to modernize and enhance your IBM i database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: