Using DB2 Universal Database on 64-bit Platforms

Chapter 4. Application Development Considerations

A number of API functions that previously used the long data type now specify sqlint32. Additionally, instead of pointers to long or unsigned long variables, some of these functions now take pointers to sqlint32 or sqluint32 variables. The application code for these API functions must be changed, because an sqlint32 pointer and a long pointer are not compatible on 64-bit UNIX based platforms.

For more information about these host variables, see the Application Development Guide.

Use the LONGERROR precompile option to prepare your application for migration to a 64-bit operating environment, while still running on a 32-bit machine. Set LONGERROR to YES on a 32-bit machine so that the precompiler returns an error whenever it encounters a host variable of the long type.

In order to migrate a 32-bit application to the 64-bit operating environment follow these steps:

  1. Prune the use of long types for host variables, unless long types are necessary. Instead, use the new portable host variables, sqlint32 or sqluint32 . For example:
       EXEC SQL BEGIN DECLARE SECTION;
          long y;         /* this declaration generates an error on 64 bit */
          sqlint32 x;     /* this declaration is acceptable for 64 bit */
       EXEC SQL END DECLARE SECTION;
    
  2. Precompile the application against a database on a 64-bit server. This creates a new package for the application that is being ported. Applications generated by compiling the output of a 32-bit precompiler are not supported on 64-bit installations. Similarly, applications generated by compiling the output of a 64-bit precompiler are not supported on 32-bit installations.
  3. Compile the application in 64-bit mode.
  4. Link the application against the new 64-bit DB2 libraries.
  5. Bind the application against a database on a 64-bit server.

Restrictions and Additional Notes on Application Development

The following restrictions and notes must be considered when developing 64-bit applications:


Writing Scratchpads on 32-bit and 64-bit Platforms

To make your UDF code portable between 32-bit and 64-bit platforms, you must change the way in which you create and use scratchpads that contain 64-bit values. Do not declare an explicit length variable for a scratchpad structure that contains one or more 64-bit values, such as pointers, long variables, or sqlint64 variables. For example, the following code sample might result in a data alignment exception on a 64-bit platform, because the structure declaration includes an explicit length variable:

  struct scratchpad_data
  {
    sqlint32 length;
    char chars[4];
    sqlint64 bigint_var;
  };

To obtain a consistent definition for scratchpad structure across all platforms in the DB2 family, it was determined that the UDF's sqludf_scratchpad::data is aligned to platform-specific alignment criteria. If alignment is an issue for that scratchpad data structure, the scratchpad declaration with no explicit length member can be used. This change was made to ensure consistency with some mainframe versions of DB2, where pointers are 16-byte aligned instead of 4- or 8-byte aligned for 32-bit and 64-bit installations, respectively.

To declare the scratchpad structure from the previous example so that it is portable between 32-bit and 64-bit platforms, remove the declaration of the explicit length variable for the structure. The following code example declares the scratchpad structure without declaring an explicit length variable:

  struct scratchpad_data
  {
    sqlint64 bigint_var;
    char chars[4];
  };

To access a scratchpad structure that does not declare an explicit length variable in your UDF, you can refer to the scratchpad using the following format:

  struct scratchpad_data * data = 
    (struct scratchpad_data*)scratch_pointer->data;

where scratch_pointer represents the sqludf_scratchpad pointer of the UDF and data represents the contents of the scratchpad.


External References

Additional information on platform specific 64-bit application considerations can be found on the following Web sites. These Web sites include tips and recommendations that can be specific to hardware and operating systems and are therefore not necessarily suitable for all 32-bit and 64-bit platforms currently supported by DB2 or in future releases of DB2. Note that IBM cannot be held responsible for information resources at non-IBM Web sites.


[ Top of Page | Previous Page | Next Page ]