YOUR FEEDBACK
AJAX: XMLHttpRequest Vs. iFrames
Kenneth wrote: You forgot to mention a disadvantage of xmlHttpRequest that i...
AJAXWorld RIA Conference
$300 Savings Expire July 25
Register Today and SAVE!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
POWERBUILDER LINKS YOU MUST CLICK ON


SQL or Stored Procedures

Digg This!

Page 2 of 2   « previous page

The code for our stored procedures can be found in Listing 1. Please note that I've purposely excluded all error checking. We can revisit this when we talk about transactions and error handling.

There are two differences related to the Users table that we need to account for. First, we won't display the password values from the User table. We'll come up with a different mechanism to let the user or administrator change passwords. Second, we have to allow the key value, userid, to change. This will be reflected in the update stored procedure we'll write - please take note.

Regarding the naming convention to be used for our stored procedures, we'll use the following forms for the following functions:

  • get_<table>_list will select all column values for all rows with no arguments.
  • get_<table> will select all column values for a key-value argument.
  • insert_<table> will insert a new row into the database table with all values provided, including key values.
  • update_<table> will update a row in the table with all values provided including key values which will be used to find the row to update. This assumes the key values will provide a unique key that is something every table should have.
It's very common to see insert and update logic combined in a single stored procedure. This is implemented by including an "if exists()" check to see if the row already exists in the table. If it does, an update statement is executed; if not, then an insert statement is executed instead. Typically, there's very little benefit in doing this and I would discourage it strongly unless there's a strong case for doing so. One such case might be a feed processor that requires the "if exists()" check for every record fed. In this situation, it may be cleaner to have the processor call the insert/update procedure with all the arguments and let the procedure check for the existence rather than forcing that check into the processor's codeline.

In the same way, the get_<table>_list and the get_<table> procedures could have been replace with a single procedure to which either a valid key value or null would be passed. If your database supports the function isnull() or something similar, then the where clause would include the phrase:

<column> = isnull(argument, <column>)

If the argument isn't null, the argument value is used as is and compared to the column value. If the argument is null, the value is replaced with the column value itself. This means the where clause would include the phrase

<column> = <column>

which always evaluates to true. Hence, if a null argument was passed, all rows would be returned; otherwise the row that matches the argument value would be returned.

In more complex applications, there may be any number of variations of stored procedures for selecting, inserting, updating, and deleting just as there may be any number of variations for presenting the user with ways of searching, viewing, and editing. Since our application is fairly simple, we can afford to, and should, take the simplest approach to meet our specifications and objectives. As we progress to more complex applications, we will, by necessity, be presented with additional challenges that we'll face and overcome with more complex solutions. However, we must always endeavor to create the "simplest" complex solutions and not get carried away or lose sight of the goal of creating a fully functional, robust, understandable, and maintainable applications.


Page 2 of 2   « previous page

About Steve Katz
Steve Katz is a senior developer at HSBC Bank USA and has extensive experience developing applications utilizing PowerBuilder, Java, and other technologies. He has used PowerBuilder since v2.0a, taught at Techwave, and even wrote some articles about PowerBuilder a very long time ago.

Sandy Turner wrote: This article states the following: "Depending on the nature of your data, however, it's very important to have the stored procedure recompiled periodically to ensure that the saved query plan is optimal for the data in the table. You can usually have the DBA group recompile your procedures weekly or at whatever interval is required." Based on the DBMS, the recompilation of your stored procedures periodically is not necessary. ORACLE, for instance, determines the execution plan each and every time the procedure is executed. SQL*Server, on the other hand, does not.
read & respond »
SYS-CON India News Desk wrote: When we last left off, we had a functional shell of an application. We had a menu that would open our five different sheets (Controls, Users, Messages, Menus, and Contacts); we had the shell of those five sheets themselves; we had some basic shared functionality with regards to managing sheets (arranging sheets, closing all open sheets); we had some basic shared DataWindow/DataStore error handling in the DBError event of our base-class u_dw and n_ds objects; we had some basic transaction management hooks in place in our base-class n_tr transaction object.
read & respond »
PBDJ LATEST STORIES . . .
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be
PowerBuilder and EAServer: Uniting the .NET and J2EE Communities
In PowerBuilder 11.2, .NET meets J2EE head-on with the capability to deploy .NET Windows Forms and Web Forms applications (as well as assemblies and Web Services) that access Enterprise JavaBeans (EJBs) in Sybase's own EAServer. As you'll see over the course of this article, integratin
HarPB Tool Review
HarPB is a specialized utility for checking PowerBuilder source objects in and out of AllFusion Harvest. It handles the special requirements of checking objects out to PowerBuilder Libraries (PBLs) and checking objects in from PBLs. These operations are non-standard to most source cont
PowerBuilder Editorial: The State of the State
Back in 2002, Sybase announced their four-phase approach toward adding .NET support to PowerBuilder. Phase 1 was the implementation of web services in PB9 and Phase 2 was the release of DataWindow.NET, which was packaged with PB 10. Phases 3 and 4 were the more significant phases. In P
PowerBuilder History - When Did Sybase Develop PB and How Did It Evolve?
I have been asked many times by various clients, students, and the IT curious about PowerBuilder: When did Sybase develop the product and how did it evolve? I keep telling this story and answering e-mails on the subject. I am now to the point where I have decided that I should have PBD
PowerBuilder 11's .NET Interoperability
PowerBuilder 11 deploys entire applications as .NET Windows Form or Web Form applications and deploys individual components as .NET Assemblies and as .NET Web Services. Version 11 consumes resources of the default .NET framework as well as resources of custom developer-defined .NET res
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING POWERBUILDER / SYBASE NEWS
Sybase Reports Record Second Quarter Results, Driven by 15% Revenue Growth
Sybase, Inc. (NYSE:SY), the largest enterprise software and services company exclusively