Product Documentation

FairCom DB V12 Updates

Previous Topic

Next Topic

Auto Import Callback

FairCom has implemented the ability to "auto import" a table into SQL at the time it is accessed. This feature requires the user to provide a SQL callback library (ctsqlcbk) implementing the following:

  1. The ctsqlCallbackLoaded function handling a call with type == 2 setting *ptr to point to the function in 2. below.
  2. A thread-safe function in ctsqlcbk that, given the database name, the table owner, and the table name, provides the necessary CTSQLIMPOPTS setting to be used to import the table, in particular the filename on disk.

    The function prototype is:

CTDBRET ctsqlImpSetOptsCallbackFunc (pCTDBSESSION pSession, pTEXT dbname, pTEXT tblowner, pTEXT tblname, CTSQLIMPOPTS **opts);

where:

  • pSession [IN] - the session handle
  • dbname [IN] - the name of the database in use
  • tblowner [IN] - the table owner of the table
  • tblname [IN] - the name in SQL of the table
  • opts [OUT] - pointer to a CTSQLIMPOPTS structure holding the information to internally call ctSQLImport function. The CTSQLIMPOPTS dbsnam, srvnam, usrnam, usrpwd, nonint members settings are ignored.

The SQL server engine at startup loads the ctsqlcbk and makes a call to ctsqlCallbackLoaded passing type == 2 and registering the function returned in ptr.

At runtime, when the SQL parser encounters an object not present as a table in the system tables, if the registered function is not NULL and the user has resource permission or DBA permission when the table owner is someone else, the code calls the registered function and if the function returns CTDBRET_OK and sets the *opts != NULL attempts an automatic sqlimport using the opts returned overwriting the ignored members listed above as necessary for an internal server automatic sqlimport.

The "import" occurs in its own independent transaction (it cannot be reverted by rolling back the transaction). If the import fails for any reason, SQL statement execution continues as if the table simply does not exist.

After running the SQL callback function, a function is called to signal the memory allocated for opts should be released as follows:

ctsqlImpSetOptsCallbackFunc (pSession, NULL, NULL, NULL, opts).

See also Auto Import: Tables that are missing on disk will now be Auto Purged.

Previous Topic

Next Topic

Auto Import: Tables that are missing on disk will now be Auto Purged

The FairCom DB SQL Auto Import now supports an "Auto Import" callback. When this new callback has been registered, the server should adjust the dictionary in the system tables to remove info for tables that are no longer on disk. The idea being we will constantly update our dictionary to match the files present on disk that have been opened. This means c-tree will automatically purge the information out of the system tables for tables that were previously auto imported but are now missing on disk, and add information for tables (Auto Import) that are opened but were not in the dictionary.

When a table is not found on disk where it was when added to the system table, it is purged and the error -20005 is sent back to the application. No attempt is made to try to see if the table can be imported again.

TOCIndex