Anda di halaman 1dari 4

MC Press Online

Partner TechTip: Embedded SQL Is Just Plain Messy. Is There a Better Way?
Contributed by Scott Salisbury Friday, 02 May 2008 Last Updated Thursday, 05 June 2008

Coding SQL within RPG can be tedious, but what if you could automatically generate SQL for RPG, SQL for Java, and SQL for PHP in a just few clicks?

by Scott Salisbury

Have you ever avoided using SQL in your RPG programs because embedded SQL is a hassle and it's just easier to do it the old-fashioned way? Have you ever wished your RPG programs could access data from Microsoft SQL Server or Oracle? Do you work with multiple databases and multiple SQL client tools? What about Java and PHP? Both use embedded SQL. Are you using them yet?

SQL(snap) simplifies SQL tasks and turns hours into a few clicks.

Coding SQL within RPG can be tedious, but what if you could automatically generate SQL for RPG, SQL for Java, and SQL for PHP in a just few clicks?

Have you ever avoided using SQL in your RPG programs because embedded SQL is a hassle and it's just easier to do it the old-fashioned way? Have you ever wished your RPG programs could access data from Microsoft SQL Server or Oracle? Do you work with multiple databases and multiple SQL client tools? What about Java and PHP? Both use embedded SQL. Are you using them yet?

SQL(snap) simplifies SQL tasks and turns hours into a few clicks.

http://www.mcpressonline.com

Powered by Joomla!

Generated: 7 September, 2008, 23:59

MC Press Online

SQL(snap) lets you surf every database in your enterprise: DB2/400, DB2, Oracle, Microsoft SQL Server, MySQL, Postgre, and others. Then, with a few mouse clicks you can build intricate SQL queries. With a few more clicks, you can generate reliable, reusable SQL code to be used in your own RPG, Java, and PHP programs. And then you can access all of your databases with RPG, Java, or PHP.

Figure 1: Build intricate SQL queries and generate code with just a few mouse clicks! (Click images to enlarge.)

Question: What do RPG, Java, and PHP have in common?

Answer: The database and SQL.

SQL is the undisputed standard for database access across every modern technology. Knowledge of SQL is vital, even for us RPG types, because in an age of application modernization and Web technologies like Java, PHP, .NET, etc., the one common thread among them all is, of course, SQL. Once you truly understand SQL, you are one large step closer to mastering another technology.

With SQL, it's usually not the complexity that keeps RPG programmers away; it's the tediousness. It is one thing to understand SQL and know how to use SELECT, INSERT, UPDATE, and DELETE from a command line or GUI interface; it's quite another to deal with cursors, prepared statements, and scrollable or updatable result sets. Not to mention host variables, error and status codes, and other insidious details within your programs. And never mind how ugly the IBM
http://www.mcpressonline.com Powered by Joomla! Generated: 7 September, 2008, 23:59

MC Press Online

precompiler makes embedded code look in debug view. Sheesh!

With Java and PHP, there is no choice: Thou shalt use SQL or surrender thy IDE. Period.

With RPG, however, it can be daunting, especially when compared to the relative simplicity of CHAIN or SETLL and READE. Consider the following snippet that finds all rows for a given customer within a specified state (see Figure 2).

Figure 2: A simple RPG SETLL, READE example.

Seen that once or twice, right? OK, now take a look at the snippet below. This is the equivalent code done with SQLRPGLE (see Figure 3).

Figure 3: A SQLRPGLE prepared statement and cursor example.

http://www.mcpressonline.com

Powered by Joomla!

Generated: 7 September, 2008, 23:59

MC Press Online

It's not rocket science, but it is more complicated, and as they say, the devil's in the details. With Java and PHP, there is an additional step not generally needed in RPG programs. In RPG, if you are connecting to the local database, there is no need to obtain a connection. With Java and PHP, you must obtain and manage a connection throughout the life cycle of the process.

SQL(snap) builds code to manage SELECT, INSERT, UPDATE, and DELETE as well as cursors, prepared statements, host variables, and connection objects where appropriate. SQL(snap) also builds data structures and helps to manage the movement of variables for your SQLRPGLE, Java, and PHP code. All of the generated code is based on the queries you build using SQL(snap). The resulting code will drop into your programs with ease, leaving the tedious aspects of database I/O to the tool and leaving you with a lot more time for other things, like business logic or learning Java or PHP...or lunch.

SQL(snap) will go a long way toward helping you learn Java and PHP as well as the internals of SQLRPGLE and accessing local or remote databases from all three languages.

Over on our Web site, there are several more code comparisons like the one above. There you will find similar snippets comparing CHAIN, READ, READP, READPE, and so forth with their SQL equivalents.

To see SQL(snap) in action and to see the code that gets generated for RPG, Java, and PHP, click over to http://www.sqlsnap.com/. Don't miss the video, the white paper, and your free trial download. You'll be up and running in 10 minutes!

http://www.mcpressonline.com

Powered by Joomla!

Generated: 7 September, 2008, 23:59

Anda mungkin juga menyukai