DataFlex, starting with v3.1c allows external database drivers to be loaded as dlls and to work as a part of the runtime. This enables a driver to work with existing DataFlex programs without changing a single line of code. Flex2SQL takes advantage of this runtime environment, and provides database drivers for Oracle, MS SQL Server, MySQL, MariaDB and PostgreSQL.
The Flex2SQL product bundle is comprised of a migration utility and database driver dll. The Migration utility takes existing DataFlex tables and indexes and migrates them to a target backend, creating the table structures, index structures, and recnum (or rowid) values for all the files in the filelist. The database driver DLL works with the DataFlex runtime and handles all client/server connection and database operations.
After completing the installation and setup of Flex2SQL, you’re ready for data migration. Data migration is performed using the GUI component. The procedure consists of logging into the target database, choosing the filelist or workspace to be converted, and then running the Convert Database command.
Flex2SQL migrates the selected files to the target database and creates an intermediate file for each data file. Intermediate files are stored in the workspace working directory, or if files where opened with the filelist option, where the .DAT file resides.
Running your Program¶
After all the files are converted to the target database, the next step is to add the appropriate login command to your program. This is the only change that is required. Mertech provides an automatic login dialog box that pops up if you’re not logged onto the server and are trying to open files that use Mertech drivers. This option is useful for testing purposes or running reports.
Integration with DataFlex¶
To give you an idea on how these pieces work together, let us look at a simple DataFlex program that opens a file.
The runtime engine calls the DataFlex API function call,
dfFileOpen(), which searches the filelist entries for a file named
MYFILE entry could point to an INT file or contains a driver prefix (such as
f2s_ms:\\servername\schema*tableName). The INT extension means that there is an intermediate file. The DataFlex API sees the .INT extension and opens the .INT file. From this .INT file, the API looks for the driver name entry. If the driver was previously loaded, it searches for the driver in the driver table. If the driver was not previously loaded, it loads the driver and adds it to the driver table. Once the driver has been loaded, the API calls the driver FileOpen code and passes control to the driver. The driver performs the operations that are necessary to open the file. Once the driver is finished it passes control back to the runtime engine.
In a similar fashion, the API passes control to the driver to handle all major functions like find, save, edit, delete, transactions, locking, etc.