Thursday, July 29, 2021

Ten years since Mythbusters: Stored Procedures Edition

Today it's exactly ten years since I published my blog post called Mythbusters: Stored Procedures Edition

Using "stored procedures" (ie storing and executing code in your database, next to the data, instead of in a middle tier or client) is a practice that is provably both efficient and secure, yet it is often dismissed as "wrong".

My original blog post looks at the usual reasons given against the use of stored procedures for "business logic" (or for anything at all, really) and explains why they tend to be myths (or outright lies), repeated so many times that they are taken as the truth. Take a moment to read the article now.

Publishing the article proved that advocating for the use of stored procedures, which had gone out of fashion already by 2011, was controversial. It caused an immediate spike in my blog traffic, receiving almost 20 000 page views in a single day (at the time, my blog had perhaps a few hundred page views per day on average). The article was picked up by Hacker News and generated a lively discussion there.

So, where are we in 2021, ten years later?

Mainstream development (still) uses imperative, object-oriented 3GL languages (Java, .NET, etc) running in the middle tier or client, dragging data out from the database to process it, with data access usually abstracted through an ORM. Which, predictably, results in suboptimal performance.

The myths about stored procedures are still prevalent. Ask a random Java/.NET developer today, and I bet he will claim that it's impossible to version control stored procedures (myth #1). In that case, please send him a link to that 10-year old article...



 

 

Sunday, November 8, 2020

New version of Quick PL/SQL, a code generator for PL/SQL

I've released a new version of Quick PL/SQL, the code generator for PL/SQL based on the same concept as QuickSQL in APEX, but for PL/SQL code. The initial version was released in August 2018.

The online version is available (as before) here: tinyurl.com/quickplsql2

The source code is available on my GitHub.

This release (version 1.2) has a few improvements. The first is syntax highlighting of the generated code (right hand side of the page). This relies on the CodeMirror library which is bundled with APEX. Unfortunately it only supports SQL, not PL/SQL, so not all code is properly highlighted, but it's better than nothing.




The second improvement is a "Quick CRUD" button which opens a dialog that allows you to specify a table name (and optionally the name of the primary key column and the package name):


Based on this it creates the markup required for a complete "CRUD package" in the Input section, which saves you from remembering the markup syntax, and saves you from typing a lot of boilerplate markup as well.

Then, as before, just click on "Generate" to have the final PL/SQL generated for you.




Enjoy! :-)



Sunday, December 8, 2019

Translation enhancements in APEX 18 and 19

The Oracle Application Express (APEX) documentation summarizes the translation process thus:

"To translate an application developed in App Builder, you must map the primary and target language, seed and export text to a translation file, translate the text, apply the translation file, and publish the translated application."

When you go to Shared Components and then click "Translate Application", this process is illustrated by a list:

So the "default" approach is to download the XLIFF file and use a third-party tool to do the translation by editing that file.

However, it is also possible to edit the translations directly from within APEX. Click on "Translation Repository" under Translation Utilities to access this editor.



A few simple, but very useful enhancements have been made to the Translation Repository pages in the last couple of APEX versions.

 In APEX 19, there is now a new column available called "Translated" which indicates whether the original string has been translated or not. Using this column it is easy to filter out the strings already translated.




The popup edit window for the translation has a checkbox, added in APEX 18, that allows you to update all existing occurrences of the source string with a new translation. This is useful if you have, for example, 100 buttons with the label "Save Changes" because you only need to do the translation once.



Also in APEX 18, a "Grid Edit" page was added so you could edit the translations using a tabular form. In APEX 19, this tabular form was replaced with an interactive grid.



This interactive grid also includes the "Translated" column that can be used to filter out the translations which are already done.

Note that sorting by the "Translate From" or "Translate To" columns in the interactive grid is not possible (if you try you'll get an "ORA-00932: inconsistent datatypes: expected - got NCLOB" error). But the list of available columns include "Translate From (Partial)" and "Translate To (Partial)" which extracts the first part of the string as a regular varchar2 (usually the strings to translate are not that long so you'll see the full string in the "Partial" column). If you need to sort the strings (I find it useful to sort alphabetically by the source string in order to find identical strings and use copy/paste to update the translation), use these "Partial" columns to set up the sorting.


Thanks to Joel Kallmann for taking the time to add these small but very useful enhancements into APEX based on my feedback.


