[View Borland Home Page][View Product List][Search This Web Site][View Available Downloads][Join Borland Online][Enter Discussion Area][Send Email To Webmaster]

BDE API Examples (DbiGetProp)

Returns a property of an object.

Example 1: Return the native database handle

This example uses the following input:
Size := GetNativeDBHandle(Database1.Handle, NativeDB);
Size is a variable of type word. NativeDB is a variable of type longint.
function GetNativeDBHandle(DBHandle: hDBIDb; var NativeHandle: longint): word;
begin
  Result := 0;
  // Get the native handle to the database...
  Check(DbiGetProp(hDBIObj(DBHandle), dbNATIVEHNDL, @NativeHandle,
      sizeof(NativeHandle), Result));
end;

Example 2: Set the transisolation level for an ODBC datasource

This example uses the following input:
SetIsolationLevel(Database2.Handle);
procedure SetIsolationLevel(DBHandle: hDBIDb);
const
  // do not change this constant value...
  SQL_TXN_ISOLATION = 108;

  // use one of the below constants values in the call to SQLSetConnectOption...
  SQL_TXN_READ_UNCOMMITTED = $00000001;
  SQL_TXN_READ_COMMITTED = $00000002;
  SQL_TXN_REPEATABLE_READ = $00000004;
  SQL_TXN_SERIALIZABLE = $00000008;

type
  TSQLSetConnectOption = function(ConnectionHandle: longint; Option: word;
    Value: integer): smallint; stdcall;

var
  NativeHandle: longint;
  Size: word;
  SQLSetConnectOption: TSQLSetConnectOption;
  LibHandle: THandle;
  ODBCResult: smallint;

begin
  // Get the native handle to the database...
  Check(DbiGetProp(hDBIObj(DBHandle), dbNATIVEHNDL, pointer(@NativeHandle),
      sizeof(NativeHandle), Size));
  // Get a handle to the DLL...
  LibHandle := LoadLibrary('ODBC32.DLL');
  if LibHandle < 32 then
    raise EDatabaseError.Create('Could not find ODBC32.DLL on system');
  try
    // Get the address of the SQLSetConnectOption function...
    @SQLSetConnectOption := GetProcAddress(LibHandle, 'SQLSetConnectOption');
    if @SQLSetConnectOption = nil then
      raise EDatabaseError.Create('Could not find SQLSetConnectOption in ODBC32.DLL');

    // Call the SQLSetConnectOption function...
    ODBCResult := SQLSetConnectOption(NativeHandle, SQL_TXN_ISOLATION,
                      SQL_TXN_READ_COMMITTED);
    if (ODBCResult <> 0) and (ODBCResult <> 1) then // Error
      raise EDatabaseError.Create('Could not set transaction option');
  finally
    // Free the DLL...
    FreeLibrary(LibHandle);
  end;
end;
Back to BDE API Reference Page

DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.
Trademarks & Copyright © 1998 Borland International, Inc.