Enhanced Support for Magic Enterprises uniPaaS Applications with BTR2SQLv5.0

February 27th, 2013

The new BTR2SQL v5.0 beta version enables uniPaaS users to migrate and convert their existing data from Btrieve data files to an SQL backend by offering direct export from the application source.

Converting your Btrieve data to SQL requires access to Data Definitions, usually through DDF files, which Magic applications do not normally use.  In the past, this required extra steps to export the information from the Magic (uniPaaS) application each time before migrating to the SQL database.  This is further complicated during a new release of the product when table definitions have been modified.

With BTR2SQL’s new feature, Magic uniPaaS developers will now be able to easily move their applications to SQL.  Later, as developers need to make changes to the application and its schema and deploy them to customers, they can do so in one step and avoid having to reexport data and repeat the process.  The user simply points the tool at the application’s source file and provides the server and database information.  In one step, all information is converted.  

 See the version 5 release notes for more details or download the product here.

Troubleshooting Btrieve Driver Deployment

February 12th, 2013

A Windows application accessing Btrieve data uses either wbtrv32.dll or w3btrv7.dll. When you deploy your migrated application you must provide the Mertech drivers as a replacement for these two DLLs.  If your application cannot locate the Mertech version of the driver or one of its dependencies, the application will not load or execute properly.

Locating the Mertech drivers

There are several locations where you can put the Mertech drivers, but the application must be able to find the Mertech version of the DLL using the standard Windows DLL Search Order. Typically the Mertech version of wbtrv32.dll or w3btrv7.dll is placed in the directory with the application executable. Windows searches here for dependencies first, so this guarantees that the correct version is located. If the driver DLL is not placed in the directory with the application, it must be found by Windows DLL search. This is slightly different on each version of Windows, but in general, this is the order of search:

  • The application’s executable directory
  • The system directory (%windir%\system32, or %windir%\SysWOW64)
  • The 16-bit system directory (%windir%\system)
  • The Windows directory (%windir%)
  • The current directory
  • The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.

Other dependencies

The Mertech driver DLLs depend on other DLLs such as oci.dll from the Oracle client. Some of the server-specific dependencies are listed below.

  • Oracle
    The Mertech driver links to oci.dll. oci.dll and all its dependencies must be found on the search path. Note: The 32-bit Oracle client must be installed and functioning, 64-bit will not work. 
  • MSSQL
    You must have SQL Native Client 2005, 2008 or 2012 installed. Note: only Version 5 (and above) of the Mertech driver supports the 2012 client. 
  • MySQL
    The 32-bit version of libmysql.dll and its dependencies must be found on the search path.
  • PgSQL
    libpq.dll and its dependencies must be found on the search path.

Read the rest of this entry »

INT File Template for B_CREATE

December 20th, 2012

The B_CREATE syntax was expanded so your application can provide the name of a pre-existing INT file to use as a pattern when creating a new table on the SQL server.

Background

The original B_CREATE syntax is:
B_CREATE KeyBuffer
Where KeyBuffer is <filename>

The only information available to the driver for creating a new file was the filename and indexes. The driver had to examine the indexes to determine there was a field of a particular data type and size at some specific offset in the record. However, the driver could not determine the names of all of the fields, so you might end up with a table such as:

CREATE TABLE cust1_dat (mds_field1 int, mds_filler1 binary(10), mds_field2 varchar(50), mds_filler2 binary(500))

Auto Template Option

B_CREATE was later expanded to make use of an existing int file (filename.int). When an application issues a B_CREATE, if an INT file already exists for the file, the driver compares its contents with the index definitions in the new create structure. If they match, the driver uses the definition in the INT file to create the table on the server. If the INT file does not look compatible, it is ignored and you are stuck with the MDS_FIELDx and MDS_FILLERx field names.

Several flags control the way the auto template option works. The ‘flag’ becomes the Key Number for the operation.

A flag telling the driver to ignore the existing INT file:
B_CM_OVERWRITE_IGNORE_INT_FILE= -6

Two flags telling the driver to always use the definition in the INT.
B_CM_OVERWRITE_FORCE_INT_FILE =-99
B_CM_NOOVERWRITE_FORCE_INT_FILE=-100

INT File Template Option

The latest enhancement to B_CREATE expands the contents of KeyBuffer to include the new filename (as before), the template filename, and the table name to be created on the server. Now you can specify an INT file for an existing file that has a pattern you want to use to create the new file. For example you can create bar.btr with the same structure (but different table name) as foo.btr.

The new B_CREATE syntax is:
B_CREATE KeyBuffer
Where KeyBuffer is:
<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 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 causes an invalid filename error.

All forms of filenames are supported for both the filename 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).

Notes

  • An INI file in the folder where the template filename is specified is read. So it is possible for the template INT file to be in a different folder than what is directly specified for the template file.
  • If the template filename does not exist, a status 12 is returned.
  • A new INT file is created for the new filename with contents that match the template INT but using the new table name.
  • If the new filename INT exists when the create call is made, it is ignored/erased and the template INT is used just as if the new file INT had not been there.
  • If the new filename INT exists and is marked as Permanent, a FileAlreadyExists error is returned.
  • The template INT should be marked as Permanent.

