• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Naming Idiosyncrasies with the DB2 Storage Engine for MySQL

    February 24, 2010 Susan Gantner

    In a recent tip, I wrote about why I think MySQL is a great benefit to our platform. With its DB2 for i storage engine, MySQL allows yet one more way to access DB2 data. In this article, I’ll go into a few naming gotchas that can arise when using MySQL. But first I’ll describe some scenarios in which developers in today’s RPG shops may find themselves taking advantage of MySQL.

    The first scenario is one I touched on in my last tip: the availability of a huge array of open source (i.e., free or nearly free) applications written in PHP, Java, or C++, to use MySQL. Whatever your new application requirement may be, a quick Google search will often reveal some open source applications that may come close to meeting those needs. Since the data from those applications can now be stored in DB2 for i, then you can use RPG to fill in any gaps in application requirements.

    The second scenario is that you may decide to develop your own applications with at least the browser interface portion of the application written in PHP, perhaps utilizing calls to RPG code in the background. You may handcraft the PHP code yourself or you may decide to utilize a framework or a tool to generate PHP logic for you. In any case, there are several options for accessing DB2 data from the PHP code. But you may prefer to use MySQL due to the number of books and Internet articles that contain examples of using MySQL with PHP. Thanks to the DB2 storage engine, that data can also be stored in DB2, making it equally accessible to your RPG programs and/or query tools.

    The third scenario is similar to the second one. You could use one of the readily available open source frameworks out there to quickly build prototypes of applications or even completely build browser-based CRUD (Create, Read, Update, and Delete) applications using MySQL. Imagine having a user ask you for an application and going back to that person later the same day with a full-function data entry application from which you can begin working on a prototype of the application together. The data from the prototypes can be stored in DB2, freeing you to complete or enhance the application further using any combination of languages.

    One such framework that I’ve seen used in this fashion is called Xataface. Using Xataface, incredibly full-function CRUD applications can be created in minutes with as little as 10 to 20 lines of configuration code. Even the simplest Xataface applications have some really nice features, such as sorting or searching on any column, producing CSV or XML output, and drop-down lists for fields with specific values lists. Xataface is just one example. Many tools like this that are written to access MySQL databases are readily available.

    Assuming one of these scenarios sounds interesting to you, the common element in all of them is the ability to have the MySQL data stored in DB2 for i so that it’s easily accessible to RPG or other familiar languages and tools. How difficult is that to do?

    It’s very simple. When a table (a.k.a., a file) is created using MySQL, simply specify the storage engine name using “Engine=IBMDB2I” in your Create Table statement. You can also configure MySQL to default to the DB2 storage engine if you prefer.

    For those of you who have created tables in DB2 using SQL, most of the syntax in the following example will look familiar:

    Create Table SUSAN.MYTABLE 
       (COMPANY Char(15), FIRSTNAME Char(10),
        LASTNAME Char(10), CREDITLMT Dec(7,2))
     Engine=IBMDB2i;
    

    The statement above, when entered via MySQL, created a MySQL table called MYTABLE in a database called SUSAN. At the same time, it also created an SQL table (a.k.a., physical file) called MYTABLE in a library named SUSAN.

    The data for MYTABLE is not duplicated; it is stored in DB2 for i because of the IBMDB2I storage engine. Therefore, the same data is equally accessible from both MySQL and either SQL in DB2 or any native database interface, such as an RPG READ. Of course, in order to use CHAIN or SETLL, I would first need to issue a Create Index statement or add a primary key to MYTABLE.

    You may have noticed that the names of the database (library), table and columns (fields) in the Create Table statement above are in uppercase. That’s significant because unlike DB2 for i, MySQL is case sensitive. So a table named MYTABLE is a different table from one named MyTable. The reason I used all uppercase names in my example is that it makes it makes life a bit easier to use from RPG, as we’ll see in moment.

    This begs the question: how does DB2 handle the case sensitivity of MySQL? The answer is that DB2 places names that are not all uppercase in double quotes. So the following example creates something very different from the earlier one:

    Create Table Susan.MyTable
      (Company Char(15), FirstName Char(10),
       LastName Char(10), CreditLmt Dec(7,2))
     Engine=IBMDB2i;   
    

    This time, a table (physical file) named “MyTable” (complete with quotes) was created in a library named “Susan”. If you’re like me, you may find that a little hard to believe, so take a look at the PDM screen below:

    As you can imagine, names like these cause problems in many native interfaces, such as in RPG F specs, so you may want to create an SQL view of the table with a more traditional uppercase name or use a file override at compile time to the mixed case name. Perhaps the best solution for situations with mixed case names is to use embedded SQL, which does support the double-quoted names, even in RPG.

    The column/field names in the “MyTable” example are also case sensitive and therefore double quoted as well when accessed via SQL. But an uppercase “system name” was generated for these fields, much like the shorter system name that is created by DB2 when a column name longer than 10 characters is used in Create Table. So a Display File Field Description (DSPFFD) command for “Susan”/”MyTable” shows the first field name to be COMPA0001 (no quotes) with an alternate SQL name of “Company”.

    As you can see from these simple examples, using embedded SQL in your RPG is often better choice for accessing your tables created from MySQL, particularly if you are not able to control the names used, such as in the first scenario above–when utilizing software packages.

    Susan Gantner is one of the most respected System i gurus in the world and is one of the co-founders of System i Developer, an organization dedicated to RPG, DB2, and other relevant software technologies for the System i platform that hosts the new RPG & DB2 Summit conference. Gantner, who has worked in IBM’s Rochester and Toronto labs, left IBM to focus on training OS/400 and i5/OS shops on the latest programming technologies. She is also a regular speaker at COMMON and other user groups. Send your questions or comments for Susan to Ted Holt via the IT Jungle Contact page.

    RELATED STORY

    What a Lifelong DB2 Fanatic Sees in MySQL



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    PowerTech:  Strengthen your security. Get a FREE Compliance Assessment today
    looksoftware:  Learn more and get your complementary ilook licences
    COMMON:  Join us at the annual 2010 conference, May 3 - 6, in Orlando, Florida

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    eCMS Gets an Interface to Vehicle Scales X64 and Blade Servers Lead the Server Recovery

    Leave a Reply Cancel reply

Volume 10, Number 7 -- February 24, 2010
THIS ISSUE SPONSORED BY:

WorksRight Software
Profound Logic Software
Northeast User Groups Conference

Table of Contents

  • Naming Idiosyncrasies with the DB2 Storage Engine for MySQL
  • How To Use the Inhibit Write Keyword?
  • Hunting Down Storage Hogs

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle