Legacy Application Modernization: Key Steps, Benefits & Best Practices
This blog post was co-authored with Riaz Merchant, President and CEO at Mertech. In the fast-paced software world, 'legacy' often signals a warning.
BLOBs (binary large object) are very large, variable length, binary or character data objects. BLOBS are typically documents (such as .pdf, .doc) or pictures (such as .jpeg, .gif, .bmp).
NOTE: Related terms, LOB (large object) and CLOB (character large object in Oracle), are used to refer to large objects consisting entirely of text data.
BLOBs can either be stored inside the database or in the file system. Storing BLOB data in the database offers a number of advantages:
The file system may be a better storage choice for BLOBs when:
For all databases, there is a slight performance penalty fetching BLOB data, because BLOB data is not stored in the same internal page as the rest of the record.
Additionally, there are special considerations when using MS SQL Server. If you use embedded SQL and access LOB columns, you have to specify a server side cursor in your call to SQL_PREPARE_STMT. MS SQL Server enforces cursor limitations on LOB columns and transactions.
When a VDF text field is too large for the native type, the Mertech drivers automatically use the BLOB data type during the migration. For example in MS SQL Server the driver automatically switches from varchar (<string length>) to varchar (max) when database limitations are hit.
As long as the size of the object fits in a regular DataFlex string, the object is bound as any regular TEXT column. The Mertech drivers transparently handle this, defaulting to non-BLOB data types if possible.
Mertech suggests using non-BLOB data types, whenever possible, if designing database tables outside of Mertech’s tools. For example, when using available SQL modeling tools to manage your database structure.
Mertech added new commands to allow you to take advantage of reading and writing BLOB types either to the database or to the file system.
Append the existing field buffer value into the assigned LOB column, preserving the existing LOB column data.
Retrieve the total length from a given LOB column
Write the existing field buffer value into the assigned LOB column, overwriting the existing LOB column data.
Read a chunk of data from a LOB column moving the read value into the assigned file field buffer. Since the chunk data is going to be moved into a file field buffer, the actual read value length cannot exceed the field buffer length.
Load an external file into a LOB column. When using LOB_LOADFROMFILE with the Oracle driver, the input file must be available from the Oracle database, because the load task will be done by the database. To use this command you must supply the alias for the created directory object.
Erase a portion of data from a LOB column. A DF_TEXT field is erased by filling it with blanks. A DF_BINARY field is erased by filling it with 0x0.
Truncate data from a LOB column to a given length.
Send the data that was loaded into an LOB column to the database. This is necessary due to MySQL’s architecture.
// Assumes the 13th field of customel is type TEXT or BINARY and named comments
Local Integer iLength
open "customel.int" as customer
clear customer
find gt customer by index.1
// Delete any lob data in the field, and fill it up with the contents of a file
Lock
LOB_TRUNCATE of customer 13 to 0
LOB_LOADFROMFILE of customer 13 FROM "." "document.pdf"
Unlock
Find Eq customer by Recnum
Direct_Output 'Binary: document-copy.pdf'
// Retrieve the chunk length and the first chunk of data into the field buffer
LOB_LENGTH of customer 13 to iLength
LOB_READ OF customer 13 First iLength
Write customel.comments
// Loop through and retrieve the following chunks and write them to a file
While (iLength > 0)
LOB_READ of customer 13 Next iLength
Write customer.comments
Loop
For more details on LOB handling and the commands, please consult Flex2SQL v11 Programmers Guide.
This blog post was co-authored with Riaz Merchant, President and CEO at Mertech. In the fast-paced software world, 'legacy' often signals a warning.
This post was co-authored with Riaz Merchant, President/CEO at Mertech Data Systems, Inc.
Shifting from your traditional legacy systems to the Cloud can be a game changer, as the benefits of cloud migration are numerous. Cloud computing...