Example 1

Your Magic (or non-Magic) application has a DB table “custmain.mcf” with table name “Customers Main”. Custmain.mcf exists in C:\MyApp\Data and C:\MyApp\Data\mds.ini has an entry: INT-Folder=..\intfiles

During migration to SQL, table “Customers Main” and C:\MyApp\IntFiles\custmain_mcf.int are created.

The application later wants to access a new customer table with the same definition as “Customers Main”. C:\MyApp\Data is the current folder at runtime.

  1. The application opens ‘cust1.dat | custmain.mcf | Cust – John Smith’.
  2. C:\MyApp\IntFiles\cust1_dat.int does not exist so the driver returns status 12.
  3. Magic then issues a B_CREATE passing the same path string as before.
  4. The driver reads C:\MyApp\IntFiles\custmain_mcf.int into the usual internal file classes and updates the table name to “Cust – John Smith” and the physical name to “cust1.dat”.
  5. The driver then issues a call to Create Table to on SQL backend, creates C:\MyApp\IntFiles\cust1_dat.int, and returns success.
  6. Magic reissues the open and continues successfully.

Example 2

You can also use this new B_CREATE option in a multi-xxx (company, customer, site, etc.) environment where you utilize the same schema in multiple folders (one for each customer for instance). Scenario

c:\
    myapp
          data
               intfiles_mssql (all files marked internally as Permanent and OS Read/Only attribute set)
                      people_btr.int
                      jobs_btr.int
                      salaries_btr.int
               intfiles_ora (all files marked internally as Permanent and OS Read/Only attribute set)
                      people_btr.int
                      jobs_btr.int
                      salaries_btr.int
               cust1
                      mds.ini (says intfiles=..\intfiles_mssql and ..\intfiles_ora,  prefix=cust1_)
               cust2
                      mds.ini (says intfiles=..\intfiles_mssql and ..\intfiles_ora,  prefix=cust2_)
               cust3
                      mds.ini (says intfiles=..\intfiles_mssql and ..\intfiles_ora,  prefix=cust3_)

When either B_OPEN or B_CREATE references one of the customer files (for example, “c:\myapp\data\cust1\people.btr”), the driver looks at the INI file to determine where the INT files are located and then opens the INT file for the required server type (for example, “c:\myapp\data\intfiles_mssql\people_btr.int”).

So, rather than having thousands of INT files in each of the customer folders  (all having the same contents), the INI file directs the driver to a common location for the INTs.

Update MDS_RECNUM Automatically

August 28th, 2012

The BTR2SQL Data Migration Utility adds the auto-increment field MDS_RECNUM as the first column of each migrated table. An extract of a migration trace is shown below:

21:51:31.078> btr2SQL.exe: Converting Billing
21:51:31.218> PrimaryKey set to recnum
21:51:32.406> SQL_FOR_SET Defined for: DemoData.dbo.BILLING
21:51:32.406> Creating new table (BILLING) at ‘c:\pvsw\demodata\billing.mkd’
21:51:32.406> RecSize=139; 7 fields, 1 indexes.
21:51:32.406> BeginTransaction [Exclusive]: sqlsrv
21:51:32.421> CREATE TABLE “DemoData”.”dbo”.”BILLING” (MDS_RECNUM DECIMAL(28,0) NOT NULL IDENTITY(1,1), “STUDENT_ID” BIGINT DEFAULT 0 NOT NULL, “TRANSACTION_NUMBER” INT DEFAULT 0 NOT NULL, “LOG” VARCHAR(20) NOT NULL, “AMOUNT_OWED” DECIMAL(13,2) NULL, “AMOUNT_PAID” DECIMAL(13,2) NULL, “REGISTRAR_ID” BIGINT DEFAULT 0 NOT NULL, “COMMENTS” VARCHAR(100) NULL)

If you are using Mertech’s drivers with your Btrieve program, Mertech’s drivers automatically handle the auto increment values.  However, if you access and change the same table by a non-Btrieve program, then the auto-increment sequence is disturbed.  To avoid this, enable a trigger that automatically fires when a record is added, deleted, or updated and perform the necessary operations for auto-increment handling.

To enable the trigger:

  1. Select the required file.
  2. <Right-click> and select Oracle Specific Options | Enable Trigger to Handle Auto-Increment and Inverse Key.

How to run a DOS Btrieve application with a SQL server

January 19th, 2011

There are still plenty of DOS-based Btrieve applications in use today. Is it possible to move these applications to a current SQL server to take advantage of integration with other applications and powerful data management tools?

The Mertech BTR2SQL driver is a replacement for the Btrieve interface. As noted in the white papers and documentation, the driver is a Windows 32-bit dll (and now supported on Windows 64-bit as well). It would be logical to think that a DOS application could not access this interface; however, many years ago, Pervasive Software (makers of Btrieve) introduced the “DOS Box” support which allows an application written for the DOS interface to enjoy the benefits of the Windows client or workgroup engines.

Read the rest of this entry »