Skip to the main content.
Downloads Try Thriftly
Downloads Try Thriftly
Group 762

Migrate and run DataFlex applications with Oracle, MS SQL Server, PostgreSQL, MySQL &  MariaDB.

flex2Crystal

Stuck in Crystal XI?  Upgrade and use the latest versions of Crystal Reports with DataFlex applications. 

BTR2SQL

Convert from Btrieve / P.SQL / Actian transactional engines to Oracle, MS SQL Server, and PostgreSQL

thriftly-1

Quickly build multi-protocol web services with the same API. Supports JSON-RPC, REST, SOAP,  Thrift, and gRPC.

 Group 671-1

 

Why Mertech?

3 min read

The BTR2SQL SDK

Mertech BTR2SQL comes with a software development kit (SDK) that gives you access to extended Btrieve functionality. The SDK contains a runtime dll and migration dll for each backend (MS SQL, MySQL, Oracle or PostgreSQL). The SDK also contains header files to define the constants and structures required for advanced programming and it contains detailed documentation and examples.


The BTR2SQL SDK is installed in the <Program Files>\Mertech Data Systems\DB Drivers\Btrieve\sdk directory.


Runtime dll with extended APIs

As one of the last steps in the migration process, you replace the Btrieve runtime dll (wbtrv32.dll or later version called w3btrv7.dll) with the Mertech runtime dll of the same name. The Mertech runtime dll codes the standard Btrieve operations (for example, B_OPEN) so that they will work with the selected SQL backend. This means your application can access the SQL backend without any changes to your existing code or BTRCALLs.


In addition to the standard Btrieve operations, the Mertech runtime dll includes extended APIs to:

    • Create temporary files or files based on existing templates
    • Determine whether the Btrieve or SQL backend is in use, determine the version of the Mertech driver that is installed, get and set runtime settings, encrypt passwords
    • Add, delete, rename, or modify existing tables using APIs similar to those provided in the Pervasive.SQL Distributed Tuning Interface (DTI)
    • Use the Embedded SQL APIs to run SQL queries directly to the SQL backend
    • Call the Fast Insert APIs, that use native SQL backend functionality to get data into a table as fast as possible
    • Start, stop and control trace output

 BeforeandAfter


How do I use the extended APIs?

The runtime dll is dynamically linked to your application when the application is loaded, so the extended APIs are automatically available and accessible just like the standard Btrieve operations through the BTRV/BTRCALL function interface. Simply use the provided constants (or the operation code) and structures defined in the mds_btrieve header. For example:

#include <mds_btrieve.h>

 
MDS_SQL_LOGIN loginInfo = {"WIN-MM75CP6C\\SQLEXPRESS", "btrtest", "mertech", "btrtest", ""};

status = BTRCALL(B_SQL_LOGIN, NULL, &loginInfo, &(dataLen=sizeof(loginInfo)), NULL, 0, 0);
Direct call interfaces are also available for some of the extended APIs. For example you can encrypt a password by calling:

#include <mds_btrieve.h>

 
status = BTRCALL(B_ENCRYPT_PASSWORD, NULL databuf, &datalen, keybuf, 0, 0);

Or, you can call MdsEncryptPassword directly:

#include <mds_btrieve.h>

 
status = MdsEncryptPassword(password, encpw, encpwlen);

 

Migration dll

The migration dll (sql_btr.dll, mys_btr.dll, ora_btr.dll, or pgs_btr.dll) includes all the standard and extended Btrieve functions plus functions to write your own migration interface:

    • MdsMigrateOneTable
    • MdsMigrateAllTablesInDdfs
    • MdsMigrateAllTablesInConfig
    • MdsPrepareDB


How do I use the migration APIs?

In order to use the migration APIs, the migration dll must be dynamically linked at runtime using LoadLibrary and the function addresses must be obtained using GetProcAddress. This is done for you in the BtrieveFile class, which is a simple wrapper class capable of loading any dll. The BtrieveFile class is defined in BtrieveFile.h. An MS SQL code extract is shown below. For additional examples, see the samples\migration subdirectory.

