(*****************************************************************************)
(* MODULE: BTRBDE                                                            *)
(* AUTHOR: Peter Blair                                                       *)
(* RIGHTS: Reggatta Systems - COPYRIGHT 1995 - 2000                          *)
(* DESCR.: This module contains the Engine Interface                         *)
(*****************************************************************************)
Unit BtrBde;
{...$DEFINE TITAN_AS_DLL}

{$Z+}

interface
uses
  BDE,
  Windows;

{============================================================================}
{                          DBI prototypes                                    }
{============================================================================}
{                          Environmental                                     }
{----------------------------------------------------------------------------}

Function BtrInitFn (                    { Initialize the Engine }
      iVer          : Word;             { Interface Version }
      pEnv          : pDBIEnv           { Environment Structure/NULL }
   ): DBIResult;

 { DO NOT CALL THIS DIRECTLY. Use the 'DbiInit' define below. }

 { Initializes the engine environment. Default settings can be overwritten  }
 { by supplying the appropriate settings. Defaults are read from the system }
 { configuration file. pEnv can be NULLP to get the system defautls.        }

Function BtrInit (pEnv: PDbiEnv): DBIResult;

Function BtrExit: DBIResult;            { Exit engine }

Function BtrDLLExit: DBIResult;         { Exit DLL }

{============================================================================}
{                         System Level Info                                  }
{============================================================================}

Function BtrGetSysVersion (             { Get system version info }
var   sysVersion    : SYSVersion
   ): DBIResult;

Function BtrGetSysConfig (              { System configuration }
var   sysConfig     : SYSConfig
   ): DBIResult;


Function BtrGetClientInfo (             { Get Client info }
var   clientInfo    : CLIENTInfo
   ): DBIResult;


Function BtrGetSysInfo (                { Get system status/info }
var   sysInfo       : SYSInfo
   ): DBIResult;


Function BtrLoadDriver (                { Load a given driver }
      pszDriverType : PChar             { Driver name }
   ): DBIResult;


{============================================================================}
{                            Sessions                                        }
{============================================================================}

Function BtrStartSession (              { Start a new session }
      pszName       : PChar;            { Name (Optional) }
var   hSes          : hDBISes;          { Session }
      pNetDir       : PChar             { Netfile directory for session (opt) }
   ): DBIResult;


Function BtrGetCurrSession (            { Get the current session }
var   hSes          : hDBISes           { Session }
   ): DBIResult;


Function BtrSetCurrSession (            { Set the current session }
      hSes          : hDBISes           { Session/NULL }
   ): DBIResult;


Function BtrCloseSession (              { Close the current session }
      hSes          : hDBISes           { Session }
   ): DBIResult;


Function BtrGetSesInfo (                { Get current session info }
var   sesInfo       : SESInfo
   ): DBIResult;


Function BtrSetPrivateDir (             { Set Private Directory for session }
      pszDir        : PChar             { Directory name/NULL }
   ): DBIResult;



{============================================================================}
{                     Datababase, Schema and File inquiry                    }
{============================================================================}

Function BtrOpenDatabase (              { Open a database }
      pszDbName     : PChar;            { Database name }
      pszDbType     : PChar;            { Database type (NULL: Universal) }
      eOpenMode     : DBIOpenMode;      { Open type }
      eShareMode    : DBIShareMode;     { Share type }
      pszPassword   : PChar;            { Password }
      iOptFlds      : Word;             { Number of optional Params }
      pOptFldDesc   : pFLDDesc;         { Optional Field Descriptors }
      pOptParams    : Pointer;          { Optional Params }
var   hDb           : hDBIDb            { Returnd database handle }
   ): DBIResult;


Function BtrSetDirectory (              { Set the current directory }
      hDb           : hDBIDb;           { Universal database handle }
      pszDir        : PChar             { Directory/NULL }
   ): DBIResult;


Function BtrGetDirectory (              { Get the current/default directory }
      hDb           : hDBIDb;           { Universal database handle }
      bDefault      : Bool;             { True for default }
      pszDir        : PChar             { Returned directory }
   ): DBIResult;


