Product Documentation

Installing FairCom Products

Previous Topic

Next Topic

Let Existing ISAM Applications Co-Exist with SQL

FairCom SQL has been designed from its core to provide as much access as possible to all existing FairCom data. For most applications, it is as simple as linking the data to the FairCom Server system tables using the Table Import Utility, ctsqlimp. Not only does this give you the ability to view and modify your tables with SQL, you also retain the ability to continue using your existing application!

  • Advantages: No changes are made to the data and index file definitions, so the existing c-tree application can access the data without changes to the application.
  • Considerations: Some higher-level SQL capabilities that require special internal fields, indexes, and file modes will not be supported unless the files and applications are adjusted to provide these requirements.

Example ISAM Application with Proper SQL Constructs

Table Definition Requirements

To take advantage of the ability to co-exist with SQL, certain requirements must be met to ensure compatibility.

  • Tables must contain IFIL and DODA structures. These can be added after the fact for existing files and are inserted automatically for files created by c-treeDB and FairCom SQL.
  • An ISAM application must use corresponding c-tree Plus data types (as defined in the DODA) as in the c-tree Plus - SQL data type mapping. For example a CT_CHAR field type is used in FairCom SQL to store a 1-byte integer.

    Note: There is an incompatibility between the use of CT_ARRAY in the c-tree Plus ODBC Driver and the use of CT_ARRAY in c-treeDB and FairCom SQL, including the c-treeSQL ODBC Driver.

    CT_ARRAY fields are imported by default as a FairCom SQL Binary field. FairCom SQL expects the first four bytes of a binary field to specify the length of the field. When you create a table with FairCom SQL these four bytes are automatically created and maintained for you. When considering a CT_ARRAY field from c- tree Plus, you must explicitly include these four prefix bytes and assign the appropriate value. An example of how to properly handle this field is demonstrated in the example code at the end of this article. Should you have existing incompatible c-tree Plus CT_ARRAY fields to import into FairCom SQL, please contact your nearest FairCom office for suggestions and advice. We're here to help you.
  • The table must have either TRNLOG or PREIMG in its file mode to use the ROLLBACK WORK and integrity constraint capabilities.
  • Superfiles are supported by FairCom SQL; however, it's not possible to create a superfile using SQL. Please create using another API like the C Database API.
  • In order to properly handle NULL, the table must contain the $NULFLD$ field, a hidden field generated by c-treeDB at creation time. Tables created with the c-treeDB interface (used with c-treeSQL) have a hidden field, $NULFLD$, which is used to determine if each user-created field in the record buffer has a NULL value. c-treeSQL requires this capability to implement constraints. c-treeDB and FairCom SQL will access tables without the $NULFLD$ field, but the table's fields will always return a non-NULL status.
  • In order to properly handle JOINS referencing ROWID, the table should contain the $ROWID$ field (a hidden field generated by the c-treeDB at creation time). c- treeDB and FairCom SQL should work with tables without the $ROWID$ field, and will use the record offset as the ROWID tuple identifier. SQL statements like select * from table where rowid > '4' will fail because using record offset as ROWID will give us record offsets instead of sequential numbers.

Note: When FairCom updates a variable-length record, the record offset for the record may change if the updated record size is larger than the original record. In this particular case, the ROWID for this ROW will not be unique, as required by the SQL standard.

Adding a DODA to an Existing Data File

To use the FairCom SQL Server with existing ISAM files that do not already have a DODA resource, add a DODA to each file. This is done most easily with a developer-created utility that opens each file and calls PutDODA to insert the required resource into that file. The utility should accomplish the following tasks:

  • Include a data object definition array (DODA) which is simply an array of DATOBJ structures, as defined below.
  • Open each data file in ctEXCLUSIVE mode.
  • Call PutDODA() for each file to insert the corresponding DODA resource.
  • Close the files.

A DODA is a data object definition array. Each element of the array is comprised of a structure of type DATOBJ. Only three of the first four fields of the DATOBJ are required for standard c-tree Plus data files. DATOBJ is defined as follows:

typedef struct {

pTEXT fsymb; /* ptr to symbol name */

pTEXT fadr; /* adr of field in record buffer */

UCOUNT ftype; /* type indicator */

UCOUNT flen; /* field length */

...

} DATOBJ;

  • fsymb points to a unique symbolic name for the field and should not be NULL.
  • fadr is not used by c-tree Plus (its value is ignored).
  • ftype is one of the field types specified in the "Field Types" table.
  • flen is set to the field's length for fixed length fields, or the known maximum for varying length fields with a known maximum length, or zero for varying length fields without a known maximum length. If the field type has an intrinsic length, which is true for types CT_CHAR through CT_DFLOAT, a zero length is automatically replaced by the intrinsic length.