Sunday, June 16, 2019

APEX custom Theme Style performance

When you create an application in Oracle Application Express (APEX) using the Universal Theme, the application comes with a few default "Theme Styles" which are essentially various stylesheets that you can switch between to go from the default blue (called "Vita") to, for example, the dark grey style (called "Vita - Slate").

You can use the Theme Roller in Oracle Application Express (APEX) to customize the colors and other settings, and by saving these you create your own Theme Styles. In this video, Shakeeb from the Oracle APEX team demonstrates how to use the Theme Roller, and he also briefly mentions that the generated stylesheet for custom theme styles can be placed into the filesystem for better performance.



I recorded a video myself to discuss the details of how custom Theme Styles affect the performance of your APEX application, and how you can move the Theme Style generated stylesheets to a web server to maximize performance and minimize bandwidth consumption:




Another issue that I did not mention in the video is that when you pick an icon for your application, APEX creates an app-icon.svg file (for the logo itself) and app-icon.css (that references the svg file), and places both those files in your Static Application Files.

Now since these files (and all other Static Application Files) are stored in the database, they require a database hit to retrieve, instead of fetching them from (and caching them on) the web server filesystem.



So if you want to maximize performance, I suggest that you remove the reference to the logo CSS file from your application (and delete the files from the Static Application Files).


If you really want that logo icon, you could of course place the .svg and .css files on the web server and reference them from there instead.


Thursday, April 25, 2019

Thoth Gateway version 1.4.3 now available

I've updated the Thoth Gateway (a PL/SQL web gateway similar to mod_plsql and ORDS, but written in .NET that allows you to run APEX and PL/SQL Web Toolkit applications using Microsoft IIS web server).



The latest release is version 1.4.3. It fixes a few minor issues, but more importantly it is compiled against the latest ODP.NET Managed Driver.

Among other things, this version of the Managed Driver supports Oracle Advanced Security Option (ASO) encryption; without this certain operations such as APEX file uploads would cause "OracleInternal.Network.NetworkException: ORA-12537: Network Session: End of file" errors against an Oracle 18c database.

When upgrading to Thoth Gateway v1.4.3 or later, please make sure you also copy the Oracle.ManagedDataAccess.dll file in addition to the PLSQLGatewayModule.dll file to make sure you have the correct library.

Enjoy!



Wednesday, January 30, 2019

APEX Plugin: Execute PL/SQL code and return content to page (updated)

Oracle APEX has a built-in Dynamic Action called "Execute PL/SQL Code" that executes a block of PL/SQL code on the server via an Ajax call (ie does not do a regular submit and reload of the whole page).

But what if you want to do something on the server AND also return some content back to the client? Back in 2012 I released an APEX Dynamic Action plugin called "Execute PL/SQL Code and Return Content" that allows you to do just that. Read the original blog post for more information.



Since then, the APEX framework has evolved and the old Ajax workhorse function called "htmldb_Get" has been deprecated and replaced with functions in the "apex.server" namespace. Hence I have updated my plugin to use the modern API.

You can find the updated version (1.1) of the plugin on my GitHub page for APEX plugins. Note that the new plugin has been exported from APEX 18.1 and therefore requires at least that version to import and use.

Enjoy! :-)


Thursday, August 9, 2018

Quick PL/SQL, a code generator for PL/SQL based on simple markup

Maybe you've heard about "Quick SQL", a utility (previously a separate application, now part of APEX 18.1 itself) that generates SQL scripts based on a simple markup language. Quick SQL is a real time-saver and allows you to go from idea to prototype to working application in an instant.

Inspired by Quick SQL, I've created a similar utility, called "Quick PL/SQL", that does the same thing, except it generates PL/SQL code (packages with functions and procedures, with standard comment blocks, formatting, etc.) based on a simple markup.

I've recorded a couple of videos to show the tool in action.

Here is an introduction which explains the basic input syntax and the output options:



And here is another video which explains how to create standard CRUD-style (Create, Read, Update, Delete) APIs for your tables:



Try it out for yourself here: https://apex.oracle.com/pls/apex/f?p=QUICKPLSQL:HOME&c=MULEDEV or via this shortcut: https://tinyurl.com/quickplsql2

Of course, I wouldn't mind if this functionality becomes available as part of the QuickSQL utility that is built into APEX! :-)