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.
Perhaps your application needs to create temporary data files at runtime. The Mertech drivers support creation of temporary files on the fly using the standard B_CREATE API. The table remains on the server until you call the B_DROP_TABLE API.
You call the B_CREATE API and provide the indexes and pathname for the file. The driver creates the requested table on the SQL backend. You can also provide a template (INT file) for the file and the table will be fully defined with field names and data types.
The Migration Utility obtains the proper definition of the file from the DDF file. Field names and data types are translated directly into the SQL schema and also saved in an INT file. The INT file is stored in the same directory as the data file. The INT file contains all of the information necessary to allow the driver to connect to, open, or recreate the converted SQL table.
To prevent the INT file from being deleted when the table is dropped, edit the INT file and change the PERMANENT_INT token to YES (the default setting is NO).
PERMANENT_INT YES
When an application issues a B_CREATE to create for example MyTempFile.mkd, the driver looks to see if a matching INT file (MyTempFile_mkd.INT) already exists. If it does, the driver compares its contents with the index definitions provided in the new create structure. If they look like a match, the driver uses the definitions in the INT file to create the table on the server. This allows you to have pre-existing INT files (with full field definitions) for temporary tables.
There may be times when you do not want an existing INT file to be used, in that case you can set the B_CREATE Keynum value:
B_CM_OVERWRITE_IGNORE_INT_FILE= -6
Opposite this, perhaps you want the driver to always use the definition in the INT. Two more flags force this behavior and the FILESPEC in the databuffer is completely ignored:
B_CM_OVERWRITE_FORCE_INT_FILE =-99
B_CM_NOOVERWRITE_FORCE_INT_FILE=-100
The Mertech drivers recognize an extended B_CREATE syntax that allows the application to specify the new filename (as normal), the name of the INT file to be used as a template for the new file, and the name of table to be created on the server. This extended syntax is formatted in the KeyBuffer as:
<new filename> | <template filename> | <table name>
If a pipe character ( ‘|’ ) appears in the KeyBuffer, <template filename> is assumed to be the next (required) string. The second pipe and <table name> are optional. If not included, the driver defaults to new filename_ext for the table name.
A space on either side of the pipe is ignored.
Quotes around any sub-string are removed. Quotes around the entire string are not supported. Quotes on the interior of any sub-string returns an invalid filename error.
All forms of filenames are supported for both the new and template parts of the string. This includes just a filename (relative to the “current directory”), current directory relative paths ( .\path\filename or ..\path\filename ), root relative paths ( \path\filename ), full paths ( c:\data\filename ) and UNC paths ( \\server\share\path\filename ).
When the EOY Report is generated, various data is collected into a temporary file. The definition for this table, ReportTemplate.mkd, is in the DDFs. Use the Migration Utility to generate the corresponding INT file, ReportTemplate_mkd.int.
When the application executes a B_CREATE("eoyreport_2014090901011545.mkd | ReportTemplate.mkd | EOYReportData_2014090901011545"), the Mertech driver reads ReportTemplate_mkd.int, creates a new table EOYReportData_2014090901011545 and generates a new INT file, eoyreport_2014090901011545_mkd.int.
Later, when B_DROP_TABLE is called, the INT file and the table on the SQL backend are removed.
Some applications manipulate the data files directly with OS calls by copying an existing data file and deleting the file when done. These direct operations are not supported by the drivers. Instead, you must fully rely on the B_CREATE API to create the temporary table and B_DROP_TABLE to remove the table when it is no longer needed.
Extra precaution must be taken to avoid multiple processes from using the same temporary file simultaneously. With Btrieve, the temp file could be created locally and thus each client could have a dedicated file. Now that the table is created in a shared SQL resource, multiple clients have access to the same table.
Several options are available to avoid this problem.
Note: In all cases, make sure to use the B_DROP_TABLE API to delete stale temp tables.
SQL administrators can be very strict when assigning access rights to users. For example, they may insist that users do not have Create Table permission. Without Create Table permission, users cannot create temporary files on the server.
One solution to this problem is to assign a different login for temporary tables. The main application data can be accessed under a login that has Read/Write access. The temporary data can be accessed under a login that does not have access to the main data but does have Create Table permission.
The easiest way to assign a different login for temporary tables is to place the temporary files in a separate directory and setup the mds.ini file in that folder to use the assigned login.
Main Data Files Directory: C:\MyApp\DATA
mds.ini (UseTrustedConnection=no, User=mydomain\me, Password=b7fba9c0e1b0f217)
MARKETING.MKD
MARKETING_MKD.INT
PURCHASING.MKD
PURCHASING_MKD.INT
Temporary Files Directory: C:\MyApp\TEMP
mds.ini (UseTrustedConnection=no, User=mydomain\temp, Password=9dc42401d47a3fd0)
TEMP1.INT
TEMP2.INT
TEMP3.INT
Note: A user name and password stored in an INT file override settings in the mds.ini file.
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...