Given a data record with the structure:

struct {

TEXT zipcode[10]; /* Zip code */

LONG ssn; /* social security # */

TEXT name[50]; /* name */

} DATA_FORMAT;

The corresponding DODA would be defined as:

DATOBJ doda[] = {

{"ZipCode",NULL,CT_FSTRING,10},

{"SocialSecurity",NULL,CT_INT4},

{"Name",NULL,CT_STRING,50}

};

Note: The two string fields show the difference between fixed-length and variable-length strings. zipcode , CT_FSTRING, takes up a fixed space in the record (10 bytes) and does not require a NULL to terminate the string. name , CT_STRING, takes up a variable amount of space up to a maximum of 50 bytes and is NULL terminated. The field types are described in "Field Types" in the FairCom DB Programmer’s Reference Guide.

The PutDODA() call inserts the DODA object as a resource into the data file. The function is declared as follows:

PutDODA (COUNT PUTDODA(COUNT datno,pDATOBJ doda,UCOUNT numfld))

PutDODA() assigns the contents of a data object definition array (DODA) to data file datno , which must be opened in ctEXCLUSIVE mode. doda points to the beginning of the DODA as described above. The numfld parameter indicates how many data fields are in the DODA, three in the example above. See review the PutDODA() function description and "Record Schemes" in the FairCom Programmer’s Reference Guide for additional details. Call FairCom for assistance if needed.

Index Definition Requirements

  • If an index contains a segment consisting of a "partial field" (i.e., does not use the c-tree Plus Schema segment modes or the segment starting offset and the segment length are different from the field starting offset and the field length) c-treeSQL cannot access this index, even though the index is still properly updated by c-tree. You will need to create a new index in c-treeSQL composed of the corresponding columns.
  • If there is more than one logical index in one physical index file, the DROP INDEX and the DROP TABLE commands will not work properly.

ALTER TABLE may not work correctly if tables contain index segments that do not start at field boundaries and/or span over several fields.

For example, if a field is deleted from the table, and this field is part of an index segment that spans over several fields, c- treeSQL may not know how to adjust the index segment length after the field is deleted from the table. The resulting index definition may not be correct. Tables with unusual characteristics may also not work correctly and the altered table may inherit characteristics preventing them from working in the original application.

Example

The following application defines a typical c-tree Plus ISAM data file and index with the proper IFIL and DODA resources necessary for use with c-treeSQL. In addition, it demonstrates the proper construction of a CT_ARRAY field to be imported into a c-treeSQL database table as a BINARY field.

See Example ISAM Application with Proper c-treeSQL Constructs.

After executing this application, run the utility to link the table to c-treeSQL:

#ctsqlimp isam_table.dat -u ADMIN -a ADMIN

Finally, run the utility to issue c- treeSQL statements against the table:

#ISQL -u ADMIN -a ADMIN ctreeSQL

ISQ>SELECT * FROM isam_table;

Troubleshooting ISAM to c-treeSQL Problems

The easiest way to avoid common problems when importing c-tree Plus data files into c-treeSQL is to copy these files into the c-treeSQL database directory, typically located in the c-treeSQL Server directory. This gives the server direct access to the files. However, it is possible to link any c-tree Plus data file from any location. c-treeSQL Server access to the file is completely relative. The most common problem encountered is an FOPN_ERR error (12) from ctsqlimp when importing the table. In most cases, this is simply the c- treeSQL Server's inability to resolve the file's relative location from the c-treeSQL dictionary files. The most straightforward way to address this issue is to specify the full pathname when specifying the data file to import.

For example, to import a c-tree Plus data file existing in another directory different from the c-treeSQL Server, execute the ctsqlimp command as follows:

#ctsqlimp c:\old_data\datafile.dat -d c-treeSQL -s FAIRCOMS -u ADMIN -a ADMIN

This will link the existing data file in place to the c-treeSQL Server. You can now query, add, and update the data with standard c-treeSQL statements.

Important!

While you can import data from another c-tree Server location into the c-treeSQL Server, keep in mind you can only use ONE of the servers to access the data. It is not possible to access a c-tree data file from multiple c-tree Servers simultaneously. With the c-treeSQL Server this is not a problem; you can continue to use your existing ISAM application with the new c-treeSQL Server!

TOCIndex