Function BtrOpenTableList (             { Open a cursor on "Tables" }
      hDb           : hDBIDb;           { Database handle }
      bExtended     : Bool;             { True for extended info }
      bSystem       : Bool;             { True to include system tables }
      pszWild       : PChar;            { Wild card name }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;

Function BtrOpenFileList (              { Open a cursor on "Files" }
      hDb           : hDBIDb;           { Universal database handle }
      pszWild       : PChar;            { Wild card name }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrOpenIndexList (             { Return "Indexes" for a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hCur          : hDBICur           { Returned cursor on "Indexes" }
   ): DBIResult;


Function BtrOpenFieldList (             { Return "Fields" for a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
      bPhyTypes     : Bool;             { True, for physical types }
var   hCur          : hDBICur           { Returned cursor on "Fields" }
   ): DBIResult;


Function BtrOpenVchkList (              { Return "Checks" for a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver Type }
var   hChkCur       : hDBICur           { Returned cursor on "Checks" }
   ): DBIResult;


Function BtrOpenRintList (              { Return Integrity checks }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hChkCur       : hDBICur           { Returned cursor on "Ref Int". }
   ): DBIResult;


Function BtrOpenSecurityList (          { Return security descriptions }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hSecCur       : hDBICur           { Returned cursor on sec list }
   ): DBIResult;


Function BtrOpenFamilyList (            { Return family members }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hFmlCur       : hDBICur           { Returned cursor on "Family" }
   ): DBIResult;


Function BtrOpenSPList (                { Open a cursor on "Stored Procedures" }
      hDb           : hDBIDb;           { Universal database handle }
      bExtended     : Bool;             { True for extended info (N/A) }
      bSystem       : Bool;             { True to include system procedures }
      pszQual       : PChar;            { Qualifier (N/A) }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrOpenSPParamList (           { Return "Parameters" for a stored procedure }
      hDb           : hDBIDb;           { Database handle }
      pszSPName     : PChar;            { Stored procedure name }
      bPhyTypes     : Bool;             { True, for physical types }
      uOverload     : Word;             { Overload number }
var   hCur          : hDBICur           { Returned cursor on "Parameters" }
   ): DBIResult;


Function BtrOpenFunctionList (          { Open a cursor on "Functions" }
      hDb           : hDBIDb;           { Universal database handle }
      eoptBits      : DBIFUNCOpts;      { Options for function list }
      phCur         : phDBICur          { Returned cursor on "Functions" }
                                        { Record desc is of type DBIFUNCDesc }
   ): DBIResult;


Function BtrOpenFunctionArgList (       { Return "Arguments" for a function }
      hDb           : hDBIDb;           { Database handle }
      pszFuncName   : PChar;            { Function name }
      uOverload     : Word;             { Overload number }
      phCur         : phDBICur          { Returned cursor on "Arguments" }
   ): DBIResult;


Function BtrCloseDatabase (             { Close a database }
var   hDb           : hDBIDb            { Pointer to database handle }
   ): DBIResult;


{============================================================================}
{                                  Capabilities                              }
{============================================================================}

Function BtrOpenDriverList (            { Get a list of driver names }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrGetDriverDesc (             { Get description for a given type }
      pszDriverType : PChar;            { Symbolic name for driver type }
var   drvType       : DRVType           { Driver type description }
   ): DBIResult;


Function BtrOpenDatabaseList (          { Get a list of registered databases }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrGetDatabaseDesc (           { Get a description of a logical db }
      pszName       : PChar;            { Name of logical database }
      pdbDesc       : pDBDesc           { Database description }
   ): DBIResult;


Function BtrOpenTableTypesList (        { Get a list of table types }
      pszDriverType : PChar;            { Driver type }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrGetTableTypeDesc (          { Get Table capabilities }
      pszDriverType : PChar;            { Driver type }
      pszTableType  : PChar;            { Table type }
var   tblType       : TBLType           { Table Capabilities }
   ): DBIResult;



Function BtrOpenFieldTypesList (        { Get a list of field types }
      pszDriverType : PChar;            { Driver type }
      pszTblType    : PChar;            { Table type (Optional) }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrGetFieldTypeDesc (          { Get list of field types }
      pszDriverType : PChar;            { Driver type }
      pszTableType  : PChar;            { Table type }
      pszFieldType  : PChar;            { Field type  (Physical only) }
var   fldType       : FLDType           { Field type description }
   ): DBIResult;


Function BtrOpenIndexTypesList (        { Get list of index types }
      pszDriverType : PChar;            { Driver type }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrGetIndexTypeDesc (          { Get description of given idx type }
      pszDriverType : PChar;            { Driver type }
      pszIndexType  : PChar;            { Index type }
var   idxType       : IDXType           { Index description }
   ): DBIResult;


Function BtrOpenLdList (                { Get a list of Lang Drivers }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;


{===========================================================================}
{                      Table Open, Properties & Structure                   }
{===========================================================================}

Function BtrOpenTable (                 { Open a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name or file name }
      pszDriverType : PChar;            { Driver type                 /NULL }
      pszIndexName  : PChar;            { Index to be used for access /NULL }
      pszIndexTagName : PChar;          { Index tag name              /NULL }
      iIndexId      : Word;             { Index number                /0 }
      eOpenMode     : DBIOpenMode;      { Read or RW }
      eShareMode    : DBIShareMode;     { Excl or Share }
      exltMode      : XLTMode;          { Xlate mode }
      bUniDirectional : Bool;           { Uni or Bi directional }
      pOptParams    : Pointer;          { Optional params /NULL }
var   hCursor       : hDBICur           { Returns Cursor handle }
   ): DBIResult;

Function BtrOpenNestedTable(            { Get nested table }
           hCursor       : hDBICur;     { Master cursor }
           iFieldNo      : Word;        { FieldID of nested table field }
           bReadOnly     : Bool;        { if TRUE, read only mode }
           bUniDirectional: Bool;       { if TRUE, unidirectional }
           var hCursorNested : hDBICur  { Returns Cursor handle for nested table }
     ): DBIResult;

Function BtrOpenRef(
           hCursor       : hDBICur;     { Master cursor }
           iFieldNo      : Word;        { FieldID }
           bReadOnly     : Bool;        { if TRUE, read only mode }
           bUniDirectional: Bool;       { If TRUE, Uni directional }
           var hRefCursor : hDBICur     { Returns Cursor handle for REF }
   ): DBIResult;

Function BtrDatabaseFlush( hDb : hDBIDb ) : DBIResult;

Function BtrGetCursorProps (            { Get Cursor properties }
      hCursor       : hDBICur;          { Cursor handle }
var   curProps      : CURProps          { Cursor properties }
   ): DBIResult;


Function BtrGetObjFromName (            { Get object from name }
      eObjType      : DBIOBJType;       { Object handle }
      pszObjName    : PChar;            { Name of object /NULL }
var   hObj          : hDBIObj           { Returned object handle }
   ): DBIResult;


Function BtrGetObjFromObj (             { Get associated object }
      hObj          : hDBIObj;          { Object handle }
      eObjType      : DBIOBJType;       { Type of associated object }
var   hObjOut       : hDBIObj           { Returns object of eObjType }
   ): DBIResult;


Function BtrGetProp (                   { Get property }
      hObj          : hDBIObj;          { Object handle }
      iProp         : Longint;          { Property to retrieve }
      PropValue     : Pointer;          { == NULL, validate iProp for getting }
      iMaxLen       : Word;             { Length of buffer pPropValue }
var   iLen          : Word              { Returns required length }
   ): DBIResult;


Function BtrSetProp (                   { Set property }
      hObj          : hDBIObj;          { Object handle }
      iProp         : Longint;          { Property to set }
      iPropValue    : Longint           { Property value }
   ): DBIResult;


Function BtrValidateProp (              { Validate a property }
      hObj          : hDBIObj;          { Object handle }
      iProp         : Longint;          { property to validate }
      bSetting      : Bool              { TRUE:setting, FALSE:getting }
   ): DBIResult;


Function BtrGetFieldDescs (             { Get field descriptions }
      hCursor       : hDBICur;          { Cursor handle }
      pfldDesc      : pFLDDesc          { Array of field descriptors }
   ): DBIResult;


Function BtrGetCursorForTable (         { Find cursor for a given table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type / NULL }
var   hCursor       : hDBICur           { Returned cursor }
   ): DBIResult;


Function BtrCloneCursor (               { Return a duplicate cursor }
      hCurSrc       : hDBICur;          { Source cursor }
      bReadOnly     : Bool;             { If TRUE, read only mode }
      bUniDirectional : Bool;           { If TRUE, Uni directional }
var   hCurNew       : hDBICur           { Destination cursor address }
   ): DBIResult;


Function BtrCloseCursor (               { Closes cursor }
var   hCursor       : hDBICur           { Pntr to Cursor handle }
   ): DBIResult;



{============================================================================}
{                      Index Manipulation & Usage                            }
{============================================================================}

Function BtrOpenIndex (                 { Open an index }
      hCursor       : hDBICur;          { Cursor handle }
      pszIndexName  : PChar;            { Index Name }
      iIndexId      : Word              { Index number (if applicable) }
   ): DBIResult;


Function BtrCloseIndex (                { Close an index }
      hCursor       : hDBICur;          { Cursor handle }
      pszIndexName  : PChar;            { Index Name }
      iIndexId      : Word              { Index number }
   ): DBIResult;


Function BtrSwitchToIndex (             { Change index order of access }
var   hCursor       : hDBICur;          { Cursor handle (In/Out) }
      pszIndexName  : PChar;            { Index name }
      pszTagName    : PChar;            { Tag name (if applicable) }
      iIndexId      : Word;             { Index number }
      bCurrRec      : Bool              { Position at current rec }
   ): DBIResult;


Function BtrGetIndexDesc (              { Get index properties }
      hCursor       : hDBICur;          { Cursor handle }
      iIndexSeqNo   : Word;             { Index number }
var   idxDesc       : IDXDesc           { Returned index description }
   ): DBIResult;


Function BtrGetIndexDescs (             { Get index properties }
      hCursor       : hDBICur;          { Cursor handle }
      idxDesc       : PIDXDesc          { Returned index descriptors }
   ): DBIResult;


Function BtrGetIndexForField (          { Get index desc for given field }
      hCursor       : hDBICur;          { Cursor handle }
      iFld          : Word;             { Field Number (1..N) }
      bProdTagOnly  : Bool;             { If TRUE, only xBASE prod tags will be returned }
var   idxDesc       : IDXDesc           { (Optional) }
   ): DBIResult;


Function BtrGetIndexSeqNo (             { Get index sequence number }
      hCursor       : hDBICur;          { Cursor handle }
      pszIndexName  : PChar;            { Index name }
      pszTagName    : PChar;            { Tag name (if applicable) }
      iIndexId      : Word;             { Index number }
var   iIndexSeqNo   : Word              { Index number }
   ): DBIResult;


Function BtrSetToKey (                  { Set key condition }
      hCursor       : hDBICur;          { Cursor handle }
      eSearchCond   : DBISearchCond;    { Search condition (default is =) }
      bDirectKey    : Bool;             { Key is supplied directly }
      iFields       : Word;             { No of full fields to match }
      iLen          : Word;             { Partial key len of last field }
      pBuff         : Pointer           { Either Record buffer or Key itself }
   ): DBIResult;


Function BtrExtractKey (                { Get the key value of current record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record buffer (optional) }
      pKeyBuf       : Pointer           { Returned. Key bytes. }
   ): DBIResult;


Function BtrSetRange (                  { Set cursor to a range }
      hCursor       : hDBICur;          { Cursor }
      bKeyItself    : Bool;             { Whether Key or Record buffer }
      iFields1      : Word;             { Key fields to be mathced in full }
      iLen1         : Word;             { Key length to compare }
      pKey1         : Pointer;          { Top/Left key in Range }
      bKey1Incl     : Bool;             { If Inclusive of Key1 }
      iFields2      : Word;             { Key fields to be mathced in full }
      iLen2         : Word;             { Key length to compare }
      pKey2         : Pointer;          { Bottom/Right key in Range }
      bKey2Incl     : Bool              { If Inclusive of Key2 }
   ): DBIResult;


Function BtrResetRange (                { Reset range }
      hCursor       : hDBICur           { cursor handle }
   ): DBIResult;


Function BtrCompareKeys (               { Compare two keys }
      hCursor       : hDBICur;          { Cursor handle }
      pKey1         : Pointer;          { Key buffer 1 to compare }
      pKey2         : Pointer;          { Key buffer 2 (Or NULL) }
      iFields       : Word;             { Fields to compare in full }
      iLen          : Word;             { Partial key to compare }
var   iResult       : SmallInt          { Compare result }
   ): DBIResult;


Function BtrGetRecordForKey (           { Find a record matching key }
      hCursor       : hDBICur;          { Cursor handle }
      bDirectKey    : Bool;             { Key is supplied directly }
      iFields       : Word;             { No of full fields to match }
      iLen          : Word;             { Partial key len of last field }
      pKey          : Pointer;          { Either Record buffer or Key itself }
      pRecBuff      : Pointer           { (Optional) Record buffer }
   ): DBIResult;


{=============================================================================}
{                          Validity check and referential integrity           }
{=============================================================================}

Function BtrGetVchkDesc (               { Get valcheck descriptor }
      hCursor       : hDBICur;          { Cursor handle }
      iValSeqNo     : Word;             { Valcheck sequence number }
      pvalDesc      : pVCHKDesc         { Returned valcheck description }
   ): DBIResult;


Function BtrGetRintDesc (               { Get referential integrity descriptor }
      hCursor       : hDBICur;          { Cursor handle }
      iRintSeqNo    : Word;             { Rint sequence number }
      printDesc     : pRINTDesc         { Returned rint description }
   ): DBIResult;


{=============================================================================}
{                              Cursor Maintenance                             }
{=============================================================================}


Function BtrSetToBegin (                { Reset cursor to beginning }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;


Function BtrSetToEnd (                  { Reset cursor to ending }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;


Function BtrSetToCursor (               { Set cursor to another cursor position }
      hDest         : hDBICur;          { Destination cursor }
      hSrc          : hDBICur           { Source cursor }
   ): DBIResult;


Function BtrGetBookMark (               { Get a book-mark }
      hCur          : hDBICur;          { Cursor }
      pBookMark     : Pointer           { Pointer to Book-Mark }
   ): DBIResult;


Function BtrSetToBookMark (             { Position to a Book-Mark }
      hCur          : hDBICur;          { Cursor }
      pBookMark     : Pointer           { Pointer to Book-Mark }
   ): DBIResult;


Function BtrCompareBookMarks (          { Compare two Book-marks }
      hCur          : hDBICur;          { Cursor }
      pBookMark1    : Pointer;          { Book mark 1 }
      pBookMark2    : Pointer;          { Book mark 2 }
var   CmpBkmkResult : CmpBkmkRslt       { Compare result }
   ): DBIResult;


{============================================================================}
{                      Data Access: Logical Record Level                     }
{============================================================================}


Function BtrGetNextRecord (             { Find/Get the next record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer(client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;


Function BtrGetPriorRecord (            { Find/Get the prior record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer (client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;


Function BtrGetRecord (                 { Gets the current record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer(client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;


Function BtrGetRelativeRecord (         { Find/Get a record by record number }
      hCursor       : hDBICur;          { Cursor handle }
      iPosOffset    : Longint;          { offset from current position }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer(client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;


Function BtrInitRecord (                { Initialize record area }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuff      : Pointer           { Record buffer }
   ): DBIResult;


Function BtrInsertRecord (              { Inserts a new record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock on this rec }
      pRecBuff      : Pointer           { New Record (client) }
   ): DBIResult;


Function BtrModifyRecord (              { Updates the current record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Modified record }
      bFreeLock     : Bool              { Free record lock }
   ): DBIResult;


Function BtrDeleteRecord (              { Deletes the current record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer           { Copy of deleted record }
   ): DBIResult;


Function BtrReadBlock (                 { Read a block of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecords      : Longint;          { Number of records to read }
      pBuf          : Pointer           { Buffer }
   ): DBIResult;


Function BtrWriteBlock (                { Write a block of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecords      : Longint;          { Number of records to write/written }
      pBuf          : Pointer           { Buffer }
   ): DBIResult;


Function BtrAppendRecord (              { Inserts a new record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuff      : Pointer           { New Record (client) }
   ): DBIResult;


Function BtrUndeleteRecord (            { Undeletes the current record }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;


Function BtrGetSeqNo (                  { Get logical record number }
      hCursor       : hDBICur;          { Cursor handle }
var   iSeqNo        : Longint           { Pointer to sequence number }
   ): DBIResult;


Function BtrSetToSeqNo (                { Position to a logical record number }
      hCursor       : hDBICur;          { Cursor handle }
      iSeqNo        : Longint           { Sequence number }
   ): DBIResult;


Function BtrGetRecordCount (            { Get the current number of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecCount     : Longint           { Number of records }
   ): DBIResult;



Function BtrGetExactRecordCount (       { Get the exact number of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecCount     : Longint           { Number of records }
   ): DBIResult;



Function BtrSetToRecordNo (             { Position to Physical Rec# }
      hCursor       : hDBICur;          { Cursor handle }
      iRecNo        : Longint           { Physical record number }
   ): DBIResult;


Function BtrSaveChanges (               { Flush all buffered changes }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;


Function BtrForceReread (               { Force Reread of buffers from Disk }
      hCursor       : hDBICur           { Cursor }
   ): DBIResult;


Function BtrCheckRefresh: DBIResult;    { Check refresh for session }


Function BtrMakePermanent (             { Make temporary table permanent }
      hCursor       : hDBICur;          { Cursor handle }
      pszName       : PChar;            { Rename temporary table }
      bOverWrite    : Bool              { Overwrite existing file }
   ): DBIResult;


Function BtrForceRecordReread (         { Force Reread of current record from Server }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuff      : Pointer           { Returned : record buffer }
   ): DBIResult;


{============================================================================}
{                            Field Level Access                              }
{============================================================================}

Function BtrGetField (                  { Get Field value }
      hCursor       : hDBICur;          { Cursor }
      iField        : Word;             { Field # (1..n) }
      pRecBuff      : Pointer;          { Record buffer }
      pDest         : Pointer;          { Destination field buffer }
var   bBlank        : Bool              { Returned : is field blank }
   ): DBIResult;


Function BtrPutField (                  { Put a value in the record buffer }
      hCursor       : hDBICur;          { Cursor }
      iField        : Word;             { Field # (1..n) }
      pRecBuff      : Pointer;          { Record buffer }
      pSrc          : Pointer           { Source field buffer }
   ): DBIResult;


Function BtrVerifyField (               { Verifies the field value }
      hCursor       : hDBICur;          { Cursor }
      iField        : Word;             { Field # (1..n) }
      pSrc          : Pointer;          { Field Value }
var   bBlank        : Bool              { Field is Blank (Returned) }
   ): DBIResult;


Function BtrOpenBlob (                  { Open a blob for access }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number (1..n) }
      eOpenMode     : DBIOpenMode       { Open for Read or RW }
   ): DBIResult;


Function BtrGetBlobSize (               { Gets the size of a blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
var   iSize         : Longint           { Blob size in bytes }
   ): DBIResult;


Function BtrGetBlob (                   { Read bytes from blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
      iOffSet       : Longint;          { Starting position }
      iLen          : Longint;          { No of bytes to be read }
      pDest         : Pointer;          { Destination }
var   iRead         : Longint           { Actual no of bytes read }
   ): DBIResult;


Function BtrPutBlob (                   { Write bytes to blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
      iOffSet       : Longint;          { Starting position }
      iLen          : Longint;          { No of bytes to put }
      pSrc          : Pointer           { pntr to Source }
   ): DBIResult;


Function BtrTruncateBlob (              { Reduces the blob size }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
      iLen          : Longint           { New blob length }
   ): DBIResult;


Function BtrFreeBlob (                  { Closes the blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word              { Field number of blob (0..n) }
   ): DBIResult;


Function BtrGetBlobHeading (            { Get Blob Heading }
      hCursor       : hDBICur;          { Cursor handle }
      iField        : Word;             { Field number of blob (1..n) }
      pRecBuf       : Pointer;          { Record buffer of owner record }
      pDest         : Pointer           { Destination buffer }
   ): DBIResult;


Function BtrSetFieldMap (               { Set a fieldmap }
      hCur          : hDBICur;          { Cursor handle }
      iFields       : Word;             { Number of fields }
      pFldDesc      : pFLDDesc          { Array of field descriptions }
   ): DBIResult;



{=============================================================================}
{                                TRANSACTIONS                                 }
{=============================================================================}

Function BtrBeginTran (                 { Begin a transaction }
      hDb           : hDBIDb;           { Database handle }
      eXIL          : eXILType;         { Transaction isolation level }
var   hXact         : hDBIXact          { Returned Xact handle }
   ): DBIResult;


Function BtrEndTran (                   { End a transaction }
      hDb           : hDBIDb;           { Database handle }
      hXact         : hDBIXact;         { Xact handle }
      eEnd          : eXEnd             { Xact end type }
   ): DBIResult;


Function BtrGetTranInfo (               { Get transaction info }
      hDb           : hDBIDb;           { Database handle }
      hXact         : hDBIXact;         { Xact handle }
      pxInfo        : pXInfo            { Xact info }
   ): DBIResult;


{=============================================================================}
{                                  LOCKING                                    }
{=============================================================================}

Function BtrAcqTableLock (              { Lock a table }
      hCursor       : hDBICur;          { Cursor handle }
      eLockType     : DBILockType       { Lock type }
   ): DBIResult;


Function BtrAcqPersistTableLock (       { Get a persistent lock }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar             { Driver type / NULL }
   ): DBIResult;


Function BtrRelPersistTableLock (       { Releases a persistent lock }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar             { Driver type / NULL }
   ): DBIResult;


Function BtrRelTableLock (              { Unlocks Table level locks }
      hCursor       : hDBICur;          { Cursor handle }
      bAll          : Bool;             { True for all table level locks }
      eLockType     : DBILockType       { Specific lock type }
   ): DBIResult;


Function BtrRelRecordLock (             { Releases record level locks }
      hCursor       : hDBICur;          { Cursor handle }
      bAll          : Bool              { True for all. Default Current. }
   ): DBIResult;


Function BtrIsRecordLocked (            { Check if current record is locked }
      hCursor       : hDBICur;          { Cursor handle }
var   bLocked       : Bool              { Rec lock status }
   ): DBIResult;


Function BtrIsTableLocked (             { Verify if Table is locked }
      hCursor       : hDBICur;          { Cursor handle }
      epdxLock      : DBILockType;      { Lock type to verify }
var   iLocks        : Word              { Nbr of locks of the given type }
   ): DBIResult;


Function BtrIsTableShared (             { Verify if this is a shared table }
      hCursor       : hDBICur;          { Cursor handle }
var   bShared       : Bool              { Shared status }
   ): DBIResult;


Function BtrOpenLockList (              { Get a list of locks }
      hCursor       : hDBICur;          { Cursor handle }
      bAllUsers     : Bool;             { True, for all Users locks }
      bAllLockTypes : Bool;             { True, for all lock types }
var   hLocks        : hDBICur           { Returned cursor on Lock list }
   ): DBIResult;


Function BtrOpenUserList (              { Get a list of users loggedin }
var   hUsers        : hDBICur           { Returned cursor on user list }
   ): DBIResult;


Function BtrSetLockRetry (              { Set Lock wait time }
      iWait         : SmallInt          { Time in seconds }
   ): DBIResult;


{============================================================================}
{                              Batch Operations                              }
{============================================================================}


Function BtrBatchMove (                 { Copy records to destination table }
      pSrcTblDesc   : pBATTblDesc;      { Source table identification, }
      hSrcCur       : hDBICur;          {  OR source cursor  ( one must be NULL ) }
      pDstTblDesc   : pBATTblDesc;      { Destination table identification, }
      hDstCur       : hDBICur;          {  OR destination cursor ( one must be NULL ) }
      ebatMode      : eBATMode;         { Batch mode }
      iFldCount     : Word;             { Size of field maps }
      pSrcFldMap    : PWord;            { Array of source field numbers }
      pszIndexName  : PChar;            { If update mode, used to match records }
      pszIndexTagName : PChar;          { Index tag name }
      iIndexId      : Word;             { Index  id }
      pszKeyviolName : PChar;           { Keyviol table name  (optional) }
      pszProblemsName : PChar;          { Problems table name (optional) }
      pszChangedName : PChar;           { Changed table name (optional) }
      lProbRecs     : PLongint;         { Number records written to problem table }
      lKeyvRecs     : PLongint;         { Number records written to keyv table }
      lChangedRecs  : PLongint;         { Number records written to changed table }
      bAbortOnFirstProb : Bool;         { If TRUE, abort on first problem rec }
      bAbortOnFirstKeyviol : Bool;      { If TRUE, abort on first keyviol rec }
var   lRecsToMove   : Longint;          { Number of records to read from source }
      bTransliterate : Bool             { If TRUE, transliterate character data }
   ): DBIResult;


Function BtrCopyTable (                 { Copy one table to another }
      hDb           : hDBIDb;           { Database handle }
      bOverWrite    : Bool;             { True, to overwrite existing file }
      pszSrcTableName : PChar;          { Source table name }
      pszSrcDriverType : PChar;         { Source driver type }
      pszDestTableName : PChar          { Destination table name }
   ): DBIResult;


Function BtrEmptyTable (                { Deletes all records }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar             { Driver type /NULL }
   ): DBIResult;


Function BtrPackTable (                 { Pack a table }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      bRegenIdxs    : Bool              { Regenerate indexes }
   ): DBIResult;


Function BtrRegenIndex (                { Regenerate an index }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszIndexName  : PChar;            { Index name }
      pszIndexTagName : PChar;          { Index tagname (xbase MDX) }
      iIndexId      : Word              { Index number }
   ): DBIResult;


Function BtrRegenIndexes (              { Regenerate all indexes }
      hCursor       : hDBICur           { Cursor }
   ): DBIResult;


Function BtrSortTable (                 { Sort table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name of source }
      pszDriverType : PChar;            { Driver type /NULL }
      hSrcCur       : hDBICur;          { OR cursor of table to sort }
      pszSortedName : PChar;            { Destination table (NULL if sort to self) }
      phSortedCur   : phDBICur;         { If non-null, return cursor on destination }
      hDstCur       : hDBICur;          { OR cursor of destination }
      iSortFields   : Word;             { Number of sort fields }
      piFieldNum    : PWord;            { Array of field numbers }
      pbCaseInsensitive : PBool;        { Which fields should sort c-i (Opt) }
      pSortOrder    : pSORTOrder;       { Array of Sort orders (Opt) }
      ppfSortFn     : ppfSORTCompFn;    { Array of compare fn pntrs (Opt) }
      bRemoveDups   : Bool;             { TRUE : Remove duplicates }
      hDuplicatesCur : hDBICur;         { Cursor to duplicates table (Opt) }
var   lRecsSort     : Longint           { In/out param. - sort this number }
   ): DBIResult;



{============================================================================}
{                           Create & Restructure                             }
{============================================================================}

Function BtrCreateTable (               { Create a new table }
      hDb           : hDBIDb;           { Database handle }
      bOverWrite    : Bool;             { True, to overwrite existing file. }
var   crTblDsc      : CRTblDesc         { Table description }
   ): DBIResult;


Function BtrCreateInMemTable (          { Create a temporary table (Logical) }
      hDb           : hDBIDb;           { Database handle }
      pszName       : PChar;            { Logical Name }
      iFields       : Word;             { No of fields }
      pfldDesc      : pFLDDesc;         { Array of field descriptors }
var   hCursor       : hDBICur           { Returned cursor handle }
   ): DBIResult;


Function BtrCreateTempTable (           { Create temporary table (Physical) }
      hDb           : hDBIDb;           { Database handle }
var   crTblDsc      : CRTblDesc;        { Table description }
var   hCursor       : hDBICur           { Returned cursor on table }
   ): DBIResult;


Function BtrDoRestructure (             { Restructure a table }
      hDb           : hDBIDb;           { Database handle }
      iTblDescCount : Word;             { Number of table descriptors (1) }
      pTblDesc      : pCRTblDesc;       { Array of table descs }
      pszSaveAs     : PChar;            { Restructure to this table }
      pszKeyviolName : PChar;           { Keyviol table name  (optional) }
      pszProblemsName : PChar;          { Problems table name (optional) }
      bAnalyzeOnly  : Bool              { Analyze restructure }
   ): DBIResult;


Function BtrRenameTable (               { Rename table & family }
      hDb           : hDBIDb;           { Database handle }
      pszOldName    : PChar;            { Old name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszNewName    : PChar             { New name }
   ): DBIResult;


Function BtrDeleteTable (               { Delete a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Name including any path }
      pszDriverType : PChar             { Driver type /NULL }
   ): DBIResult;


Function BtrAddIndex (                  { Add a new index }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name including any path }
      pszDriverType : PChar;            { Driver type /NULL }
var   IdxDesc       : IDXDesc;          { Description of the index }
      pszKeyviolName : PChar            { Keyviol table name (optional) }
   ): DBIResult;


Function BtrDeleteIndex (               { Delete index }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszIndexName  : PChar;            { Index name }
      pszIndexTagName : PChar;          { Index tagname (xbase MDX) }
      iIndexId      : Word              { Index number }
   ): DBIResult;


{===========================================================================}
{                            Error Info                                     }
{===========================================================================}

Function BtrGetErrorEntry (             { Get error entry }
      uEntry        : Word;             { Error stack entry }
var   ulNativeError : Longint;          { Returned. Native error code, if any }
      pszError      : PChar             { Returned. Error string, if any }
   ): DBIResult;


Function BtrGetErrorInfo (              { Return info on last error }
      bFull         : Bool;             { If Full details }
var   ErrInfo       : DBIErrInfo        { Error Info }
   ): DBIResult;


Function BtrGetErrorString (            { Get message for error code }
      rslt          : DBIResult;        { Engine error code }
      pszError      : PChar             { Error string for the error }
   ): DBIResult;


Function BtrGetErrorContext (           { Get specific Context if available }
      eContext      : SmallInt;         { Context type }
      pszContext    : PChar             { Context string (MAXMSGLEN +1) }
   ): DBIResult;


{============================================================================}
{                              Dbi Services                                  }
{============================================================================}

Function BtrDateEncode (                { Encode Date components into Date }
      iMon          : Word;             { Month    (1..12) }
      iDay          : Word;             { Day      (1..31) }
      iYear         : SmallInt;         { Year     (0..2**16-1) }
var   dateD         : DBIDATE           { Encoded date }
   ): DBIResult;


Function BtrDateDecode (                { Decode Date into components }
      dateD         : DBIDATE;          { Encoded Date }
var   iMon          : Word;             { Month }
var   iDay          : Word;             { Day }
var   iYear         : SmallInt          { Year }
   ): DBIResult;


Function BtrTimeEncode (                { Encode Time components into TIME }
      iHour         : Word;             { Hours (0..23) }
      iMin          : Word;             { Minutes (0..59) }
      iMilSec       : Word;             { Milli Seconds (0..59999) }
var   timeT         : Time              { Encoded Time }
   ): DBIResult;


Function BtrTimeDecode (                { Decode TIME into components }
      timeT         : Time;             { Encoded Time }
var   iHour         : Word;             { Hours (0..23) }
var   iMin          : Word;             { Minutes (0..59) }
var   iMilSec       : Word              { Milli Seconds (0..59999) }
   ): DBIResult;


Function BtrTimeStampEncode (           { Encode Date & TIme into Date+Time }
      dateD         : DBIDATE;          { Encoded Date }
      timeT         : Time;             { Encoded Time }
var   tsTS          : TimeStamp         { Encoded Date+Time }
   ): DBIResult;


Function BtrTimeStampDecode (           { Decode Date & Time from Date+Time }
      tsTS          : TIMESTAMP;        { Encoded Date+Time }
var   dateD         : DBIDATE;          { Encoded Date }
var   timeT         : Time              { Encoded Time }
   ): DBIResult;



Function BtrBcdFromFloat (              { Converts FLOAT number into FMTBcd format }
var   iVal          : Double;           { Float to convert }
      iPrecision    : Word;             { Precision of BCD }
      iPlaces       : Word;             { Number of decimals }
var   Bcd           : FMTBcd            { returns Bcd number (length = iPrecision +2) }
   ): DBIResult;


Function BtrBcdToFloat (                { Converts FMTBcd number to FLOAT }
var   Bcd           : FMTBcd;           { Bcd number to convert }
var   iVal          : Double            { Returns converted float }
   ): DBIResult;


{===========================================================================}
{                           CallBacks                                       }
{===========================================================================}

Function BtrRegisterCallBack (          { Register a call back fn }
      hCursor       : hDBICur;          { Cursor (Optional) }
      ecbType       : CBType;           { Type of call back }
      iClientData   : Longint;          { Pass-thru client data }
      iCbBufLen     : Word;             { Callback buffer len }
      CbBuf         : Pointer;          { Pointer to callback buffer }
      pfCb          : pfDBICallBack     { Call back fn being registered }
   ): DBIResult;


Function BtrGetCallBack (               { Register a call back fn }
      hCursor       : hDBICur;          { Cursor (Optional) }
      ecbType       : CBType;           { Type of call back }
      piClientData  : PLongint;         { Pass-thru client data }
      piCbBufLen    : PWord;            { Callback buffer len }
      ppCbBuf       : Pointer;          { Pointer to callback buffer }
var   pfCb          : pfDBICallBack     { Call back fn being registered }
   ): DBIResult;


{============================================================================}
{                          Date, time formats                                }
{============================================================================}


Function BtrGetDateFormat (             { Get current date format }
var   fmtDate       : FMTDate
   ): DBIResult;


Function BtrSetDateFormat (             { Set current date format }
var   fmtDate       : FMTDate
   ): DBIResult;


Function BtrGetTimeFormat (             { Get current time format }
var   fmtTime       : FMTTime
   ): DBIResult;


Function BtrSetTimeFormat (             { Set current time format }
var   fmtTime       : FMTTime
   ): DBIResult;


Function BtrGetNumberFormat (           { Get current number format }
var   fmtNumber     : FMTNumber
   ): DBIResult;


Function BtrSetNumberFormat (           { Set current number format }
var   fmtNumber     : FMTNumber
   ): DBIResult;


{============================================================================}
{                      Conversions                                           }
{============================================================================}

Function BtrNativeToAnsi (              { Convert from native to Ansi }
      LdObj         : Pointer;          { Language driver }
      pAnsiStr      : PChar;            { Destination buffer (opt) }
      pNativeStr    : PChar;            { Source buffer }
      iLen          : Longint;          { Length of buffer (opt) }
var   bDataLoss     : Bool              { Returns TRUE if conversion will loose data (opt) }
   ): DBIResult;


Function BtrAnsiToNative (              { Convert from Ansi to native }
      LdObj         : Pointer;          { Language driver }
      pNativeStr    : PChar;            { Destination buffer (opt) }
      pAnsiStr      : PChar;            { Source buffer }
      iLen          : Longint;          { Length of buffer (opt) }
var   bDataLoss     : Bool              { Returns TRUE if conversion will loose data (opt) }
   ): DBIResult;


{============================================================================}
{                            Filters                                         }
{============================================================================}

Function BtrAddFilter (                 { Add a filter to the cursor }
      hCursor       : hDBICur;          { Cursor handle }
      iClientData   : Longint;          { Client supplied data      (opt) }
      iPriority     : Word;             { 1..N with 1 being highest (opt) }
      bCanAbort     : Bool;             { TRUE if pfFiltercan return ABORT (opt) }
      pcanExpr      : pCANExpr;         { Expression tree        (opt) }
      pfFilter      : pfGENFilter;      { ptr to filter function (opt) }
var   hFilter       : hDBIFilter        { Returns filter handle }
   ): DBIResult;


Function BtrDropFilter (                { Drop a filter }
      hCursor       : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter        { Filter handle }
   ): DBIResult;


Function BtrActivateFilter (            { Activate a Filter }
      hCursor       : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter        { Filter handle }
   ): DBIResult;


Function BtrDeactivateFilter (          { Deactivate Filter }
      hCursor       : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter        { Filter handle }
   ): DBIResult;


Function BtrGetFilterInfo (             { Get filter information }
      hCur          : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter;       { Filter handle          /NULL }
      iFilterId     : Word;             { Filter id              /0 }
      iFilterSeqNo  : Word;             { Filter sequence number /0 }
var   Filterinfo    : FilterInfo        { Returns filter info }
   ): DBIResult;


{============================================================================}
{                            Linked Cursors                                  }
{============================================================================}

Function BtrBeginLinkMode (             { Convert cursor to a link cursor }
var   hCursor       : hDBICur           { In/Out : returns new cursor }
   ): DBIResult;


Function BtrEndLinkMode (               { Convert cursor back to normal cursor }
var   hCursor       : hDBICur           { In/Out : returns original cursor }
   ): DBIResult;


Function BtrLinkDetail (                { Link detail to master }
      hMstrCursor   : hDBICur;          { Master cursor }
      hDetlCursor   : hDBICur;          { Detail cursor }
      iLnkFields    : Word;             { Number of link fields }
      piMstrFields  : PWord;            { Array of fields in master }
      piDetlFields  : PWord             { Array of fields in detail }
   ): DBIResult;


Function BtrLinkDetailToExp (           { Link detail to a master using exp }
      hCursorMstr   : hDBICur;          { Master cursor }
      hCursorDetl   : hDBICur;          { Detail cursor }
      iKeyLen       : Word;             { Key length to match }
      pszMstrExp    : PChar             { Expression string }
   ): DBIResult;


Function BtrUnlinkDetail (              { Unlink detail from master }
      hDetlCursor   : hDBICur           { Detail cursor to unlink }
   ): DBIResult;


Function BtrGetLinkStatus (             { Query linkage info for table }
      hCursor       : hDBICur;          { Cursor handle }
var   hCursorMstr   : hDBICur;          { Returns master cursor, if any   (opt) }
var   hCursorDet    : hDBICur;          { Returns first detail cursor, if any (opt) }
var   hCursorSib    : hDBICur           { Returns next sibling detail cursor, if any (opt) }
   ): DBIResult;



{===========================================================================}
{                            Translation                                    }
{===========================================================================}


Function BtrTranslateRecordStructure (  { Translate a record }
      pszSrcDriverType : PChar;         { Source driver type }
      iFlds         : Word;             { Number of fields }
      pfldsSrc      : pFLDDesc;         { Array of source fields: logical or physical types }
      pszDstDriverType : PChar;         { Destination driver type }
      pszLangDriver : PChar;            { Language driver for destination }
      pfldsDst      : pFLDDesc;         { Array of dest. fields returned }
      bCreatable    : Bool              { TRUE -> map to creatable fields only. }
   ): DBIResult;


Function BtrOpenFieldXlt (              { Open translation object }
      pszSrcTblType : PChar;            { NULL for Logical }
      pszSrcLangDrv : PChar;            { NULL if no tranliteration }
      pfldSrc       : pFLDDesc;         { source field descriptor }
      pszDestTblType : PChar;           { NULL for Logical }
      pszDstLangDrv : PChar;            { NULL if no tranliteration }
      pfldDest      : pFLDDesc;         { Source field descriptor }
var   bDataLoss     : Bool;             { Set to TRUE, for data loss }
var   hXlt          : hDBIXlt           { Returned translate handle }
   ): DBIResult;


Function BtrTranslateField (            { Translate a field }
      hXlt          : hDBIXlt;          { Translation handle }
      pSrc          : Pointer;          { Source field }
      pDest         : Pointer           { Destination field }
   ): DBIResult;


Function BtrCloseFieldXlt (             { Close translation object }
      hXlt          : hDBIXlt           { Translation handle }
   ): DBIResult;


{=========================================================================}
{    Delayed Updates                                                      }
{=========================================================================}

Function BtrBeginDelayedUpdates (       { put cursor in delayed update mode }
var   hCursor       : hDBICur           { In/Out : returns new Cursor }
   ): DBIResult;


Function BtrEndDelayedUpdates (         { Convert cursor back to normal cursor }
var   hCursor       : hDBICur           { In/Out : returns original Cursor }
   ): DBIResult;


Function BtrApplyDelayedUpdates (       { Perform the specified operation. }
      hCursor       : hDBICur;          { Delayed update cursor handle }
      eUpdCmd       : DBIDelayedUpdCmd  { Op Type: Commit or Rollback. }
   ): DBIResult;


Function BtrGetDelayedUpdates (
      hCursor       : hDBICur;          { Delayed update cursor handle }
var   hCache        : hDBICur           { In/Out: returns cursor on cache }
   ): DBIResult;

{===========================================================================}
{                                 MISC.                                     }
{===========================================================================}


Function BtrGetTableOpenCount (         {  Get local cursor count }
      hDb           : hDBIDb;           { Database }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
var   iOpenCount    : Word              { returned number of cursors }
   ): DBIResult;


Function BtrUseIdleTime: DBIResult;     { Use Idle time }


Function BtrGetLdObj (                  { Get language driver }
      hCursor       : hDBICur;          { Cursor handle }
var   pLdObj        : Pointer           { Returned language driver object }
   ): DBIResult;


Function BtrGetLdName (                 { Get language driver name from table }
      pszDriver     : PChar;            { Driver name }
      pObjName      : PChar;            { Name of object, i.e. table name }
      pLdName       : PChar             { Returned language driver name }
   ): DBIResult;


Function BtrFormFullName (              { Form Full Name }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszFullName   : PChar             { Returns full name }
   ): DBIResult;


Function BtrAddPassword (               { Add a password to current session }
      pszPassword   : PChar             { Password }
   ): DBIResult;


Function BtrDropPassword (              { Drop a password from current session }
      pszPassword   : PChar             { password/NULL }
   ): DBIResult;


Function BtrGetNetUserName (            { Get network username }
      pszNetUserName : PChar            { Returns username }
   ): DBIResult;



Function BtrDebugLayerOptions (         { Get SDK debug layer options }
      iOption       : Word;             { Option }
      pDebugFile    : PChar
   ): DBIResult;


Function BtrOpenCfgInfoList (           { Open a cursor on "Config" }
      hCfg          : hDBICfg;          { NULL }
      eOpenMode     : DBIOpenMode;      { ReadWrite or readonly }
      eConfigMode   : CFGMode;          { Config mode }
      pszCfgPath    : PChar;            { Path }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;

Function BtrImportODBC(                 { Import current ODBC drivers and data sources }
      hCfg          : hDBICfg;          { NULL }
      bPersist      : Bool              { Persistent or session relative }
   ): DBIResult;

Function BtrAddAlias (                  { Add a new alias }
      hCfg          : hDBICfg;          { NULL }
      pszAliasName  : PChar;            { Alias name }
      pszDriverType : PChar;            { Driver type for alias }
      pszParams     : PChar;            { Optional parameters }
      bPersist      : Bool              { Persistent or session relative }
   ): DBIResult;


Function BtrDeleteAlias (               { Add a new alias }
      hCfg          : hDBICfg;          { NULL }
      pszAliasName  : PChar             { Alias name }
   ): DBIResult;

Function BtrAddDriver(                  { Add a new driver }
      hCfg          : hDBICfg;          { NULL }
      pszDriverName : PChar;            { Driver name }
      pszParams     : PChar;            { Optional parameters }
      bPersist      : Bool              { Persistent or session relative }
   ): DBIResult;

Function BtrDeleteDriver(               { Delete a driver }
      hCfg          : hDBICfg;          { NULL }
      pszDriverName : PChar;            { Driver name }
      bSave         : Bool              { Save config file }
   ): DBIResult;



{ This IFDEF is here so PP.EXE will strip out these undocumented BDE API's }

Function BtrOpenConfigFile (            { Open/Create configuration }
      pszDirPath    : PChar;            { Directory }
      bCreate       : Bool;             { TRUE to create/overwrite }
var   hCfg          : hDBICfg           { Handle to config }
   ): DBIResult;


Function BtrCloseConfigFile (           { Close the config file }
var   hCfg          : hDBICfg;          { Handle }
      bSave         : Bool;             { To save the changes }
      bDefault      : Bool;             { To make this file the default }
      bSaveAs16     : Bool              { To save as a 16-bit config file }
   ): DBIResult;


Function BtrCfgSave (                   { Save current configuration }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszNewFile    : PChar;            { (Optional): Save as this file }
      bSaveAs16     : Bool              { To save as a 16-bit config file }
   ): DBIResult;


Function BtrCfgBuildPath (              { Build a path for accessing config. }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCategory   : PChar;            { NULL for root }
      pszGroup      : PChar;            { NULL for no group }
      pszSection    : PChar;            { NULL fro no section }
      pszCfgPath    : PChar             { Returned path }
   ): DBIResult;


Function BtrCfgPosition (               { Position the config path }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar             { Path }
   ): DBIResult;


Function BtrCfgGetNextNode (            { Get next defined node }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszNodeName   : PChar             { Node name (Returned) }
   ): DBIResult;


Function BtrCfgGetRecord (              { Get a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar;            { Path }
var   iFields       : Word;             { Returned nbr of fields }
      pfldDesc      : pFLDDesc;         { Field descriptors }
      pRec          : Pointer           { Field values }
   ): DBIResult;


Function BtrCfgAddRecord (              { Add a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar;            { Path }
      iFields       : Word;             { No of fields }
      pfldDesc      : pFLDDesc;         { Field descriptors }
      pRec          : Pointer           { Data values }
   ): DBIResult;


Function BtrCfgModifyRecord (           { Modify a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar;            { Path }
      iFields       : Word;             { Nbr of fields }
      pfldDesc      : pFLDDesc;         { Field descriptors }
      pRec          : Pointer           { Data values }
   ): DBIResult;


Function BtrCfgDropRecord (             { Delete a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar             { Path }
   ): DBIResult;


Function BtrCfgTranslate (              { Translate configuration string }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszConfigPath : PChar;            { configuration path }
      pszTrans      : PChar;            { translated path }
      iFields       : Word;             { number of fields, 0 if path only }
      pfldDesc      : pFLDDesc;         { field descriptors, NULL if path only }
      pRec          : Pointer           { record buffer, NULL if path only }
   ): DBIResult;


Function BtrCfgGetHelp (                { Get help message }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszConfigPath : PChar;            { configuration path }
      pszFldName    : PChar;            { field name  ( optional ) }
      pszHelpString : PChar             { help string ( returned ) }
   ): DBIResult;


Function BtrCfgMerge (                  { Merge config files }
      hCfgDest      : hDBICfg;          { Destination Cfg handle/ NULL }
      hCfgSrc       : hDBICfg;          { Source Cfg handle/ NULL }
      pszSrcPath    : PChar             { Source Path / NULL }
   ): DBIResult;



{===========================================================================}
{                      Query Management                                     }
{===========================================================================}

Function BtrQExecDirect (               { Execute query }
      hDb           : hDBIDb;           { Database handle }
      eQryLang      : DBIQryLang;       { Query language }
      pszQuery      : PChar;            { Query }
      phCur         : phDBICur          { Returned cursor on result set }
   ): DBIResult;


Function BtrQAlloc (                    { Allocates a statement handle }
      hDb           : hDBIDb;           { Database handle }
      eQryLang      : DBIQryLang;       { Query language }
var   hStmt         : hDBIStmt          { Returned statment handle }
   ): DBIResult;


Function BtrQPrepare (                  { Prepare a query }
      hStmt         : hDBIStmt;         { Returned statment handle }
      pszQuery      : PChar             { Query }
   ): DBIResult;


Function BtrQPrepareExt (               { Prepare a query }
      hDb           : hDBIDb;           { Database handle }
      eQryLang      : DBIQryLang;       { Query language }
      pszQuery      : PChar;            { Query }
      propBits      : Word;             { properties for Prepare, e.g. qprepFORUPDATE }
var   hStmt         : hDBIStmt          { Returned statment handle }
   ): DBIResult;


Function BtrQExec (                     { Execute prepared query }
      hStmt         : hDBIStmt;         { Statement handle }
      phCur         : phDBICur          { Returned handle on result set }
   ): DBIResult;


Function BtrQFree (                     { Free statement handle }
var   hStmt         : hDBIStmt          { Statement handle }
   ): DBIResult;


Function BtrQSetParams (                { Set query options }
      hStmt         : hDBIStmt;         { Statement handle }
      uFldDescs     : Word;             { Number of parameter field descriptors }
      paFldDescs    : pFLDDesc;         { Array of parameter field descriptors }
      pRecBuff      : Pointer           { Record buffer }
   ): DBIResult;


Function BtrQInstantiateAnswer (        { Create answer table }
      hStmt         : hDBIStmt;         { Statement Handle }
      hCur          : hDBICur;          { Cursor Handle }
      pszAnswerName : PChar;            { Answer Table Name/NULL }
      pszAnswerType : PChar;            { Answer Table Type/NULL }
      bOverWrite    : Bool;             { Overwrite Flag }
      phCur         : phDBICur          { cursor to instantiated table (output)(optional) }
   ): DBIResult;


Function BtrQExecProcDirect (           { Direct execution of stored procedure }
      hDb           : hDBIDb;           { Database handle }
      pszProc       : PChar;            { Stored procedure name }
      uParamDescs   : Word;             { Number of parameter descriptors }
      paParamDescs  : pSPParamDesc;     { Array of parameter descriptors }
      pRecBuff      : Pointer;          { Record buffer }
var   hCur          : hDBICur           { Returned handle on result set }
   ): DBIResult;


Function BtrQPrepareProc (              { Prepare a stored procedure }
      hDb           : hDBIDb;           { Database handle }
      pszProc       : PChar;            { Stored procedure name }
      uParamDescs   : Word;             { Number of parameter descriptors }
      paParamDescs  : pSPParamDesc;     { Array of parameter descriptors }
      pRecBuff      : Pointer;          { Record buffer }
var   hStmt         : hDBIStmt          { Returned statment handle }
   ): DBIResult;


Function BtrQSetProcParams (            { Set procedure params }
      hStmt         : hDBIStmt;         { Statement handle }
      uParamDescs   : Word;             { Number of parameter descriptors }
      paParamDescs  : pSPParamDesc;     { Array of parameter descriptors }
      pRecBuff      : Pointer           { Record buffer }
   ): DBIResult;

type
  PSTMTBaseDesc = ^STMTBaseDesc;
  STMTBaseDesc = packed record 
    szDatabase   : DBINAME;
    szTableName  : DBITBLNAME; 
    szFieldName  : DBINAME; 
    bExpression  : Bool; 
    bAggregate   : Bool; 
  end;

Function BtrQGetBaseDescs( 
      hStmt         : hDBIStmt;         { Statement Handle }
var   hCur          : hDBICur           { Cursor of type STMTBaseDesc }
   ): DBIResult;


{ This IFDEF is here so PP.EXE will strip out these undocumented BDE API's }

{===========================================================================}
{                      Language drivers                                     }
{===========================================================================}

const
  MAXLDNAME = 20;
  MAX_LCNAME_LEN = 32;
  DOS_CP = 1;
  WIN_CP = 2;
  UC_CP = 13;

type
  TOSBLObj = packed record
    LangId: SmallInt;
    LdName: array[0..MAXLDNAME - 1] of char;
    EnglishDesc: array[0..MAX_LCNAME_LEN - 1] of char;
    LdDescriptor: array[0..19] of char;
    LocaleHdl: Pointer;
    CodeSet: SmallInt;
    LocaleType: SmallInt;
    LanguageSortType: SmallInt;
    LocaleCount: SmallInt;
    PrimaryCpPlatform: SmallInt;
    PrimaryCodePageID: Word;
    AlternateCodePageID: Word;
    ProductID: Word;
    NoConversions: Bool;
    LdLCID: Integer;
  end;

function OsLdInit (                     { Initialize a Language Driver }
      pDefDir       : PChar;
      pDefLangDr    : PChar
   ): DBIResult;


function OsLdExit: DBIResult;


function OsLdGetDefaultObj (            { Get default language driver }
var   pLdObj        : PLocale
   ): DBIResult;


function OsLdGetSymbName (              { Get symbolic name }
      pLdObj        : PLocale;
      pSymbName     : PByte
   ): DBIResult;


function OsLdGetDriverId (              { Get driver id }
      pLdObj        : PLocale;
var   DriverId      : Word
   ): DBIResult;


function OsLdGetDescName (              { Get desciptive name }
      pLdObj        : PLocale;
      pDescName     : PByte
   ): DBIResult;


function OsLdGetSortsig (               { Get sort signature (paradox) }
      pLdObj        : PLocale;
var   SortSig       : SmallInt
   ): DBIResult;

function OsLdGetProductID (             { Get product ID (DBASE, PDOX, etc.) }
      pLdObj        : Pointer;
      piProdID      : PWord
   ): DBIResult;

function OsLdGetCodePage (              { Get codepage }
      pLdObj        : PLocale;
var   CodePage      : SmallInt
): DBIResult;


function OsLdGetFName (                 { Get filename (DOS only) }
      pLdObj        : PLocale;
      PName         : PChar
   ): DBIResult;



{ Init scan through available language drivers }
function OsLdSearchInit(var SHandle: Pointer): DBIResult;

function OsLdSearchEnd(SHandle: Pointer): DBIResult;

{ Get LdObj for next language driver in list }
{ (Note: the returned ppLdObj can only be used for the informational functions : }
{ OsLdGetSymbName, etc. }

function OsLdSearchNext(SHandle: Pointer; var ppLdObj: Pointer): DBIResult;


function OsLdLoadBySortSig(
      SortSig       : Word;
      CodePage      : Word;
var   pLdObj        : PLocale
    ): DBIResult;


function OsLdLoadByFName(
      pFName        : PChar;
var   pLdObj        : PLocale
   ): DBIResult;


function OsLdLoadBySymbName(
      pSymbName     : PChar;
var   pLdObj        : PLocale
   ): DBIResult;


function OsLdLoadByDriverId(
      iDriverId     : Word;
var   pLdObj        : PLocale
   ): DBIResult;

function OsLdLoadByLCID (
      _lcid         : Integer;
var   pLdObj: Pointer
   ): DBIResult;

function OsLdUnloadObj(
var   pLdObj        : PLocale
   ): DBIResult;

function OsLdGetMinMax (
      pLdObj        : Pointer;
      pcMin         : PChar;
      pcMax         : PChar
   ): DBIResult;

function OsLdStrnCmp(
      pLdObj        : PLocale;
      Str1          : PChar;
      Str2          : PChar;
      Len           : Word
   ): DBIResult;


function OsLdStrCmp(
      pLdObj        : PLocale;
      Str1          : PChar;
      Str2          : PChar
   ): DBIResult;


function OsLdStrToUpper(
      pLdObj        : PLocale;
      Str           : PByte
   ): DBIResult;


function OsLdStrnToUpper(
      pLdObj        : PLocale;
      Str           : PByte;
      Len           : Word
   ): DBIResult;


function OsLdStrToLower(
      pLdObj        : PLocale;
      Str           : PByte
   ): DBIResult;


function OsLdStrnToLower(
      pLdObj        : PLocale;
      Str           : PByte;
      Len           : Word
   ): DBIResult;


function OsLdStrCmpi(
      pLdObj        : PLocale;
      str1          : PCHAR;
      str2          : PChar
   ): SmallInt;


function OsLdStrnCmpi(
      pLdObj        : PLocale;
      Str1          : PChar;
      Str2          : PChar;
      Len           : Word
   ): SmallInt;

{ Multi purpose translate function : }
{ If destination is NULL, performs check only. }
{ If iLen = 0, assumes zero-terminated string, otherwise iLen is lenght of buffer to convert }
{ if destination == source, in place conversion is performed }
{ Works on both Ansi and Oem drivers. }
{ NOTE: does not take into account Japanese problem. }
function OsLdSetConvChars (
      o2a           : Shortint;
      a2o           : Shortint
   ): DBIResult;

function OsLdOemToAnsi(
      pLdObj        : PLocale;
      AnsiStr       : PChar;
      OemStr        : PChar;
      Len           : Word;
var   DataLoss      : BOOL
   ): DBIResult;


function OsLdAnsiToOem(
      pLdObj        : PLocale;
      OemStr        : PChar;
      AnsiStr       : PChar;
      Len           : Word;
var   DataLoss      : BOOL
): DBIResult;


function OsLdIsAnsiCharInOemCp(
      pLdObj        : PLocale;
      AnsiCh        : Char
   ): Bool;


function OsLdIsOemCharInAnsiCp(
      pLdObj        : PLocale;
      OemCh         : Char
   ): Bool;


function OsLdAnsiCharToOem(
      pLdObj        : PLocale;
      ch            : Byte
   ): Byte;


function OsLdOemCharToAnsi(
      pLdObj        : PLocale;
      ch            : Byte
   ): Byte;


function OsLdCharToUpper(
      pLdObj        : PLocale;
      ch            : Byte
   ): Byte;


function OsLdCharToLower(
      pLdObj        : PLocale;
      ch            : Byte
   ): Byte;


function OsLdIsAlpha(
      pLdObj        : PLocale;
      ch            : Byte
   ): Bool;


function OsLdIsDigit(
      pLdObj        : PLocale;
      ch            : Byte
   ): Bool;


function OsLdBuildCharSetXform(
      pCharMap      : PChar;
      pLdObjSrc     : PLocale;
      pLdObjDest    : PLocale;
var   DataLoss      : Bool
   ): Bool;

function OsLdGetFuncAddrLdStrnColli_ (
var   ppf           : Pointer
   ): DBIResult;

function OsLdGetFuncAddrLdStrnColl_ (
var   ppf           : Pointer
   ): DBIResult;

function OsLdGetFuncAddrLdStrnCmpi_ (
var   ppf           : Pointer
   ): DBIResult;

function OsLdStrnColl (
      pLdObj        : Pointer;
      Str1          : PByte;
      Str2          : PByte;
      Maxlen        : Word
   ): Shortint;

function OsLdStrnColli (
      pBlObj        : Pointer;
      str1          : PChar;
      str2          : PChar;
      iLen          : Word
   ): Shortint;

function OsLdExStrCmp (
      pLdObj        : Pointer;
      Right         : PByte;
      RightLen      : Shortint;
      Left          : PByte;
      LeftLen       : Shortint;
      Exact: Bool
   ): Shortint;


Function BtrGetLdNameFromDb(
      hDb           : hDbiDb;
      DbName        : PChar;
      pldName       : PChar
   ): DBIResult;

{ Schema Cache functions }
Function BtrSchemaCacheFlush(hDb: hDBIDb; pszTableName: PChar): DBIResult;

Function BtrBeginConstraintLayer(
     hDb          : hDBIDb;
var  hCur         : hDBICur;
     pDsCb        : pfDataSourcesCallback;
     lUserVal     : Integer
  ): DBIResult;

Function BtrEndConstraintLayer(
var  hCur         : hDBICur
  ): DBIResult;

Function BtrSQLTextToCanEx(
     hStmt         :  hDBIStmt;
     pExprText     :  PChar;
     iFields       :  Word;
     pFlds         :  pFLDDesc;
     exType        :  EXPType;
     pszFldName    :  PChar;
     pszSourceDb   :  PChar;
var  piCanSize     :  Word;
     pCanEx        :  PByte
   ): DBIResult;


Function BtrCheckSQLExpression(
     hCur          :  hDBICur;
     pszExpr       :  PChar;
     pszFldName    :  PChar;
     expType       :  EXPType;
     pDsCB         :  pfDataSourcesCallback;
     iClientData   :  Integer
   ): DBIResult;

function DsProviderGetDataPacket(
    hCur             : hDBICur;         { Result cursor handle }
    eProvOptions     : Integer;         { Options for provider }
    pDsCB            : Pointer;         { Callback for field origin }
    iClientData      : Integer;         { Client Data for callback }
    piMaxRecords     : PInteger;        { In: Max recs, Out: Actual Recs }
var Packet           : PVarArray;
var pbEndOfData      : Bool             { End of file was reached }
): DBIResult;

function DsResolver(
    iNoOfDataSources  : Integer;               { Number of data sources. }
    Packets           : PPacketList;           { Packet Buffer }
    hDb               : hDBIDb;                { Database handle. }
    szDbName          : PChar;                 { Database name }
    szDbType          : PChar;                 { Database type }
    szDbPassword      : PChar;                 { Password }
    pszSqlStr         : PNameList;             { SQL str used to generate Packet. }
    ppTableName       : PNameList;             { If open table, name of table }
    piClientData      : PInteger;              { Client Data for Resolver callback }
    ppfReconcile      : PCBList;               { Reconcile Callback-fn }
    ppDsCB            : PCBList;               { PpfDataSourcesCallback; }
    ClientData        : Integer;               { Client Data for DSCallback }
    piMaxErrorRecords : PInteger;              { In: MaxErrors, Out: ErrorCount }
    pppErrPacket      : PPacketList            { Packet Buffer for error set }
): DBIResult;

implementation
{$I BSE.INC}

Uses
  BseEng,
  BtrMain;

Const
  COPYRIGHT = 'Copyright 1995-1999 - Reggatta Systems, Inc.';

{============================================================================}
{                          Environmental                                     }
{----------------------------------------------------------------------------}

Function BtrInitFn (                    { Initialize the Engine }
      iVer          : Word;             { Interface Version }
      pEnv          : pDBIEnv           { Environment Structure/NULL }
   ): DBIResult;
begin
(*
  if not Assigned( VEng ) then
  begin
    VEng := StartEngine( iVer, pEnv );
    If ( VEng <> NIL ) then
      Result := DBIERR_NONE
    else
      Result := DBIERR_NOTINITIALIZED;
  end
  else
*)
    Result := DBIERR_MULTIPLEINIT;
end;


Function BtrExit: DBIResult;            { Exit engine }
begin
  If ( BtrEng <> NIL ) then
  begin
    Try
      BtrEng.Free;
    Finally
      BtrEng := NIL;
    End;
  end;
  Result := DBIERR_NONE;
end;


Function BtrDLLExit: DBIResult;         { Exit DLL }
begin
  Result := DBIERR_NONE;
end;


{============================================================================}
{                         System Level Info                                  }
{============================================================================}

Function BtrGetSysVersion (             { Get system version info }
var   sysVersion    : SYSVersion
   ): DBIResult;
begin
  Result := BtrEng.GetSysVersion( SysVersion );
end;


Function BtrGetSysConfig (              { System configuration }
var   sysConfig     : SYSConfig
   ): DBIResult;
begin
  Result := BtrEng.GetSysConfig( sysConfig );
end;



Function BtrGetClientInfo (             { Get Client info }
var   clientInfo    : CLIENTInfo
   ): DBIResult;
begin
  Result := BtrEng.GetClientInfo( clientInfo );
end;



Function BtrGetSysInfo (                { Get system status/info }
var   sysInfo       : SYSInfo
   ): DBIResult;
begin
  Result := BtrEng.GetSysInfo( sysInfo );
end;


Function BtrLoadDriver (                { Load a given driver }
      pszDriverType : PChar             { Driver name }
   ): DBIResult;
begin
  Result := BtrEng.LoadDriver( pszDriverType )
end;


{============================================================================}
{                            Sessions                                        }
{============================================================================}
Function BtrStartSession (              { Start a new session }
      pszName       : PChar;            { Name (Optional) }
var   hSes          : hDBISes;          { Session }
      pNetDir       : PChar             { Netfile directory for session (opt) }
   ): DBIResult;
begin
  Result := BtrEng.StartSession( pszName, hSes, pNetDir );
end;


Function BtrGetCurrSession (            { Get the current session }
var   hSes          : hDBISes           { Session }
   ): DBIResult;
begin
  Result := BtrEng.GetCurrSession( hSes );
end;


Function BtrSetCurrSession (            { Set the current session }
      hSes          : hDBISes           { Session/NULL }
   ): DBIResult;
begin
  Result := BtrEng.SetCurrSession( hSes );
end;


Function BtrCloseSession (              { Close the current session }
      hSes          : hDBISes           { Session }
   ): DBIResult;
begin
  Result := BtrEng.CloseSession( hSes )
end;


Function BtrGetSesInfo (                { Get current session info }
var   sesInfo       : SESInfo
   ): DBIResult;
begin
  Result := BtrEng.GetSesInfo( sesInfo );
end;


Function BtrSetPrivateDir (             { Set Private Directory for session }
      pszDir        : PChar             { Directory name/NULL }
   ): DBIResult;
begin
  Result := BtrEng.SetPrivateDir( pszDir );
end;


{============================================================================}
{                     Datababase, Schema and File inquiry                    }
{============================================================================}

Function BtrOpenDatabase (              { Open a database }
      pszDbName     : PChar;            { Database name }
      pszDbType     : PChar;            { Database type (NULL: Universal) }
      eOpenMode     : DBIOpenMode;      { Open type }
      eShareMode    : DBIShareMode;     { Share type }
      pszPassword   : PChar;            { Password }
      iOptFlds      : Word;             { Number of optional Params }
      pOptFldDesc   : pFLDDesc;         { Optional Field Descriptors }
      pOptParams    : Pointer;          { Optional Params }
var   hDb           : hDBIDb            { Returned database handle }
   ): DBIResult;
begin
  Result := BtrEng.OpenDatabase( pszDbName, pszDbType, eOpenMode, eShareMode,
              pszPassword, iOptFlds, pOptFldDesc, pOptParams, hDb )
end;


Function BtrSetDirectory (              { Set the current directory }
      hDb           : hDBIDb;           { Universal database handle }
      pszDir        : PChar             { Directory/NULL }
   ): DBIResult;
begin
  Result := BtrEng.SetDirectory( hDb, pszDir )
end;


Function BtrGetDirectory (              { Get the current/default directory }
      hDb           : hDBIDb;           { Universal database handle }
      bDefault      : Bool;             { True for default }
      pszDir        : PChar             { Returned directory }
   ): DBIResult;
begin
  Result := BtrEng.GetDirectory( hDb, bDefault, pszDir );
end;


Function BtrOpenTableList (             { Open a cursor on "Tables" }
      hDb           : hDBIDb;           { Database handle }
      bExtended     : Bool;             { True for extended info }
      bSystem       : Bool;             { True to include system tables }
      pszWild       : PChar;            { Wild card name }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenTableList( hDb, bExtended, bSystem, pszWild, hCur )
end;


Function BtrOpenFileList (              { Open a cursor on "Files" }
      hDb           : hDBIDb;           { Universal database handle }
      pszWild       : PChar;            { Wild card name }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenFileList( hDb, pszWild, hCur );
end;


Function BtrOpenIndexList (             { Return "Indexes" for a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hCur          : hDBICur           { Returned cursor on "Indexes" }
   ): DBIResult;
begin
  Result := BtrEng.OpenIndexList( hdb, pszTableName, pszDriverType, hCur )
end;


Function BtrOpenFieldList (             { Return "Fields" for a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
      bPhyTypes     : Bool;             { True, for physical types }
var   hCur          : hDBICur           { Returned cursor on "Fields" }
   ): DBIResult;
begin
  Result := BtrEng.OpenFieldList( hDb, pszTableName, pszDriverType, bPhyTypes, hCur )
end;


Function BtrOpenVchkList (              { Return "Checks" for a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver Type }
var   hChkCur       : hDBICur           { Returned cursor on "Checks" }
   ): DBIResult;
begin
  Result := BtrEng.OpenVchkList( hDb, pszTableName, pszDriverType, hChkCur )
end;


Function BtrOpenRintList (              { Return Integrity checks }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hChkCur       : hDBICur           { Returned cursor on "Ref Int". }
   ): DBIResult;
begin
  Result := BtrEng.OpenRIntList( hDb, pszTableName, pszDriverType, hChkCur )
end;



Function BtrOpenSecurityList (          { Return security descriptions }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hSecCur       : hDBICur           { Returned cursor on sec list }
   ): DBIResult;
begin
  Result := BtrEng.OpenSecurityList( hDb, pszTableName, pszDriverType, hSecCur )
end;


Function BtrOpenFamilyList (            { Return family members }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type }
var   hFmlCur       : hDBICur           { Returned cursor on "Family" }
   ): DBIResult;
begin
  Result := BtrEng.OpenFamilyList( hDb, pszTableName, pszDriverType, hFmlCur )
end;


Function BtrOpenSPList (                { Open a cursor on "Stored Procedures" }
      hDb           : hDBIDb;           { Universal database handle }
      bExtended     : Bool;             { True for extended info (N/A) }
      bSystem       : Bool;             { True to include system procedures }
      pszQual       : PChar;            { Qualifier (N/A) }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenSPList( hDb, bExtended, bSystem, pszQual, hCur )
end;


Function BtrOpenSPParamList (           { Return "Parameters" for a stored procedure }
      hDb           : hDBIDb;           { Database handle }
      pszSPName     : PChar;            { Stored procedure name }
      bPhyTypes     : Bool;             { True, for physical types }
      uOverload     : Word;             { Overload number }
var   hCur          : hDBICur           { Returned cursor on "Parameters" }
   ): DBIResult;
begin
  Result := BtrEng.OpenSPParamList( hDb, pszSPName, bPhyTypes, uOverload, hCur )
end;


Function BtrOpenFunctionList (          { Open a cursor on "Functions" }
      hDb           : hDBIDb;           { Universal database handle }
      eoptBits      : DBIFUNCOpts;      { Options for function list }
      phCur         : phDBICur          { Returned cursor on "Functions" }
                                        { Record desc is of type DBIFUNCDesc }
   ): DBIResult;
begin
  Result := BtrEng.OpenFunctionList( hDb, eOPtBits, phCur );
end;


Function BtrOpenFunctionArgList (       { Return "Arguments" for a function }
      hDb           : hDBIDb;           { Database handle }
      pszFuncName   : PChar;            { Function name }
      uOverload     : Word;             { Overload number }
      phCur         : phDBICur          { Returned cursor on "Arguments" }
   ): DBIResult;
begin
  Result := BtrEng.OpenFunctionArgList( hDb, pszFuncName, uOverload, phCur );
end;


Function BtrCloseDatabase (             { Close a database }
var   hDb           : hDBIDb            { Pointer to database handle }
   ): DBIResult;
begin
  Result := BtrEng.CloseDatabase( hDb );
end;


{============================================================================}
{                                  Capabilities                              }
{============================================================================}

Function BtrOpenDriverList (            { Get a list of driver names }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenDriverList( hCur );
end;


Function BtrGetDriverDesc (             { Get description for a given type }
      pszDriverType : PChar;            { Symbolic name for driver type }
var   drvType       : DRVType           { Driver type description }
   ): DBIResult;
begin
  Result := BtrEng.GetDriverDesc( pszDriverType, drvType )
end;



Function BtrOpenDatabaseList (          { Get a list of registered databases }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenDatabaseList( hCur );
end;



Function BtrGetDatabaseDesc (           { Get a description of a logical db }
      pszName       : PChar;            { Name of logical database }
      pdbDesc       : pDBDesc           { Database description }
   ): DBIResult;
begin
  Result := BtrEng.GetDatabaseDesc( pszName, pdbDesc );
end;


Function BtrOpenTableTypesList (        { Get a list of table types }
      pszDriverType : PChar;            { Driver type }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenTableTypesList( pszDriverType, hCur );
end;


Function BtrGetTableTypeDesc (          { Get Table capabilities }
      pszDriverType : PChar;            { Driver type }
      pszTableType  : PChar;            { Table type }
var   tblType       : TBLType           { Table Capabilities }
   ): DBIResult;
begin
  Result := BtrEng.GetTableTypeDesc( pszDriverType, pszTableType, tblType );
end;



Function BtrOpenFieldTypesList (        { Get a list of field types }
      pszDriverType : PChar;            { Driver type }
      pszTblType    : PChar;            { Table type (Optional) }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenFieldTypesList( pszDriverType, pszTblType, hCur )
end;


Function BtrGetFieldTypeDesc (          { Get list of field types }
      pszDriverType : PChar;            { Driver type }
      pszTableType  : PChar;            { Table type }
      pszFieldType  : PChar;            { Field type  (Physical only) }
var   fldType       : FLDType           { Field type description }
   ): DBIResult;
begin
  Result := BtrEng.GetFieldTypeDesc( pszDriverType, pszTableType, pszFieldType, fldType )
end;



Function BtrOpenIndexTypesList (        { Get list of index types }
      pszDriverType : PChar;            { Driver type }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenIndexTypesList( pszDriverType, hCur );
end;



Function BtrGetIndexTypeDesc (          { Get description of given idx type }
      pszDriverType : PChar;            { Driver type }
      pszIndexType  : PChar;            { Index type }
var   idxType       : IDXType           { Index description }
   ): DBIResult;
begin
  Result := BtrEng.GetIndexTypeDesc( pszDriverType, pszIndexType, idxType );
end;



Function BtrOpenLdList (                { Get a list of Lang Drivers }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenLdList( hCur );
end;



{===========================================================================}
{                      Table Open, Properties & Structure                   }
{===========================================================================}

Function BtrOpenTable (                 { Open a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name or file name }
      pszDriverType : PChar;            { Driver type                 /NULL }
      pszIndexName  : PChar;            { Index to be used for access /NULL }
      pszIndexTagName : PChar;          { Index tag name              /NULL }
      iIndexId      : Word;             { Index number                /0 }
      eOpenMode     : DBIOpenMode;      { Read or RW }
      eShareMode    : DBIShareMode;     { Excl or Share }
      exltMode      : XLTMode;          { Xlate mode }
      bUniDirectional : Bool;           { Uni or Bi directional }
      pOptParams    : Pointer;          { Optional params /NULL }
var   hCursor       : hDBICur           { Returns Cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.OpenTable(
              hDb,
              pszTableName,
              pszDriverType,
              pszIndexName,
              pszIndexTagName,
              iIndexId,
              eOpenMode,
              eShareMode,
              exltMode,
              bUnidirectional,
              pOptParams,
              hCursor
            );
end;


Function BtrOpenNestedTable(                                { Get nested table }
           hCursor       : hDBICur;                         { Master cursor }
           iFieldNo      : Word;                            { FieldID of nested table field }
           bReadOnly     : Bool;                            { if TRUE, read only mode }
           bUniDirectional: Bool;                           { if TRUE, unidirectional }
           var hCursorNested : hDBICur                      { Returns Cursor handle for nested table }
         ): DBIResult;
begin
  Result := BtrEng.OpenNestedTable( hCursor, iFieldNo,
    bReadOnly, bUnidirectional, hCursorNested );
end;

Function BtrOpenRef(
           hCursor       : hDBICur;                         { Master cursor }
           iFieldNo      : Word;                            { FieldID }
           bReadOnly     : Bool;                            { if TRUE, read only mode }
           bUniDirectional: Bool;                           { If TRUE, Uni directional }
           var hRefCursor : hDBICur                         { Returns Cursor handle for REF }
         ): DBIResult;
begin
  Result := BtrEng.OpenRef( hCursor, iFieldNo,
    bReadOnly, bUnidirectional, hRefCursor );
end;

Function BtrDatabaseFlush( hDb : hDBIDb ): DBIResult;
begin
  Result := BtrEng.DatabaseFlush( hdb );
end;


Function BtrGetCursorProps (            { Get Cursor properties }
      hCursor       : hDBICur;          { Cursor handle }
var   curProps      : CURProps          { Cursor properties }
   ): DBIResult;
begin
  Result := BtrEng.GetCursorProps( hCursor, curProps );
end;


Function BtrGetObjFromName (            { Get object from name }
      eObjType      : DBIOBJType;       { Object handle }
      pszObjName    : PChar;            { Name of object /NULL }
var   hObj          : hDBIObj           { Returned object handle }
   ): DBIResult;
begin
  Result := BtrEng.GetObjFromName( eObjType, pszObjName, hObj );
end;


Function BtrGetObjFromObj (             { Get associated object }
      hObj          : hDBIObj;          { Object handle }
      eObjType      : DBIOBJType;       { Type of associated object }
var   hObjOut       : hDBIObj           { Returns object of eObjType }
   ): DBIResult;
begin
  Result := BtrEng.GetObjFromObj( hObj, eObjType, hObjOut );
end;


Function BtrGetProp (                   { Get property }
      hObj          : hDBIObj;          { Object handle }
      iProp         : Longint;          { Property to retrieve }
      PropValue     : Pointer;          { == NULL, validate iProp for getting }
      iMaxLen       : Word;             { Length of buffer pPropValue }
var   iLen          : Word              { Returns required length }
   ): DBIResult;
begin
  Result := BtrEng.GetEngProp( hObj, iProp, PropValue, iMaxLen, iLen );
end;


Function BtrSetProp (                   { Set property }
      hObj          : hDBIObj;          { Object handle }
      iProp         : Longint;          { Property to set }
      iPropValue    : Longint           { Property value }
   ): DBIResult;
begin
  Result := BtrEng.SetEngProp( hObj, iProp, iPropValue );
end;


Function BtrValidateProp (              { Validate a property }
      hObj          : hDBIObj;          { Object handle }
      iProp         : Longint;          { property to validate }
      bSetting      : Bool              { TRUE:setting, FALSE:getting }
   ): DBIResult;
begin
  Result := BtrEng.ValidateEngProp( hObj, iProp, bSetting );
end;


Function BtrGetFieldDescs (             { Get field descriptions }
      hCursor       : hDBICur;          { Cursor handle }
      pfldDesc      : pFLDDesc          { Array of field descriptors }
   ): DBIResult;
begin
  Result := BtrEng.GetFieldDescs( hCursor, pfldDesc );
end;


Function BtrGetCursorForTable (         { Find cursor for a given table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type / NULL }
var   hCursor       : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.GetCursorForTable( hDb, pszTableName, pszDriverType, hCursor );
end;


Function BtrCloneCursor (               { Return a duplicate cursor }
      hCurSrc       : hDBICur;          { Source cursor }
      bReadOnly     : Bool;             { If TRUE, read only mode }
      bUniDirectional : Bool;           { If TRUE, Uni directional }
var   hCurNew       : hDBICur           { Destination cursor address }
   ): DBIResult;
begin
  Result := BtrEng.CloneCursor( hCurSrc, bReadOnly, bUniDirectional, hCurNew );
end;


Function BtrCloseCursor (               { Closes cursor }
var   hCursor       : hDBICur           { Pntr to Cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.CloseCursor( hCursor );
end;



{============================================================================}
{                      Index Manipulation & Usage                            }
{============================================================================}

Function BtrOpenIndex (                 { Open an index }
      hCursor       : hDBICur;          { Cursor handle }
      pszIndexName  : PChar;            { Index Name }
      iIndexId      : Word              { Index number (if applicable) }
   ): DBIResult;
begin
  Result := BtrEng.OpenIndex( hCursor, pszIndexName, iIndexId );
end;


Function BtrCloseIndex (                { Close an index }
      hCursor       : hDBICur;          { Cursor handle }
      pszIndexName  : PChar;            { Index Name }
      iIndexId      : Word              { Index number }
   ): DBIResult;
begin
  Result := BtrEng.CloseIndex( hCursor, pszIndexName, iIndexId );
end;


Function BtrSwitchToIndex (             { Change index order of access }
var   hCursor       : hDBICur;          { Cursor handle (In/Out) }
      pszIndexName  : PChar;            { Index name }
      pszTagName    : PChar;            { Tag name (if applicable) }
      iIndexId      : Word;             { Index number }
      bCurrRec      : Bool              { Position at current rec }
   ): DBIResult;
begin
  Result := BtrEng.SwitchToIndex( hCursor, pszIndexName, pszTagName, iIndexId, bCurrRec );
end;


Function BtrGetIndexDesc (              { Get index properties }
      hCursor       : hDBICur;          { Cursor handle }
      iIndexSeqNo   : Word;             { Index number }
var   idxDesc       : IDXDesc           { Returned index description }
   ): DBIResult;
begin
  Result := BtrEng.GetIndexDesc( hCursor, iIndexSeqNo, idxDesc );
end;


Function BtrGetIndexDescs (             { Get index properties }
      hCursor       : hDBICur;          { Cursor handle }
      idxDesc       : PIDXDesc          { Returned index descriptors }
   ): DBIResult;
begin
  Result := BtrEng.GetIndexDescs( hCursor, idxDesc );
end;


Function BtrGetIndexForField (          { Get index desc for given field }
      hCursor       : hDBICur;          { Cursor handle }
      iFld          : Word;             { Field Number (1..N) }
      bProdTagOnly  : Bool;             { If TRUE, only xBASE prod tags will be returned }
var   idxDesc       : IDXDesc           { (Optional) }
   ): DBIResult;
begin
  Result := BtrEng.GetIndexForField( hCursor, iFld, bProdTagOnly, idxDesc );
end;


Function BtrGetIndexSeqNo (             { Get index sequence number }
      hCursor       : hDBICur;          { Cursor handle }
      pszIndexName  : PChar;            { Index name }
      pszTagName    : PChar;            { Tag name (if applicable) }
      iIndexId      : Word;             { Index number }
var   iIndexSeqNo   : Word              { Index number }
   ): DBIResult;
begin
  Result := BtrEng.GetIndexSeqNo( hCursor, pszIndexName, pszTagName,
              iIndexID, iIndexSeqNo );
end;


Function BtrSetToKey (                  { Set key condition }
      hCursor       : hDBICur;          { Cursor handle }
      eSearchCond   : DBISearchCond;    { Search condition (default is =) }
      bDirectKey    : Bool;             { Key is supplied directly }
      iFields       : Word;             { No of full fields to match }
      iLen          : Word;             { Partial key len of last field }
      pBuff         : Pointer           { Either Record buffer or Key itself }
   ): DBIResult;
begin
  Result := BtrEng.SetToKey( hCursor, eSearchCond, bDirectKey, iFields, iLen, pBuff );
end;


Function BtrExtractKey (                { Get the key value of current record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record buffer (optional) }
      pKeyBuf       : Pointer           { Returned. Key bytes. }
   ): DBIResult;
begin
  Result := BtrEng.ExtractKey( hCursor, pRecBuf, pKeyBuf );
end;


Function BtrSetRange (                  { Set cursor to a range }
      hCursor       : hDBICur;          { Cursor }
      bKeyItself    : Bool;             { Whether Key or Record buffer }
      iFields1      : Word;             { Key fields to be mathced in full }
      iLen1         : Word;             { Key length to compare }
      pKey1         : Pointer;          { Top/Left key in Range }
      bKey1Incl     : Bool;             { If Inclusive of Key1 }
      iFields2      : Word;             { Key fields to be mathced in full }
      iLen2         : Word;             { Key length to compare }
      pKey2         : Pointer;          { Bottom/Right key in Range }
      bKey2Incl     : Bool              { If Inclusive of Key2 }
   ): DBIResult;
begin
  Result := BtrEng.SetRange( hCursor, bKeyItself, iFields1, iLen1, pKey1,
              bKey1Incl, iFields2, iLen2, pKey2, bKey2Incl );
end;


Function BtrResetRange (                { Reset range }
      hCursor       : hDBICur           { cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.ResetRange( hCursor );
end;


Function BtrCompareKeys (               { Compare two keys }
      hCursor       : hDBICur;          { Cursor handle }
      pKey1         : Pointer;          { Key buffer 1 to compare }
      pKey2         : Pointer;          { Key buffer 2 (Or NULL) }
      iFields       : Word;             { Fields to compare in full }
      iLen          : Word;             { Partial key to compare }
var   iResult       : SmallInt          { Compare result }
   ): DBIResult;
begin
  Result := BtrEng.CompareKeys( hCursor, pKey1, pKey2, iFields, iLen, iResult );
end;


Function BtrGetRecordForKey (           { Find a record matching key }
      hCursor       : hDBICur;          { Cursor handle }
      bDirectKey    : Bool;             { Key is supplied directly }
      iFields       : Word;             { No of full fields to match }
      iLen          : Word;             { Partial key len of last field }
      pKey          : Pointer;          { Either Record buffer or Key itself }
      pRecBuff      : Pointer           { (Optional) Record buffer }
   ): DBIResult;
begin
  Result := BtrEng.GetRecordForKey( hCursor, bDirectKey, ifields, iLen, pKey, pRecBuff );
end;


{=============================================================================}
{                          Validity check and referential integrity           }
{=============================================================================}

Function BtrGetVchkDesc (               { Get valcheck descriptor }
      hCursor       : hDBICur;          { Cursor handle }
      iValSeqNo     : Word;             { Valcheck sequence number }
      pvalDesc      : pVCHKDesc         { Returned valcheck description }
   ): DBIResult;
begin
  Result := BtrEng.GetVChkDesc( hCursor, iValSeqNo, pvalDesc );
end;


Function BtrGetRintDesc (               { Get referential integrity descriptor }
      hCursor       : hDBICur;          { Cursor handle }
      iRintSeqNo    : Word;             { Rint sequence number }
      printDesc     : pRINTDesc         { Returned rint description }
   ): DBIResult;
begin
  Result := BtrEng.GetRintDesc( hCursor, iRintSeqNo, printDesc );
end;


{=============================================================================}
{                              Cursor Maintenance                             }
{=============================================================================}

Function BtrSetToBegin (                { Reset cursor to beginning }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.SetToBegin( hCursor );
end;



Function BtrSetToEnd (                  { Reset cursor to ending }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.SetToEnd( hCursor );
end;


Function BtrSetToCursor (               { Set cursor to another cursor position }
      hDest         : hDBICur;          { Destination cursor }
      hSrc          : hDBICur           { Source cursor }
   ): DBIResult;
begin
  Result := BtrEng.SetToCursor( hDest, hSrc );
end;


Function BtrGetBookMark (               { Get a book-mark }
      hCur          : hDBICur;          { Cursor }
      pBookMark     : Pointer           { Pointer to Book-Mark }
   ): DBIResult;
begin
  Result := BtrEng.GetBookMark( hCur, pBookMark );
end;


Function BtrSetToBookMark (             { Position to a Book-Mark }
      hCur          : hDBICur;          { Cursor }
      pBookMark     : Pointer           { Pointer to Book-Mark }
   ): DBIResult;
begin
  Result := BtrEng.SetToBookMark( hCur, pBookMark );
end;


Function BtrCompareBookMarks (          { Compare two Book-marks }
      hCur          : hDBICur;          { Cursor }
      pBookMark1    : Pointer;          { Book mark 1 }
      pBookMark2    : Pointer;          { Book mark 2 }
var   CmpBkmkResult : CmpBkmkRslt       { Compare result }
   ): DBIResult;
begin
  Result := BtrEng.CompareBookMarks( hCur, pBookMark1, pBookMark2, CmpBkmkResult );
end;



{============================================================================}
{                      Data Access: Logical Record Level                     }
{============================================================================}

Function BtrGetNextRecord (             { Find/Get the next record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer(client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;
begin
  Result := BtrEng.GetNextRecord( hCursor, eLock, pRecBuff, pRecProps );
end;


Function BtrGetPriorRecord (            { Find/Get the prior record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer (client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;
begin
  Result := BtrEng.GetPriorRecord( hCursor, eLock, pRecBuff, pRecProps )
end;


Function BtrGetRecord (                 { Gets the current record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer(client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;
begin
  Result := BtrEng.GetRecord( hCursor, eLock, pRecBuff, pRecProps )
end;



Function BtrGetRelativeRecord (         { Find/Get a record by record number }
      hCursor       : hDBICur;          { Cursor handle }
      iPosOffset    : Longint;          { offset from current position }
      eLock         : DBILockType;      { Optional lock request }
      pRecBuff      : Pointer;          { Record buffer(client) }
      precProps     : pRECProps         { Optional record properties }
   ): DBIResult;
begin
  Result := BtrEng.GetRelativeRecord( hCursor, iPosOffset, eLock, pRecBuff, pRecProps )
end;


Function BtrInitRecord (                { Initialize record area }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuff      : Pointer           { Record buffer }
   ): DBIResult;
begin
  Result := BtrEng.InitRecord( hCursor, pRecBuff )
end;


Function BtrInsertRecord (              { Inserts a new record }
      hCursor       : hDBICur;          { Cursor handle }
      eLock         : DBILockType;      { Optional lock on this rec }
      pRecBuff      : Pointer           { New Record (client) }
   ): DBIResult;
begin
  Result := BtrEng.InsertRecord( hCursor, eLock, pRecBuff )
end;



Function BtrModifyRecord (              { Updates the current record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Modified record }
      bFreeLock     : Bool              { Free record lock }
   ): DBIResult;
begin
  Result := BtrEng.ModifyRecord( hCursor, pRecBuf, bFreeLock )
end;


Function BtrDeleteRecord (              { Deletes the current record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer           { Copy of deleted record }
   ): DBIResult;
begin
  Result := BtrEng.DeleteRecord( hCursor, pRecBuf )
end;


Function BtrReadBlock (                 { Read a block of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecords      : Longint;          { Number of records to read }
      pBuf          : Pointer           { Buffer }
   ): DBIResult;
begin
  Result := BtrEng.ReadBlock( hCursor, iRecords, pBuf )
end;


Function BtrWriteBlock (                { Write a block of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecords      : Longint;          { Number of records to write/written }
      pBuf          : Pointer           { Buffer }
   ): DBIResult;
begin
  Result := BtrEng.WriteBlock( hCursor, iRecords, pBuf )
end;


Function BtrAppendRecord (              { Inserts a new record }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuff      : Pointer           { New Record (client) }
   ): DBIResult;
begin
  Result := BtrEng.AppendRecord( hCursor, pRecBuff )
end;



Function BtrUndeleteRecord (            { Undeletes the current record }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.UnDeleteRecord( hCursor )
end;



Function BtrGetSeqNo (                  { Get logical record number }
      hCursor       : hDBICur;          { Cursor handle }
var   iSeqNo        : Longint           { Pointer to sequence number }
   ): DBIResult;
begin
  Result := BtrEng.GetSeqNo( hCursor, iSeqNo )
end;


Function BtrSetToSeqNo (                { Position to a logical record number }
      hCursor       : hDBICur;          { Cursor handle }
      iSeqNo        : Longint           { Sequence number }
   ): DBIResult;
begin
  Result := BtrEng.SettoSeqNo( hCursor, iSeqNo )
end;


Function BtrGetRecordCount (            { Get the current number of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecCount     : Longint           { Number of records }
   ): DBIResult;
begin
  Result := BtrEng.GetRecordCount( hCursor, iRecCount )
end;


Function BtrGetExactRecordCount (       { Get the current number of records }
      hCursor       : hDBICur;          { Cursor handle }
var   iRecCount     : Longint           { Number of records }
   ): DBIResult;
begin
  Result := BtrEng.GetExactRecordCount( hCursor, iRecCount )
end;


Function BtrSetToRecordNo (             { Position to Physical Rec# }
      hCursor       : hDBICur;          { Cursor handle }
      iRecNo        : Longint           { Physical record number }
   ): DBIResult;
begin
  Result := BtrEng.SetToRecordNo( hCursor, iRecNo )
end;


Function BtrSaveChanges (               { Flush all buffered changes }
      hCursor       : hDBICur           { Cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.SaveChanges( hCursor )
end;


Function BtrForceReread (               { Force Reread of buffers from Disk }
      hCursor       : hDBICur           { Cursor }
   ): DBIResult;
begin
  Result := BtrEng.ForceReread( hCursor )
end;


Function BtrCheckRefresh: DBIResult;    { Check refresh for session }
begin
  Result := BtrEng.CheckRefresh
end;


Function BtrMakePermanent (             { Make temporary table permanent }
      hCursor       : hDBICur;          { Cursor handle }
      pszName       : PChar;            { Rename temporary table }
      bOverWrite    : Bool              { Overwrite existing file }
   ): DBIResult;
begin
  Result := BtrEng.MakePermanent( hCursor, pszName, bOverWrite )
end;


Function BtrForceRecordReread (         { Force Reread of current record from Server }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuff      : Pointer           { Returned : record buffer }
   ): DBIResult;
begin
  Result := BtrEng.ForceRecordReread( hCursor, pRecBuff );
end;


{============================================================================}
{                            Field Level Access                              }
{============================================================================}

Function BtrGetField (                  { Get Field value }
      hCursor       : hDBICur;          { Cursor }
      iField        : Word;             { Field # (1..n) }
      pRecBuff      : Pointer;          { Record buffer }
      pDest         : Pointer;          { Destination field buffer }
var   bBlank        : Bool              { Returned : is field blank }
   ): DBIResult;
begin
  Result := BtrEng.GetField( hCursor, iField, pRecBuff, pDest, bBlank )
end;


Function BtrPutField (                  { Put a value in the record buffer }
      hCursor       : hDBICur;          { Cursor }
      iField        : Word;             { Field # (1..n) }
      pRecBuff      : Pointer;          { Record buffer }
      pSrc          : Pointer           { Source field buffer }
   ): DBIResult;
begin
  Result := BtrEng.PutField( hCursor, iField, pRecBuff, pSrc )
end;


Function BtrVerifyField (               { Verifies the field value }
      hCursor       : hDBICur;          { Cursor }
      iField        : Word;             { Field # (1..n) }
      pSrc          : Pointer;          { Field Value }
var   bBlank        : Bool              { Field is Blank (Returned) }
   ): DBIResult;
begin
  Result := BtrEng.VerifyField( hCursor, iField, pSrc, bBlank )
end;


Function BtrOpenBlob (                  { Open a blob for access }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number (1..n) }
      eOpenMode     : DBIOpenMode       { Open for Read or RW }
   ): DBIResult;
begin
  Result := BtrEng.OpenBlob( hCursor, precBuf, iField, eOpenMode )
end;


Function BtrGetBlobSize (               { Gets the size of a blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
var   iSize         : Longint           { Blob size in bytes }
   ): DBIResult;
begin
  Result := BtrEng.GetBlobSize( hCursor, precBuf, iField, iSize )
end;


Function BtrGetBlob (                   { Read bytes from blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
      iOffSet       : Longint;          { Starting position   }
      iLen          : Longint;          { No of bytes to be read   }
      pDest         : Pointer;          { Destination }
var   iRead         : Longint           { Actual no of bytes read }
   ): DBIResult;
begin
  Result := BtrEng.GetBlob( hCursor, pRecBuf, iField, iOffset, iLen, pDest, iRead )
end;


Function BtrPutBlob (                   { Write bytes to blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
      iOffSet       : Longint;          { Starting position   }
      iLen          : Longint;          { No of bytes to put   }
      pSrc          : Pointer           { pntr to Source }
   ): DBIResult;
begin
  Result := BtrEng.PutBlob( hCursor, pRecBuf, iField, iOffset, iLen, pSrc )
end;


Function BtrTruncateBlob (              { Reduces the blob size }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word;             { Field number of blob (1..n) }
      iLen          : Longint           { New blob length }
   ): DBIResult;
begin
  Result := BtrEng.TruncateBlob( hCursor, pRecBuf, iField, iLen )
end;


Function BtrFreeBlob (                  { Closes the blob }
      hCursor       : hDBICur;          { Cursor handle }
      pRecBuf       : Pointer;          { Record Buffer }
      iField        : Word              { Field number of blob (0..n) }
   ): DBIResult;
begin
  Result := BtrEng.FreeBlob( hCursor, pRecBuf, iField )
end;


Function BtrGetBlobHeading (            { Get Blob Heading }
      hCursor       : hDBICur;          { Cursor handle }
      iField        : Word;             { Field number of blob (1..n) }
      pRecBuf       : Pointer;          { Record buffer of owner record }
      pDest         : Pointer           { Destination buffer }
   ): DBIResult;
begin
  Result := BtrEng.GetBlobHeading( hCursor, iField, pRecBuf, pDest )
end;


Function BtrSetFieldMap (               { Set a fieldmap }
      hCur          : hDBICur;          { Cursor handle }
      iFields       : Word;             { Number of fields }
      pFldDesc      : pFLDDesc          { Array of field descriptions }
   ): DBIResult;
begin
  Result := BtrEng.SetFieldMap( hCur, iFields, pFldDesc )
end;



{=============================================================================}
{                                TRANSACTIONS                                 }
{=============================================================================}

Function BtrBeginTran (                 { Begin a transaction }
      hDb           : hDBIDb;           { Database handle }
      eXIL          : eXILType;         { Transaction isolation level }
var   hXact         : hDBIXact          { Returned Xact handle }
   ): DBIResult;
begin
  Result := BtrEng.BeginTran( hDb, eXIL, hXact )
end;


Function BtrEndTran (                   { End a transaction }
      hDb           : hDBIDb;           { Database handle }
      hXact         : hDBIXact;         { Xact handle }
      eEnd          : eXEnd             { Xact end type }
   ): DBIResult;
begin
  Result := BtrEng.EndTran( hDb, hXact, eEnd )
end;


Function BtrGetTranInfo (               { Get transaction info }
      hDb           : hDBIDb;           { Database handle }
      hXact         : hDBIXact;         { Xact handle }
      pxInfo        : pXInfo            { Xact info }
   ): DBIResult;
begin
  Result := BtrEng.GetTranInfo( hDb, hXact, pxInfo )
end;


{=============================================================================}
{                                  LOCKING                                    }
{=============================================================================}

Function BtrAcqTableLock (              { Lock a table }
      hCursor       : hDBICur;          { Cursor handle }
      eLockType     : DBILockType       { Lock type }
   ): DBIResult;
begin
  Result := BtrEng.AcqTableLock( hCursor, eLockType )
end;


Function BtrAcqPersistTableLock (       { Get a persistent lock }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar             { Driver type / NULL }
   ): DBIResult;
begin
  Result := BtrEng.AcqPersistTableLock( hDb, pszTableName, pszDriverType );
end;


Function BtrRelPersistTableLock (       { Releases a persistent lock }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar             { Driver type / NULL }
   ): DBIResult;
begin
  Result := BtrEng.RelPersistTableLock( hDb, pszTableName, pszDriverType );
end;


Function BtrRelTableLock (              { Unlocks Table level locks }
      hCursor       : hDBICur;          { Cursor handle }
      bAll          : Bool;             { True for all table level locks }
      eLockType     : DBILockType       { Specific lock type }
   ): DBIResult;
begin
  Result := BtrEng.RelTableLock( hCursor, bAll, eLockType )
end;


Function BtrRelRecordLock (             { Releases record level locks }
      hCursor       : hDBICur;          { Cursor handle }
      bAll          : Bool              { True for all. Default Current. }
   ): DBIResult;
begin
  Result := BtrEng.RelRecordLock( hCursor, bAll )
end;


Function BtrIsRecordLocked (            { Check if current record is locked }
      hCursor       : hDBICur;          { Cursor handle }
var   bLocked       : Bool              { Rec lock status }
   ): DBIResult;
begin
  Result := BtrEng.IsRecordLocked( hCursor, bLocked )
end;


Function BtrIsTableLocked (             { Verify if Table is locked }
      hCursor       : hDBICur;          { Cursor handle }
      epdxLock      : DBILockType;      { Lock type to verify }
var   iLocks        : Word              { Nbr of locks of the given type }
   ): DBIResult;
begin
  Result := BtrEng.IsTableLocked( hCursor, epdxLock, iLocks );
end;


Function BtrIsTableShared (             { Verify if this is a shared table }
      hCursor       : hDBICur;          { Cursor handle }
var   bShared       : Bool              { Shared status }
   ): DBIResult;
begin
  Result := BtrEng.IsTableShared( hCursor, bShared );
end;


Function BtrOpenLockList (              { Get a list of locks }
      hCursor       : hDBICur;          { Cursor handle }
      bAllUsers     : Bool;             { True, for all Users locks }
      bAllLockTypes : Bool;             { True, for all lock types }
var   hLocks        : hDBICur           { Returned cursor on Lock list }
   ): DBIResult;
begin
  Result := BtrEng.OpenLockList( hCursor, bAllUsers, bAllLockTypes, hLocks );
end;


Function BtrOpenUserList (              { Get a list of users loggedin }
var   hUsers        : hDBICur           { Returned cursor on user list }
   ): DBIResult;
begin
  Result := BtrEng.OpenUserList( hUsers );
end;


Function BtrSetLockRetry (              { Set Lock wait time }
      iWait         : SmallInt          { Time in seconds }
   ): DBIResult;
begin
  Result := BtrEng.SetLockRetry( iWait );
end;



{============================================================================}
{                              Batch Operations                              }
{============================================================================}


Function BtrBatchMove (                 { Copy records to destination table }
      pSrcTblDesc   : pBATTblDesc;      { Source table identification, }
      hSrcCur       : hDBICur;          {  OR source cursor  ( one must be NULL ) }
      pDstTblDesc   : pBATTblDesc;      { Destination table identification, }
      hDstCur       : hDBICur;          {  OR destination cursor ( one must be NULL ) }
      ebatMode      : eBATMode;         { Batch mode }
      iFldCount     : Word;             { size of field maps }
      pSrcFldMap    : PWord;            { Array of source field numbers }
      pszIndexName  : PChar;            { If update mode, used to match records }
      pszIndexTagName : PChar;          { Index tag name }
      iIndexId      : Word;             { Index  id }
      pszKeyviolName : PChar;           { Keyviol table name  (optional) }
      pszProblemsName : PChar;          { Problems table name (optional) }
      pszChangedName : PChar;           { Changed table name (optional) }
      lProbRecs     : PLongint;         { Number of records to read from source }
      lKeyvRecs     : PLongint;         { Number of records to read from source }
      lChangedRecs  : PLongint;         { Number of records to read from source }
      bAbortOnFirstProb : Bool;         { If TRUE, abort on first problem rec }
      bAbortOnFirstKeyviol : Bool;      { If TRUE, abort on first keyviol rec }
var   lRecsToMove   : Longint;          { Number of records to read from source }
      bTransliterate : Bool             { If TRUE, transliterate character data }
   ): DBIResult;
begin
  Result := BtrEng.BatchMove(
              pSrcTblDesc,              { Source table identification, }
              hSrcCur,                  {  OR source cursor  ( one must be NULL ) }
              pDstTblDesc,              { Destination table identification, }
              hDstCur,                  {  OR destination cursor ( one must be NULL ) }
              ebatMode,                 { Batch mode }
              iFldCount,                { size of field maps }
              pSrcFldMap,               { Array of source field numbers }
              pszIndexName,             { If update mode, used to match records }
              pszIndexTagName,          { Index tag name }
              iIndexId,                 { Index  id }
              pszKeyviolName,           { Keyviol table name  (optional) }
              pszProblemsName,          { Problems table name (optional) }
              pszChangedName,           { Changed table name (optional) }
              lProbRecs,                { Number of records to read from source }
              lKeyvRecs,                { Number of records to read from source }
              lChangedRecs,             { Number of records to read from source }
              bAbortOnFirstProb,        { If TRUE, abort on first problem rec }
              bAbortOnFirstKeyviol,     { If TRUE, abort on first keyviol rec }
              lRecsToMove,              { Number of records to read from source }
              bTransliterate            { If TRUE, transliterate character data }
            );
end;


Function BtrCopyTable (                 { Copy one table to another }
      hDb           : hDBIDb;           { Database handle }
      bOverWrite    : Bool;             { True, to overwrite existing file }
      pszSrcTableName : PChar;          { Source table name }
      pszSrcDriverType : PChar;         { Source driver type }
      pszDestTableName : PChar          { Destination table name }
   ): DBIResult;
begin
  Result := BtrEng.CopyTable( hDb, bOverWrite, pszSrcTableName, pszSrcDriverType,
              pszDestTableName );
end;


Function BtrEmptyTable (                { Deletes all records }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar             { Driver type /NULL }
   ): DBIResult;
begin
  Result := BtrEng.EmptyTable( hDb, hCursor, pszTableName, pszDriverType );
end;


Function BtrPackTable (                 { Pack a table }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      bRegenIdxs    : Bool              { Regenerate indexes }
   ): DBIResult;
begin
  Result := BtrEng.PackTable( hDb, hCursor, pszTableName, pszDriverType, bRegenIdxs );
end;


Function BtrRegenIndex (                { Regenerate an index }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszIndexName  : PChar;            { Index name }
      pszIndexTagName : PChar;          { Index tagname (xbase MDX) }
      iIndexId      : Word              { Index number }
   ): DBIResult;
begin
  Result := BtrEng.RegenIndex( hDb, hCursor, pszTableName, pszDriverType,
              pszIndexName, pszIndexTagName, iIndexId );
end;


Function BtrRegenIndexes (              { Regenerate all indexes }
      hCursor       : hDBICur           { Cursor }
   ): DBIResult;
begin
  Result := BtrEng.RegenIndexes( hCursor );
end;


Function BtrSortTable (                 { Sort table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name of source }
      pszDriverType : PChar;            { Driver type /NULL }
      hSrcCur       : hDBICur;          { OR cursor of table to sort }
      pszSortedName : PChar;            { Destination table (NULL if sort to self) }
      phSortedCur   : phDBICur;         { If non-null, return cursor on destination }
      hDstCur       : hDBICur;          { OR cursor of destination }
      iSortFields   : Word;             { Number of sort fields }
      piFieldNum    : PWord;            { Array of field numbers }
      pbCaseInsensitive : PBool;        { Which fields should sort c-i (Opt) }
      pSortOrder    : pSORTOrder;       { Array of Sort orders (Opt) }
      ppfSortFn     : ppfSORTCompFn;    { Array of compare fn pntrs (Opt) }
      bRemoveDups   : Bool;             { TRUE : Remove duplicates }
      hDuplicatesCur : hDBICur;         { Cursor to duplicates table (Opt) }
var   lRecsSort     : Longint           { in/out param. - sort this number }
   ): DBIResult;
begin
  Result := BtrEng.SortTable(
              hDb,                      { Database handle }
              pszTableName,             { Table name of source }
              pszDriverType,            { Driver type /NULL }
              hSrcCur,                  { OR cursor of table to sort }
              pszSortedName,            { Destination table (NULL if sort to self) }
              phSortedCur,              { If non-null, return cursor on destination }
              hDstCur,                  { OR cursor of destination }
              iSortFields,              { Number of sort fields }
              piFieldNum,               { Array of field numbers }
              pbCaseInsensitive,        { Which fields should sort c-i (Opt) }
              pSortOrder,               { Array of Sort orders (Opt) }
              ppfSortFn,                { Array of compare fn pntrs (Opt) }
              bRemoveDups,              { TRUE : Remove duplicates }
              hDuplicatesCur,           { Cursor to duplicates table (Opt) }
              lRecsSort                 { in/out param. - sort this number }
            );
end;



{============================================================================}
{                           Create & Restructure                             }
{============================================================================}

Function BtrCreateTable (               { Create a new table }
      hDb           : hDBIDb;           { Database handle }
      bOverWrite    : Bool;             { True, to overwrite existing file. }
var   crTblDsc      : CRTblDesc         { Table description }
   ): DBIResult;
begin
  Result := BtrEng.CreateTable( hDb, bOverWrite, crTblDsc );
end;


Function BtrCreateInMemTable (          { Create a temporary table (Logical) }
      hDb           : hDBIDb;           { Database handle }
      pszName       : PChar;            { Logical Name }
      iFields       : Word;             { No of fields }
      pfldDesc      : pFLDDesc;         { Array of field descriptors }
var   hCursor       : hDBICur           { Returned cursor handle }
   ): DBIResult;
begin
  Result := BtrEng.CreateInMemTable( hDb, pszName, iFields, pFldDesc, hCursor );
end;


Function BtrCreateTempTable (           { Create temporary table (Physical) }
      hDb           : hDBIDb;           { Database handle }
var   crTblDsc      : CRTblDesc;        { Table description }
var   hCursor       : hDBICur           { Returned cursor on table }
   ): DBIResult;
begin
  Result := BtrEng.CreateTempTable( hDb, crTblDsc, hCursor );
end;


Function BtrDoRestructure (             { Restructure a table }
      hDb           : hDBIDb;           { Database handle }
      iTblDescCount : Word;             { Number of table descriptors (1) }
      pTblDesc      : pCRTblDesc;       { Array of table descs }
      pszSaveAs     : PChar;            { Restructure to this table }
      pszKeyviolName : PChar;           { Keyviol table name  (optional) }
      pszProblemsName : PChar;          { Problems table name (optional) }
      bAnalyzeOnly  : Bool              { Analyze restructure }
   ): DBIResult;
begin
  Result := BtrEng.DoRestructure( hDb, iTblDescCount, pTblDesc, pszSaveAs,
              pszKeyviolName, pszProblemsName, bAnalyzeOnly );
end;


Function BtrRenameTable (               { Rename table & family }
      hDb           : hDBIDb;           { Database handle }
      pszOldName    : PChar;            { Old name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszNewName    : PChar             { New name }
   ): DBIResult;
begin
  Result := BtrEng.RenameTable( hDb, pszOldName, pszDriverType, pszNewName );
end;


Function BtrDeleteTable (               { Delete a table }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Name including any path }
      pszDriverType : PChar             { Driver type /NULL }
   ): DBIResult;
begin
  Result := BtrEng.DeleteTable( hDb, pszTableName, pszDriverType );
end;


Function BtrAddIndex (                  { Add a new index }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name including any path }
      pszDriverType : PChar;            { Driver type /NULL }
var   IdxDesc       : IDXDesc;          { Description of the index }
      pszKeyviolName : PChar            { Keyviol table name (optional) }
   ): DBIResult;
begin
  Result := BtrEng.AddIndex( hDb, hCursor, pszTableName, pszDriverType,
              idxDesc, pszKeyViolName );
end;


Function BtrDeleteIndex (               { Delete index }
      hDb           : hDBIDb;           { Database handle }
      hCursor       : hDBICur;          { Cursor (OR) }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszIndexName  : PChar;            { Index name }
      pszIndexTagName : PChar;          { Index tagname (xbase MDX) }
      iIndexId      : Word              { Index number }
   ): DBIResult;
begin
  Result := BtrEng.DeleteIndex( hDb, hCursor, pszTableName, pszDriverType,
              pszIndexName, pszIndexTagName, iIndexId );
end;


{===========================================================================}
{                            Error Info                                     }
{===========================================================================}

Function BtrGetErrorEntry (             { Get error entry }
      uEntry        : Word;             { Error stack entry }
var   ulNativeError : Longint;          { Returned. Native error code, if any }
      pszError      : PChar             { Returned. Error string, if any }
   ): DBIResult;
begin
  Result := BtrEng.GetErrorEntry( uEntry, ulNativeError, pszError );
end;


Function BtrGetErrorInfo (              { Return info on last error }
      bFull         : Bool;             { If Full details }
var   ErrInfo       : DBIErrInfo        { Error Info }
   ): DBIResult;
begin
  Result := BtrEng.GetErrorInfo( bFull, ErrInfo )
end;


Function BtrGetErrorString (            { Get message for error code }
      rslt          : DBIResult;        { Engine error code }
      pszError      : PChar             { Error string for the error }
   ): DBIResult;
begin
  Result := BtrEng.GetErrorString( rslt, pszError )
end;


Function BtrGetErrorContext (           { Get specific Context if available }
      eContext      : SmallInt;         { Context type }
      pszContext    : PChar             { Context string (MAXMSGLEN +1) }
   ): DBIResult;
begin
  Result := BtrEng.GetErrorContext( eContext, pszContext );
end;


{============================================================================}
{                              Dbi Services                                  }
{============================================================================}

Function BtrDateEncode (                { Encode Date components into Date }
      iMon          : Word;             { Month    (1..12) }
      iDay          : Word;             { Day      (1..31) }
      iYear         : SmallInt;         { Year     (0..2**16-1) }
var   dateD         : DBIDate           { Encoded date }
   ): DBIResult;
begin
  Result := BtrEng.DateEncode( iMon, iDay, iYear, dateD )
end;


Function BtrDateDecode (                { Decode Date into components }
      dateD         : DBIDate;          { Encoded Date }
var   iMon          : Word;             { Month }
var   iDay          : Word;             { Day }
var   iYear         : SmallInt          { Year }
   ): DBIResult;
begin
  Result := BtrEng.DateDecode( dateD, iMon, iDay, iYear )
end;


Function BtrTimeEncode (                { Encode Time components into TIME }
      iHour         : Word;             { Hours (0..23) }
      iMin          : Word;             { Minutes (0..59) }
      iMilSec       : Word;             { Milli Seconds (0..59999) }
var   timeT         : Time              { Encoded Time }
   ): DBIResult;
begin
  Result := BtrEng.TimeEncode( iHour, iMin, iMilSec, timeT )
end;


Function BtrTimeDecode (                { Decode TIME into components }
      timeT         : Time;             { Encoded Time }
var   iHour         : Word;             { Hours (0..23) }
var   iMin          : Word;             { Minutes (0..59) }
var   iMilSec       : Word              { Milli Seconds (0..59999) }
   ): DBIResult;
begin
  Result := BtrEng.TimeDecode( timeT, iHour, iMin, iMilSec )
end;


Function BtrTimeStampEncode (           { Encode Date & TIme into Date+Time }
      dateD         : DBIDate;          { Encoded Date }
      timeT         : Time;             { Encoded Time }
var   tsTS          : TimeStamp         { Encoded Date+Time }
   ): DBIResult;
begin
  Result := BtrEng.TimeStampEncode( dateD, timeT, tsTS );
end;


Function BtrTimeStampDecode (           { Decode Date & Time from Date+Time }
      tsTS          : TIMESTAMP;        { Encoded Date+Time }
var   dateD         : DBIDate;          { Encoded Date }
var   timeT         : Time              { Encoded Time }
   ): DBIResult;
begin
  Result := BtrEng.TimeStampDecode( tsTS, dateD, timeT );
end;



Function BtrBcdFromFloat (              { Converts FLOAT number into FMTBcd format }
var   iVal          : Double;           { Float to convert }
      iPrecision    : Word;             { Precision of BCD }
      iPlaces       : Word;             { Number of decimals }
var   Bcd           : FMTBcd            { returns Bcd number (length = iPrecision +2) }
   ): DBIResult;
begin
  Result := BtrEng.BCDFromFloat( iVal, iPrecision, iPlaces, Bcd )
end;


Function BtrBcdToFloat (                { Converts FMTBcd number to FLOAT }
var   Bcd           : FMTBcd;           { Bcd number to convert }
var   iVal          : Double            { Returns converted float }
   ): DBIResult;
begin
  Result := BtrEng.BCDToFloat( Bcd, iVal );
end;


{===========================================================================}
{                           CallBacks                                       }
{===========================================================================}

Function BtrRegisterCallBack (          { Register a call back fn }
      hCursor       : hDBICur;          { Cursor (Optional) }
      ecbType       : CBType;           { Type of call back }
      iClientData   : Longint;          { Pass-thru client data }
      iCbBufLen     : Word;             { Callback buffer len }
      CbBuf         : Pointer;          { Pointer to callback buffer }
      pfCb          : pfDBICallBack     { Call back fn being registered }
   ): DBIResult;
begin
  Result := BtrEng.RegisterCallBack( hCursor, ecbType, iClientData, iCbBufLen,
              CbBuf, pfCb );
end;


Function BtrGetCallBack (               { Register a call back fn }
      hCursor       : hDBICur;          { Cursor (Optional) }
      ecbType       : CBType;           { Type of call back }
      piClientData  : PLongint;         { Pass-thru client data }
      piCbBufLen    : PWord;            { Callback buffer len }
      ppCbBuf       : Pointer;          { Pointer to callback buffer }
var   pfCb          : pfDBICallBack     { Call back fn being registered }
   ): DBIResult;
begin
  Result := BtrEng.GetCallBack( hCursor, ecbType, piClientData, piCbBufLen, ppCbBuf, pfCb );
end;


{============================================================================}
{                       	 Date, time formats                          }
{============================================================================}


Function BtrGetDateFormat (             { Get current date format }
var   fmtDate       : FMTDate
   ): DBIResult;
begin
  fmtDate := BtrEng.DateFormat;
  Result  := DBIERR_NONE;
end;


Function BtrSetDateFormat (             { Set current date format }
var   fmtDate       : FMTDate
   ): DBIResult;
begin
  BtrEng.DateFormat := fmtDate;
  Result := DBIERR_NONE;
end;


Function BtrGetTimeFormat (             { Get current time format }
var   fmtTime       : FMTTime
   ): DBIResult;
begin
  fmtTime := BtrEng.TimeFormat;
  Result  := DBIERR_NONE;
end;


Function BtrSetTimeFormat (             { Set current time format }
var   fmtTime       : FMTTime
   ): DBIResult;
begin
  BtrEng.TimeFormat := fmtTime;
  Result  := DBIERR_NONE;
end;


Function BtrGetNumberFormat (           { Get current number format }
var   fmtNumber     : FMTNumber
   ): DBIResult;
begin
  Result := BtrEng.GetNumberFormat( fmtNumber );
end;


Function BtrSetNumberFormat (           { Set current number format }
var   fmtNumber     : FMTNumber
   ): DBIResult;
begin
  Result := BtrEng.SetNumberFormat( fmtNumber );
end;


{============================================================================}
{                      Conversions                                           }
{============================================================================}

Function BtrNativeToAnsi (              { Convert from native to Ansi }
      LdObj         : Pointer;          { Language driver }
      pAnsiStr      : PChar;            { Destination buffer (opt) }
      pNativeStr    : PChar;            { Source buffer }
      iLen          : Longint;          { Length of buffer (opt) }
var   bDataLoss     : Bool              { Returns TRUE if conversion will loose data (opt) }
   ): DBIResult;
begin
  Result := BtrEng.NativeToAnsi( LdObj, pAnsiStr, pNativeStr, iLen, bDataLoss )
end;


Function BtrAnsiToNative (              { Convert from Ansi to native }
      LdObj         : Pointer;          { Language driver }
      pNativeStr    : PChar;            { Destination buffer (opt) }
      pAnsiStr      : PChar;            { Source buffer }
      iLen          : Longint;          { Length of buffer (opt) }
var   bDataLoss     : Bool              { Returns TRUE if conversion will loose data (opt) }
   ): DBIResult;
begin
  Result := BtrEng.AnsiToNative( LdObj, pNativeStr, pAnsiStr, iLen, bDataLoss );
end;


{============================================================================}
{                            Filters                                         }
{============================================================================}

Function BtrAddFilter (                 { Add a filter to the cursor }
      hCursor       : hDBICur;          { Cursor handle }
      iClientData   : Longint;          { Client supplied data      (opt) }
      iPriority     : Word;             { 1..N with 1 being highest (opt) }
      bCanAbort     : Bool;             { TRUE if pfFiltercan return ABORT (opt) }
      pcanExpr      : pCANExpr;         { Expression tree        (opt) }
      pfFilter      : pfGENFilter;      { ptr to filter function (opt) }
var   hFilter       : hDBIFilter        { Returns filter handle }
   ): DBIResult;
begin
  Result := BtrEng.AddFilter( hCursor, iClientData, iPriority, bCanAbort,
              pcanExpr, pfFilter, hFilter );
end;


Function BtrDropFilter (                { Drop a filter }
      hCursor       : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter        { Filter handle }
   ): DBIResult;
begin
  Result := BtrEng.DropFilter( hCursor, hFilter );
end;


Function BtrActivateFilter (            { Activate a Filter }
      hCursor       : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter        { Filter handle }
   ): DBIResult;
begin
  Result := BtrEng.ActivateFilter( hCursor, hFilter );
end;


Function BtrDeactivateFilter (          { Deactivate Filter }
      hCursor       : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter        { Filter handle }
   ): DBIResult;
begin
  Result := BtrEng.DeactivateFilter( hCursor, hFilter );
end;


Function BtrGetFilterInfo (             { Get filter information }
      hCur          : hDBICur;          { Cursor handle }
      hFilter       : hDBIFilter;       { Filter handle          /NULL }
      iFilterId     : Word;             { Filter id              /0 }
      iFilterSeqNo  : Word;             { Filter sequence number /0 }
var   Filterinfo    : FilterInfo        { Returns filter info }
   ): DBIResult;
begin
  Result := BtrEng.GetFilterInfo( hCur, hFilter, iFilterId, iFilterSeqNo, FilterInfo );
end;


{============================================================================}
{                            Linked Cursors                                  }
{============================================================================}
Function BtrBeginLinkMode (             { Convert cursor to a link cursor }
var   hCursor       : hDBICur           { In/Out : returns new cursor }
   ): DBIResult;
begin
  Result := BtrEng.BeginLinkMode( hCursor );
end;


Function BtrEndLinkMode (               { Convert cursor back to normal cursor }
var   hCursor       : hDBICur           { In/Out : returns original cursor }
   ): DBIResult;
begin
  Result := BtrEng.EndLinkMode( hCursor );
end;


Function BtrLinkDetail (                { Link detail to master }
      hMstrCursor   : hDBICur;          { Master cursor }
      hDetlCursor   : hDBICur;          { Detail cursor }
      iLnkFields    : Word;             { Number of link fields }
      piMstrFields  : PWord;            { Array of fields in master }
      piDetlFields  : PWord             { Array of fields in detail }
   ): DBIResult;
begin
  Result := BtrEng.LinkDetail( hMstrCursor, hDetlCursor, iLnkFields,
              piMstrFields, piDetlFields );
end;


Function BtrLinkDetailToExp (           { Link detail to a master using exp }
      hCursorMstr   : hDBICur;          { Master cursor }
      hCursorDetl   : hDBICur;          { Detail cursor }
      iKeyLen       : Word;             { Key length to match }
      pszMstrExp    : PChar             { Expression string }
   ): DBIResult;
begin
  Result := BtrEng.LinkDetailtoExp( hCursorMstr, hCursorDetl, iKeyLen, pszMstrExp );
end;


Function BtrUnlinkDetail (              { Unlink detail from master }
      hDetlCursor   : hDBICur           { Detail cursor to unlink }
   ): DBIResult;
begin
  Result := BtrEng.UnLinkDetail( hDetlCursor );
end;


Function BtrGetLinkStatus (             { Query linkage info for table }
      hCursor       : hDBICur;          { Cursor handle }
var   hCursorMstr   : hDBICur;          { Returns master cursor, if any   (opt) }
var   hCursorDet    : hDBICur;          { Returns first detail cursor, if any (opt) }
var   hCursorSib    : hDBICur           { Returns next sibling detail cursor, if any (opt) }
   ): DBIResult;
begin
  Result := BtrEng.GetLinkStatus( hCursor, hCursorMstr, hCursorDet, hCursorSib );
end;



{===========================================================================}
{                            Translation                                    }
{===========================================================================}

Function BtrTranslateRecordStructure (  { Translate a record }
      pszSrcDriverType : PChar;         { Source driver type }
      iFlds         : Word;             { Number of fields }
      pfldsSrc      : pFLDDesc;         { Array of source fields: logical or physical types }
      pszDstDriverType : PChar;         { Destination driver type }
      pszLangDriver : PChar;            { Language driver for destination }
      pfldsDst      : pFLDDesc;         { Array of dest. fields returned }
      bCreatable    : Bool              { TRUE -> map to creatable fields only. }
   ): DBIResult;
begin
  Result := BtrEng.TranslateRecordStructure( pszSrcDriverType, iFlds, pFldsSrc,
              pszDstDriverType, pszLangDriver, pFldsDst, bCreatable );
end;


Function BtrOpenFieldXlt (              { Open translation object }
      pszSrcTblType : PChar;            { NULL for Logical }
      pszSrcLangDrv : PChar;            { NULL if no tranliteration }
      pfldSrc       : pFLDDesc;         { source field descriptor }
      pszDestTblType : PChar;           { NULL for Logical }
      pszDstLangDrv : PChar;            { NULL if no tranliteration }
      pfldDest      : pFLDDesc;         { Source field descriptor }
var   bDataLoss     : Bool;             { Set to TRUE, for data loss }
var   hXlt          : hDBIXlt           { Returned translate handle }
   ): DBIResult;
begin
  Result := BtrEng.OpenFieldXlt( pszSrcTblType, pszSrcLangDrv, pfldSrc,
              pszDestTblType, pszDstLangDrv, pfldDest, bDataLoss, hXlt );
end;


Function BtrTranslateField (            { Translate a field }
      hXlt          : hDBIXlt;          { Translation handle }
      pSrc          : Pointer;          { Source field }
      pDest         : Pointer           { Destination field }
   ): DBIResult;
begin
  Result := BtrEng.TranslateField( hXLt, pSrc, pDest );
end;


Function BtrCloseFieldXlt (             { Close translation object }
      hXlt          : hDBIXlt           { Translation handle }
   ): DBIResult;
begin
  Result := BtrEng.CloseFieldXlt( hXlt );
end;



{=========================================================================}
{    Delayed Updates                                                      }
{=========================================================================}

Function BtrBeginDelayedUpdates (       { put cursor in delayed update mode }
var   hCursor       : hDBICur           { In/Out : returns new Cursor }
   ): DBIResult;
begin
  Result := BtrEng.BeginDelayedUpdates( hCursor );
end;


Function BtrEndDelayedUpdates (         { Convert cursor back to normal cursor }
var   hCursor       : hDBICur           { In/Out : returns original Cursor }
   ): DBIResult;
begin
  Result := BtrEng.EndDelayedUpdates( hCursor );
end;


Function BtrApplyDelayedUpdates (       { Perform the specified operation. }
      hCursor       : hDBICur;          { Delayed update cursor handle }
      eUpdCmd       : DBIDelayedUpdCmd  { Op Type: Commit or Rollback. }
   ): DBIResult;
begin
  Result := BtrEng.ApplyDelayedUpdates( hCursor, eUpdCmd );
end;


{ Dbi function to get a cursor on the updates cache. }

Function BtrGetDelayedUpdates (
      hCursor       : hDBICur;          { Delayed update cursor handle }
var   hCache        : hDBICur           { In/Out: returns cursor on cache }
   ): DBIResult;
begin
  Result := BtrEng.GetDelayedUpdates( hCursor, hCache );
end;


{===========================================================================}
{                                 MISC.                                     }
{===========================================================================}


Function BtrGetTableOpenCount (         {  Get local cursor count }
      hDb           : hDBIDb;           { Database }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
var   iOpenCount    : Word              { returned number of cursors }
   ): DBIResult;
begin
  Result := BtrEng.GetTableOpenCount( hDb, pszTableName, pszDriverType, iOpenCount )
end;


Function BtrUseIdleTime: DBIResult;     { Use Idle time }
begin
  Result := BtrEng.UseIdleTime;
end;


Function BtrGetLdObj (                  { Get language driver }
      hCursor       : hDBICur;          { Cursor handle }
var   pLdObj        : Pointer           { Returned language driver object }
   ): DBIResult;
begin
  Result := BtrEng.GetLdObj( hCursor, pLdObj )
end;


Function BtrGetLdName (                 { Get language driver name from table }
      pszDriver     : PChar;            { Driver name }
      pObjName      : PChar;            { Name of object, i.e. table name }
      pLdName       : PChar             { Returned language driver name }
   ): DBIResult;
begin
  Result  := BtrEng.GetLdName( pszDriver, pObjName, pLdName );
end;


Function BtrFormFullName (              { Form Full Name }
      hDb           : hDBIDb;           { Database handle }
      pszTableName  : PChar;            { Table name }
      pszDriverType : PChar;            { Driver type /NULL }
      pszFullName   : PChar             { Returns full name }
   ): DBIResult;
begin
  Result := BtrEng.FormFullName( hDb, pszTableName, pszDriverType, pszFullName );
end;


Function BtrAddPassword (               { Add a password to current session }
      pszPassword   : PChar             { Password }
   ): DBIResult;
begin
  Result := BtrEng.AddPassword( pszPassword )
end;


Function BtrDropPassword (              { Drop a password from current session }
      pszPassword   : PChar             { password/NULL }
   ): DBIResult;
begin
  Result := BtrEng.DropPassword( pszPassword )
end;


Function BtrGetNetUserName (            { Get network username }
      pszNetUserName : PChar            { Returns username }
   ): DBIResult;
begin
  Result := BtrEng.GetNetUserName( pszNetUserName );
end;



Function BtrDebugLayerOptions (         { Get SDK debug layer options }
      iOption       : Word;             { Option }
      pDebugFile    : PChar
   ): DBIResult;
begin
  Result := BtrEng.DebugLayerOptions( iOption, pDebugFile );
end;


Function BtrOpenCfgInfoList (           { Open a cursor on "Config" }
      hCfg          : hDBICfg;          { NULL }
      eOpenMode     : DBIOpenMode;      { ReadWrite or readonly }
      eConfigMode   : CFGMode;          { Config mode }
      pszCfgPath    : PChar;            { Path }
var   hCur          : hDBICur           { Returned cursor }
   ): DBIResult;
begin
  Result := BtrEng.OpenCfgInfoList( hCfg, eOpenMode, eConfigMode, pszCfgPath, hCur )
end;


Function BtrImportODBC(                 { Import current ODBC drivers and data sources }
      hCfg          : hDBICfg;          { NULL }
      bPersist      : Bool              { Persistent or session relative }
   ): DBIResult;
begin
  Result := BtrEng.ImportODBC( hCfg, bPersist );
end;

Function BtrAddAlias (                  { Add a new alias }
      hCfg          : hDBICfg;          { NULL }
      pszAliasName  : PChar;            { Alias name }
      pszDriverType : PChar;            { Driver type for alias }
      pszParams     : PChar;            { Optional parameters }
      bPersist      : Bool              { Persistent or session relative }
   ): DBIResult;
begin
  Result := BtrEng.AddAlias( hCfg, pszAliasName, pszDriverType, pszParams, bPersist );
end;


Function BtrDeleteAlias (               { Add a new alias }
      hCfg          : hDBICfg;          { NULL }
      pszAliasName  : PChar             { Alias name }
   ): DBIResult;
begin
  Result := BtrEng.DeleteAlias( hCfg, pszAliasName );
end;


Function BtrAddDriver(                  { Add a new driver }
      hCfg          : hDBICfg;          { NULL }
      pszDriverName : PChar;            { Driver name }
      pszParams     : PChar;            { Optional parameters }
      bPersist      : Bool              { Persistent or session relative }
   ): DBIResult;
begin
  Result := BtrEng.AddDriver( hCfg, pszDriverName, pszParams, bPersist );
end;

Function BtrDeleteDriver(               { Delete a driver }
      hCfg          : hDBICfg;          { NULL }
      pszDriverName : PChar;            { Driver name }
      bSave         : Bool              { Save config file }
   ): DBIResult;
begin
  Result := BtrEng.DeleteDriver( hCfg, pszDriverName, bSave );
end;


Function BtrOpenConfigFile (            { Open/Create configuration }
      pszDirPath    : PChar;            { Directory }
      bCreate       : Bool;             { TRUE to create/overwrite }
var   hCfg          : hDBICfg           { Handle to config }
   ): DBIResult;
begin
  Result := BtrEng.OpenConfigFile( pszDirPath, bCreate, hCfg );
end;


Function BtrCloseConfigFile (           { Close the config file }
var   hCfg          : hDBICfg;          { Handle }
      bSave         : Bool;             { To save the changes }
      bDefault      : Bool;             { To make this file the default }
      bSaveAs16     : Bool              { To save as a 16-bit config file }
   ): DBIResult;
begin
  Result := BtrEng.CloseConfigFile( hCfg, bSave, bDefault, bSaveAs16 );
end;


Function BtrCfgSave (                   { Save current configuration }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszNewFile    : PChar;            { (Optional): Save as this file }
      bSaveAs16     : Bool              { To save as a 16-bit config file }
   ): DBIResult;
begin
  Result := BtrEng.CfgSave( hCfg, pszNewFile, bSaveAs16 );
end;


Function BtrCfgBuildPath (              { Build a path for accessing config. }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCategory   : PChar;            { NULL for root }
      pszGroup      : PChar;            { NULL for no group }
      pszSection    : PChar;            { NULL fro no section }
      pszCfgPath    : PChar             { Returned path }
   ): DBIResult;
begin
  Result := BtrEng.CfgBuildPath( hCfg, pszCategory, pszGroup, pszSection, pszCfgPath );
end;



Function BtrCfgPosition (               { Position the config path }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar             { Path }
   ): DBIResult;
begin
  Result := BtrEng.CfgPosition( hCfg, pszCfgPath );
end;


Function BtrCfgGetNextNode (            { Get next defined node }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszNodeName   : PChar             { Node name (Returned) }
   ): DBIResult;
begin
  Result := BtrEng.CfgGetNextNode( hCfg, pszNodeName );
end;


Function BtrCfgGetRecord (              { Get a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar;            { Path }
var   iFields       : Word;             { Returned nbr of fields }
      pfldDesc      : pFLDDesc;         { Field descriptors }
      pRec          : Pointer           { Field values }
   ): DBIResult;
begin
  Result := BtrEng.CfgGetRecord( hCfg, pszCfgPath, iFields, pfldDesc, pRec );
end;


Function BtrCfgAddRecord (              { Add a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar;            { Path }
      iFields       : Word;             { No of fields }
      pfldDesc      : pFLDDesc;         { Field descriptors }
      pRec          : Pointer           { Data values }
   ): DBIResult;
begin
  Result := BtrEng.CfgAddRecord( hCfg, pszCfgPath, iFields, pfldDesc, pRec );
end;


Function BtrCfgModifyRecord (           { Modify a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar;            { Path }
      iFields       : Word;             { Nbr of fields }
      pfldDesc      : pFLDDesc;         { Field descriptors }
      pRec          : Pointer           { Data values }
   ): DBIResult;
begin
  Result := BtrEng.CfgModifyRecord( hCfg, pszCfgPath, iFields, pfldDesc, pRec );
end;


Function BtrCfgDropRecord (             { Delete a record }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszCfgPath    : PChar             { Path }
   ): DBIResult;
begin
  Result := BtrEng.CfgDropRecord( hCfg, pszCfgPath );
end;


Function BtrCfgTranslate (              { Translate configuration string }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszConfigPath : PChar;            { configuration path }
      pszTrans      : PChar;            { translated path }
      iFields       : Word;             { number of fields, 0 if path only }
      pfldDesc      : pFLDDesc;         { field descriptors, NULL if path only }
      pRec          : Pointer           { record buffer, NULL if path only }
   ): DBIResult;
begin
  Result := BtrEng.CfgTranslate( hCfg, pszConfigPath, pszTrans, iFields, pfldDesc, pRec );
end;


Function BtrCfgGetHelp (                { Get help message }
      hCfg          : hDBICfg;          { Config Handle/NULL }
      pszConfigPath : PChar;            { configuration path }
      pszFldName    : PChar;            { field name  ( optional ) }
      pszHelpString : PChar             { help string ( returned ) }
   ): DBIResult;
begin
  Result := BtrEng.CfgGetHelp( hCfg, pszConfigPath, pszFldName, pszHelpString );
end;


Function BtrCfgMerge (                  { Merge config files }
      hCfgDest      : hDBICfg;          { Destination Cfg handle/ NULL }
      hCfgSrc       : hDBICfg;          { Source Cfg handle/ NULL }
      pszSrcPath    : PChar             { Source Path / NULL }
   ): DBIResult;
begin
  Result := BtrEng.CfgMerge( hCfgDest, hCfgSrc, pszSrcPath );
end;


{===========================================================================}
{                      Query Management                                     }
{===========================================================================}

Function BtrQExecDirect (               { Execute query }
      hDb           : hDBIDb;           { Database handle }
      eQryLang      : DBIQryLang;       { Query language }
      pszQuery      : PChar;            { Query }
      phCur         : phDBICur          { Returned cursor on result set }
   ): DBIResult;
begin
  Result := BtrEng.QExecDirect( hDb, eQryLang, pszQuery, phCur );
end;


Function BtrQAlloc (                    { Allocates a statement handle }
      hDb           : hDBIDb;           { Database handle }
      eQryLang      : DBIQryLang;       { Query language }
var   hStmt         : hDBIStmt          { Returned statment handle }
   ): DBIResult;
begin
  Result := BtrEng.QAlloc( hDb, eQryLang, hStmt );
end;


Function BtrQPrepare (                  { Prepare a query }
      hStmt         : hDBIStmt;         { Returned statment handle }
      pszQuery      : PChar             { Query }
   ): DBIResult;
begin
  Result := BtrEng.QPrepare( hStmt, pszQuery );
end;


Function BtrQExec (                     { Execute prepared query }
      hStmt         : hDBIStmt;         { Statement handle }
      phCur         : phDBICur          { Returned handle on result set }
   ): DBIResult;
begin
  Result := BtrEng.QExec( hStmt, phCur );
end;


Function BtrQPrepareExt (               { Prepare a query }
      hDb           : hDBIDb;           { Database handle }
      eQryLang      : DBIQryLang;       { Query language }
      pszQuery      : PChar;            { Query }
      propBits      : Word;             { properties for Prepare, e.g. qprepFORUPDATE }
var   hStmt         : hDBIStmt          { Returned statment handle }
   ): DBIResult;
begin
  Result := BtrEng.QPrepareExt( hDb, eQryLang, pszQuery, propBits, hStmt );
end;


Function BtrQFree (                     { Free statement handle }
var   hStmt         : hDBIStmt          { Statement handle }
   ): DBIResult;
begin
  Result := BtrEng.QFree( hStmt );
end;


Function BtrQSetParams (                { Set query options }
      hStmt         : hDBIStmt;         { Statement handle }
      uFldDescs     : Word;             { Number of parameter field descriptors }
      paFldDescs    : pFLDDesc;         { Array of parameter field descriptors }
      pRecBuff      : Pointer           { Record buffer }
   ): DBIResult;
begin
  Result := BtrEng.QSetParams( hStmt, uFldDescs, paFldDescs, pRecBuff );
end;


Function BtrQInstantiateAnswer (        { Create answer table }
      hStmt         : hDBIStmt;         { Statement Handle }
      hCur          : hDBICur;          { Cursor Handle }
      pszAnswerName : PChar;            { Answer Table Name/NULL }
      pszAnswerType : PChar;            { Answer Table Type/NULL }
      bOverWrite    : Bool;             { Overwrite Flag }
      phCur         : phDBICur          { cursor to instantiated table (output)(optional) }
   ): DBIResult;
begin
  Result := BtrEng.QInstantiateAnswer( hStmt, hCur, pszAnswerName, pszAnswerType,
              bOverWrite, phCur );
end;

Function BtrQExecProcDirect (           { Direct execution of stored procedure }
      hDb           : hDBIDb;           { Database handle }
      pszProc       : PChar;            { Stored procedure name }
      uParamDescs   : Word;             { Number of parameter descriptors }
      paParamDescs  : pSPParamDesc;     { Array of parameter descriptors }
      pRecBuff      : Pointer;          { Record buffer }
var   hCur          : hDBICur           { Returned handle on result set }
   ): DBIResult;
begin
  Result := BtrEng.QExecProcDirect( hDb, pszProc, UParamDescs, paParamDescs, pRecBuff, hCur );
end;


Function BtrQPrepareProc (              { Prepare a stored procedure }
      hDb           : hDBIDb;           { Database handle }
      pszProc       : PChar;            { Stored procedure name }
      uParamDescs   : Word;             { Number of parameter descriptors }
      paParamDescs  : pSPParamDesc;     { Array of parameter descriptors }
      pRecBuff      : Pointer;          { Record buffer }
var   hStmt         : hDBIStmt          { Returned statment handle }
   ): DBIResult;
begin
  Result := BtrEng.QPrepareProc( hDb, pszProc, uParamDescs, paParamDescs, pRecBuff, hStmt );
end;


Function BtrQSetProcParams (            { Set procedure params }
      hStmt         : hDBIStmt;         { Statement handle }
      uParamDescs   : Word;             { Number of parameter descriptors }
      paParamDescs  : pSPParamDesc;     { Array of parameter descriptors }
      pRecBuff      : Pointer           { Record buffer }
   ): DBIResult;
begin
  Result := BtrEng.QSetProcParams( hStmt, UParamDescs, paParamDescs, pRecBuff );
end;


Function BtrSchemaCacheFlush(hDb: hDBIDb; pszTableName: PChar): DBIResult;
begin
  Result := BtrEng.SchemaCacheFlush( hDb, pszTableName );
end;

Function BtrBeginConstraintLayer(
     hDb          : hDBIDb;
var  hCur         : hDBICur;
     pDsCb        : pfDataSourcesCallback;
     lUserVal     : Integer
  ): DBIResult;
begin
  Result := BtrEng.BeginConstraintLayer( hDb, hCur, pDsCb, lUserVal );
end;

Function BtrEndConstraintLayer(
var  hCur         : hDBICur
  ): DBIResult;
begin
  Result := BtrEng.EndConstraintLayer( hCur );
end;

Function BtrSQLTextToCanEx(
     hStmt         :  hDBIStmt;
     pExprText     :  PChar;
     iFields       :  Word;
     pFlds         :  pFLDDesc;
     exType        :  EXPType;
     pszFldName    :  PChar;
     pszSourceDb   :  PChar;
var  piCanSize     :  Word;
     pCanEx        :  PByte
   ): DBIResult;
begin
  Result := BtrEng.SQLTextToCanEx( hStmt, pExprText, iFields, pFlds, exType,
              pszFldName, pszSourceDb, piCanSize, pCanEx );
end;

Function BtrCheckSQLExpression(
     hCur          :  hDBICur;
     pszExpr       :  PChar;
     pszFldName    :  PChar;
     expType       :  EXPType;
     pDsCB         :  pfDataSourcesCallback;
     iClientData   :  Integer
   ): DBIResult;
begin
  Result := BtrEng.CheckSQLExpression( hCur, pszExpr, pszFldName, expType, pDsCB, iClientData );
end;

function DsProviderGetDataPacket(
    hCur             : hDBICur;         { Result cursor handle }
    eProvOptions     : Integer;         { Options for provider }
    pDsCB            : Pointer;         { Callback for field origin }
    iClientData      : Integer;         { Client Data for callback }
    piMaxRecords     : PInteger;        { In: Max recs, Out: Actual Recs }
var Packet           : PVarArray;
var pbEndOfData      : Bool             { End of file was reached }
): DBIResult;
begin
  Result := BtrEng.DsProviderGetDataPacket( hCur, eProvOptions, pDsCB, iClientData,
              piMaxRecords, Packet, pbEndOfData );
end;

function DsResolver(
    iNoOfDataSources  : Integer;               { Number of data sources. }
    Packets           : PPacketList;           { Packet Buffer }
    hDb               : hDBIDb;                { Database handle. }
    szDbName          : PChar;                 { Database name }
    szDbType          : PChar;                 { Database type }
    szDbPassword      : PChar;                 { Password }
    pszSqlStr         : PNameList;             { SQL str used to generate Packet. }
    ppTableName       : PNameList;             { If open table, name of table }
    piClientData      : PInteger;              { Client Data for Resolver callback }
    ppfReconcile      : PCBList;               { Reconcile Callback-fn }
    ppDsCB            : PCBList;               { PpfDataSourcesCallback; }
    ClientData        : Integer;               { Client Data for DSCallback }
    piMaxErrorRecords : PInteger;              { In: MaxErrors, Out: ErrorCount }
    pppErrPacket      : PPacketList            { Packet Buffer for error set }
): DBIResult;
begin
  Result := BtrEng.DsResolver(
              iNoOfDataSources,
              Packets,
              hDb,
              szDbName,
              szDbType,
              szDbPassword,
              pszSqlStr,
              ppTableName,
              piClientData,
              ppfReconcile,
              ppDsCB,
              ClientData,
              piMaxErrorRecords,
              pppErrPacket
            );
end;

Function BtrQGetBaseDescs(
      hStmt         : hDBIStmt;         { Statement Handle }
var   hCur          : hDBICur           { Cursor of type StatementBaseDesc }
   ): DBIResult;
begin
  Result := DBIERR_NOTSUPPORTED;
end;


{===========================================================================}
{                      Language drivers                                     }
{===========================================================================}

Function OsLdInit(pDefDir: PChar; pDefLangDr: PChar): DBIResult;
begin
  Result := BtrEng.OsLdInit( pDefDir, pDefLangDr );
end;


Function OsLdExit: DBIResult;
begin
  Result := BtrEng.OsLdExit;
end;


Function OsLdGetDefaultObj(var pLdObj: PLocale): DBIResult;
begin
  Result := BtrEng.OsLdGetDefaultObj( pLdObj );
end;


Function OsLdGetSymbName(pLdObj: PLocale; pSymbName: PByte): DBIResult;
begin
  Result := BtrEng.OsLdGetSymbName( pLdObj, pSymbName );
end;


Function OsLdGetDriverId( pLdObj : PLocale; var DriverId: Word ) : DBIResult;
begin
  Result := BtrEng.OsLdGetDriverId( pLdObj, DriverId );
end;

Function OsLdGetDescName( pLdObj : PLocale; pDescName: PByte ): DBIResult;
begin
  Result := BtrEng.OsLdGetDescName( pLdObj, pDescName );
end;


Function OsLdGetSortsig(pLdObj: PLocale; var SortSig: SmallInt): DBIResult;
begin
  Result  := BtrEng.OsLdGetSortSig( pLdObj, SortSig );
end;

function OsLdGetProductID (             { Get product ID (DBASE, PDOX, etc.) }
      pLdObj        : Pointer;
      piProdID      : PWord
   ): DBIResult;
begin
  Result := BtrEng.OsLdGetProductID( pLdObj, piProdID );
end;


Function OsLdGetCodePage(pLdObj: PLocale; var CodePage: SmallInt): DBIResult;
begin
  Result  := BtrEng.OsLdGetCodePage( pLdObj, CodePage );
end;

Function OsLdGetFName(pLdObj: PLocale; PName: PChar): DBIResult;
begin
  Result := BtrEng.OsLdGetFName( pLdObj, pName );
end;

function OsLdSearchInit(var SHandle: Pointer): DBIResult;
begin
  Result := BtrEng.OsLdSearchInit( SHandle );
end;

function OsLdSearchEnd(SHandle: Pointer): DBIResult;
begin
  Result := BtrEng.OsLdSearchEnd( SHandle );
end;


function OsLdSearchNext(SHandle: Pointer; var ppLdObj: Pointer): DBIResult;
begin
  Result := BtrEng.OsLdSearchNext( SHandle, ppLdObj );
end;

Function OsLdLoadBySortSig(SortSig: Word; CodePage: Word; var pLdObj: PLocale): DBIResult;
begin
  Result := BtrEng.OsLdLoadBySortSig( SortSig, CodePage, pLdObj );
end;

Function OsLdLoadByFName(pFName: PChar; var pLdObj :PLocale): DBIResult;
begin
  Result := BtrEng.OsLdLoadByFName( pFName, pLdObj );
end;

Function OsLdLoadBySymbName(pSymbName: PChar; var pLdObj: PLocale): DBIResult;
begin
  Result := BtrEng.OsLdLoadBySymbName( pSymbName, pLdObj );
end;

Function OsLdLoadByDriverId(iDriverId: Word; var pLdObj: PLocale): DBIResult;
begin
  Result := BtrEng.OsLdLoadByDriverId( iDriverId, pLdObj );
end;

function OsLdLoadByLCID ( _lcid : Integer; var pLdObj: Pointer ): DBIResult;
begin
  Result := BtrEng.OsLdLoadByCID( _lcid, pLdObj );
end;

Function OsLdUnloadObj(var pLdObj: PLocale): DBIResult;
begin
  Result := BtrEng.OsLdUnLoadObj( pLdObj );
end;


function OsLdGetMinMax( pLdObj : Pointer; pcMin : PChar; pcMax : PChar ): DBIResult;
begin
  Result := BtrEng.OsLdGetMinMax( pLdObj, pcMin, pcMax );
end;


Function OsLdStrnCmp(pLdObj: PLocale; Str1: PChar; Str2: PChar; Len: Word): DBIResult;
begin
  Result := BtrEng.OsLdStrnCmp( pLdObj, Str1, Str2, Len );
end;

Function OsLdStrCmp(pLdObj: PLocale; Str1: PChar; Str2: PChar): DBIResult;
begin
  Result := BtrEng.OsLdStrCmp( pLdObj, Str1, Str2 );
end;

Function OsLdStrToUpper(pLdObj: PLocale; Str: PByte): DBIResult;
begin
  Result := BtrEng.OsLdStrToUpper( pLdObj, Str );
end;

Function OsLdStrnToUpper(pLdObj: PLocale; Str: PByte; Len: Word): DBIResult;
begin
  Result := BtrEng.OsLdStrnToUpper( pLdObj, Str, Len );
end;

Function OsLdStrToLower(pLdObj: PLocale; Str: PByte): DBIResult;
begin
  Result := BtrEng.OsLdStrToLower( pLdObj, Str );
end;

Function OsLdStrnToLower(pLdObj: PLocale; Str: PByte; Len: Word): DBIResult;
begin
  Result := BtrEng.OsLdStrnToLower( pLdObj, Str, Len );
end;

Function OsLdStrCmpi(pLdObj: PLocale; str1:pCHAR; str2: PChar): SmallInt;
begin
  Result := BtrEng.OsLdStrCmpi( pLdObj, Str1, Str2 );
end;


Function OsLdStrnCmpi(pLdObj: PLocale; Str1: PChar; Str2: PChar; Len: Word): SmallInt;
begin
  Result := BtrEng.OsLdStrnCmpi( pLdObj, Str1, Str2, Len );
end;


Function OsLdSetConvChars (
      o2a           : Shortint;
      a2o           : Shortint
   ): DBIResult;
begin
  Result := BtrEng.OsLdSetConvChars( o2a, a2o );
end;

function OsLdGetFuncAddrLdStrnColli_(
      var ppf : Pointer
   ) : DBIResult;
begin
  Result := BtrEng.OsLdGetFuncAddrLdStrnColli_( ppf );
end;

function OsLdGetFuncAddrLdStrnColl_ (
var   ppf           : Pointer
   ): DBIResult;
begin
  Result := BtrEng.OsLdGetFuncAddrLdStrnColl_( ppf );
end;

function OsLdGetFuncAddrLdStrnCmpi_ (
var   ppf           : Pointer
   ): DBIResult;
begin
  Result := BtrEng.OsLdGetFuncAddrLdStrnCmpi_( ppf );
end;

function OsLdStrnColl (
      pLdObj        : Pointer;
      Str1          : PByte;
      Str2          : PByte;
      Maxlen        : Word
   ): Shortint;
begin
  Result := BtrEng.OsLdStrnColl( pLdObj, Str1, Str2, MaxLen );
end;

function OsLdStrnColli (
      pBlObj        : Pointer;
      str1          : PChar;
      str2          : PChar;
      iLen          : Word
   ): Shortint;
begin
  Result := BtrEng.OsLdStrnColli( pBlObj, Str1, Str2, iLen );
end;

function OsLdExStrCmp (
      pLdObj        : Pointer;
      Right         : PByte;
      RightLen      : Shortint;
      Left          : PByte;
      LeftLen       : Shortint;
      Exact: Bool
   ): Shortint;
begin
  Result := BtrEng.OsLdExStrCmp( pLdObj, Right, RightLen, Left, LeftLen, Exact );
end;


Function OsLdOemToAnsi(pLdObj: PLocale; AnsiStr: PChar; OemStr: PChar; Len: Word; var DataLoss: BOOL): DBIResult;
begin
  Result := BtrEng.OsLdOemToAnsi( pLdObj, AnsiStr, OemStr, Len, DataLoss );
end;

Function OsLdAnsiToOem(pLdObj: PLocale; OemStr: PChar; AnsiStr: PChar; Len: Word; var DataLoss: BOOL): DBIResult;
begin
  Result := BtrEng.OsLdAnsiToOem( pLdObj, OemStr, AnsiStr, Len, DataLoss );
end;

Function OsLdIsAnsiCharInOemCp(pLdObj :PLocale; AnsiCh: Char): Bool;
begin
  Result := BtrEng.OsLdIsAnsiCharInOemCp( pLdObj, AnsiCh );
end;

Function OsLdIsOemCharInAnsiCp(pLdObj :PLocale; OemCh: Char): Bool;
begin
  Result := BtrEng.OsLdIsOemCharInAnsiCp( pLdObj, OemCh );
end;

Function OsLdAnsiCharToOem(pLdObj: PLocale; ch: Byte): Byte;
begin
  Result := BtrEng.OsLdAnsiCharToOem( pLdObj, Ch );
end;

Function OsLdOemCharToAnsi(pLdObj: PLocale; ch: Byte): Byte;
begin
  Result := BtrEng.OsLdOemCharToAnsi( pLdObj, Ch );
end;

Function OsLdCharToUpper(pLdObj: PLocale; ch: Byte): Byte;
begin
  Result := BtrEng.OsLdCharToUpper( pLdObj, Ch );
end;

Function OsLdCharToLower(pLdObj: PLocale; ch: Byte): Byte;
begin
  Result := BtrEng.OsLdCharToLower( pLdObj, Ch );
end;

Function OsLdIsAlpha(pLdObj: PLocale; ch: Byte): Bool;
begin
  Result := BtrEng.OsLdIsAlpha( pLdObj, Ch );
end;

Function OsLdIsDigit(pLdObj: PLocale; ch: Byte): Bool;
begin
  Result := BtrEng.OsLdIsDigit( pLdObj, Ch );
end;

Function OsLdBuildCharSetXform(pCharMap: PChar; pLdObjSrc: PLocale;
           pLdObjDest: PLocale; var DataLoss: Bool): Bool;
begin
  Result := BtrEng.OsLdBuildCharSetXform( pCharMap, pLdObjSrc, pLdObjDest, DataLoss );
end;


Function BtrGetLdNameFromDb(hDb: hDbiDb; DbName: PChar; pldName: PChar): DbiResult;
begin
  Result := BtrEng.GetLdNameFromDb( hDb, DbName, pldName );
end;



Function BtrInit(pEnv: PDBIEnv): DBIResult;
begin
  Result := BtrInitFn(DbiINTFVER, pEnv);
end;


{===========================================================================}
{                      Data Repository                                      }
{===========================================================================}




end.

