Data conversion considerations
When data, especially binary data, is exchanged between server and client, there are several data conversion issues to consider.
For example, when data is transferred between operating systems with different byte-ordering schemes, numeric data must undergo a byte-reversal process to restore its correct numeric value. Different operating systems also have certain alignment requirements for referencing numeric data in memory; some operating systems cause program exceptions if these requirements are not observed. Character data types are automatically converted by the database, except when character data is embedded in a binary data type such as BLOB or a VARCHAR FOR BIT DATA.
There are two ways to avoid data conversion problems:
- Always transform objects into printable character data types,
including numeric data.
This approach has the disadvantages of slowing performance, due to the many potential conversions required, and increasing the complexity of code accessing these objects, such as on the client or in the transform function itself.
- Devise an operating system-neutral format for an object transformed
into a binary data type, similar to the approach that is taken by Java™ implementations. Be sure to:
- Take care when packing or unpacking these compacted objects to properly encode or decode the individual data types and to avoid data corruption or program faults.
- Include sufficient header information in the transformed type so that the remainder of the encoded object can be correctly interpreted independent of the client or server operating system.
- Use the DBINFO option of CREATE FUNCTION to pass to the transform function various characteristics related to the database server environment. These characteristics can be included in the header in an operating system-neutral format.
As much as possible, write transform functions so that they correctly handle all of the complexities associated with the transfer of data between server and client. When you design your application, consider the specific requirements of your environment and evaluate the tradeoffs between complete generality and simplicity. For example, if you know that both the database server and all of its clients run in an AIX® environment and use the same code page, you could decide to ignore the previously discussed considerations, because no conversions are currently required. However, if your environment changes in the future, you might have to exert considerable effort to revise your original design to correctly handle data conversion.