#include <BtrieveFile.h>
void useMdsMigrateOneTable()
{
BtrieveFile* pBF = new BtrieveFile("sql_btr.dll");

 

MDSRESULT status;

static const char ddfLocation[] = "c:\pvsw\demodata\";
static const char tableName[] = "billing";

status = pBF->MdsMigrateOneTable(ddfLocation, tableName, MDS_MIG_FULL, NULL);
}  //useMigrateOneTable()


Can I access Btrieve and an SQL backend simultaneously?

Consider the following scenario. During the migration process, some files are left in Btrieve, while others are migrated to an SQL backend. This could be an interim step during the migration process to test the migration. Or, a decision may have been made to leave private tables in Btrieve on the local machine, while common tables are stored on a central SQL Server. The Mertech drivers support this scenario.


Rather than replacing the Pervasive dll with the Mertech dll of the same name, an application needs to load Pervasive’s wbtrv32.dll and one of the Mertech migration dlls (sql_btr.dll, mys_btr.dll, ora_btr.dll, or pgs_btr.dll ) to simultaneously access the Btrieve and SQL backend.

Below is an example accessing both Btrieve and MS SQL:

#include <BtrieveFile.h>

 

// Load Pervasive's Btrieve access dll
BtrieveFile* btrieve = new BtrieveFile("w3btrv7.dll");

// Load Mertech's Microsoft SQL library
BtrieveFile* mssql = new BtrieveFile("sql_btr.dll");

// Open an old Btrieve file
bStat = btrieve->BTRCALL(B_OPEN, NULL, &(datalen=0), FILE_NAME, MAX_KEY_BUF_SIZE, 0);

// Open a Btrieve file migrated to MS SQL
bStat = mssql->BTRCALL(B_OPEN, NULL, &(datalen=0), FILE_NAME2, MAX_KEY_BUF_SIZE, 0);
By loading the different dlls explicitly, the application is able to access the BTRCALL function from each; providing access to both Pervasive Btrieve files and SQL-migrated files.

simultaneous

You can also use this same method to access multiple SQL backends. For example, load the sql_btr.dll and the ora_btr.dll to simultaneously access MS SQL and Oracle backends.


Note
: The INT files that are produced during migration are specific to each SQL backend so you will need to create a folder for each backend and provide an MDS.INI (sample in the SDK) that specifies the INT-Folder location and login information for each server.


Where can I get additional information?

This SDK directory <Program Files>\Mertech Data Systems\DB Drivers\Btrieve\sdk contains:

• The required header files in the include subdirectory. Header files have detailed comments that describe new operation codes and structures.
• Extensive documentation in the docs subdirectory. Select Windows Start menu | Mertech’s ISDBC Drivers for Btrieve | SDK.

A description of the SDK can also be found in the BTR2SQL User Guide.


Are there any programming examples available?

Programming examples can be found in the sdk\samples subdirectory. Select Windows Start menu | Mertech’s ISDBC Drivers for Btrieve | SDK Samples.

• See sdk\samples\migration for how write your own migration interface

• See sdk\ samples\fastinsert for how to use the Fast Insert APIs to get data into a table as fast as possible

See sdk\samples\MdsApis\C for how to:

• Use B_SET_FIELD_FETCH to add performance benefits to an application that reads large records but only requires a few of the fields

• Use B_EXTENDED_VERSION to find out whether the Pervasive or Mertech version of the dll was loaded, or which version of the Mertech driver was loaded, or what version of the SQL server is currently connected

• Use embedded SQL to create databases and users and to add and drop tables

 

 

Hybrid Cloud Migration: Plan, Process and Advantages

Hybrid Cloud Migration: Plan, Process and Advantages

This post was co-authored with Riaz Merchant, President/CEO at Mertech Data Systems, Inc.

Read More
Financial Benefits of Cloud Migration & Hybrid Cloud Applications

Financial Benefits of Cloud Migration & Hybrid Cloud Applications

Shifting from your traditional legacy systems to the Cloud can be a game changer, as the benefits of cloud migration are numerous. Cloud computing...

Read More

AWS Application Modernization: Best Practices & Tools

In the age of digital transformation, businesses are increasingly moving away from traditional on-premises systems, steering towards more dynamic,...

Read More