firebirde bağlanan kullanıcı sayısını nasıl bulabilirim?

Firebird ve Interbase veritabanları ve SQL komutlarıyla ilgli sorularınızı sorabilirsiniz. Delphi tarafındaki sorularınızı lütfen Programlama forumunda sorunuz.
Cevapla
ng
Üye
Mesajlar: 192
Kayıt: 01 Mar 2004 11:49
Konum: Bursa
İletişim:

firebirde bağlanan kullanıcı sayısını nasıl bulabilirim?

Mesaj gönderen ng »

Firebirde bağlanan kullancılardan haberdar olmak istiyorum? yada mesela 5 ten fazla kullanıcının aynı anda bağlantı yapmasını kısıtlamak istiyorum. mümkünmüdür ? Nasıl yapabilirim. Teşekkürler.
mucit
Üye
Mesajlar: 83
Kayıt: 24 Kas 2004 10:41
Konum: BURSA

Mesaj gönderen mucit »

Merhaba,

Kod: Tümünü seç

unit UserCountUnit;

interface

uses
  Windows, SysUtils;

  procedure BuildPBString(var PB: array of char; var PBLen: Integer; item: byte; contents: string);
  function UserSayi(DBName, UserName, Password: string): Integer;

implementation

const
  isc_dpb_version1 = 1;
  isc_dpb_user_name = 28;
  isc_dpb_password = 29;
  isc_info_end = 1;
  isc_info_truncated = 2;
  isc_info_error = 3;
  isc_info_user_names = 53;
  IBASE_DLL = 'GDS32.DLL';
  KILOBYTE = 1024;

type
  ISC_LONG = Longint;
  ISC_STATUS = ISC_LONG;
  ISC_STATUS_VECTOR = array[0..19] of ISC_STATUS;
  PSTATUS_VECTOR = ^ISC_STATUS_VECTOR;
  PPSTATUS_VECTOR = ^PSTATUS_VECTOR;
  Tisc_db_handle = Pointer;
  pisc_db_handle = ^Tisc_db_handle;
  TParamBlock = array[0..KILOBYTE - 1] of Char;
  TLargePB = array[0..(4 * KILOBYTE) - 1] of Char;
  TSmallPB = array[0..(KILOBYTE div 4) - 1] of Char;

var
  ErrorCode: ISC_STATUS;
  StatusVector: ISC_STATUS_VECTOR;
  DBHandle: Tisc_db_handle;

function isc_interprete(buffer: PChar; status_vector_ptr: PPSTATUS_VECTOR): ISC_STATUS;
  stdcall; external IBASE_DLL name 'isc_interprete';

function isc_attach_database(status_vector: PSTATUS_VECTOR; db_name_length: Short;
  db_name: PChar; db_handle: pisc_db_handle; parm_buffer_length: Short;
  parm_buffer: PChar): ISC_STATUS; stdcall; external IBASE_DLL name 'isc_attach_database';

function isc_database_info(status_vector: PSTATUS_VECTOR; db_handle: pisc_db_handle;
  item_list_buffer_length: Smallint; item_list_buffer: Pointer;
  result_buffer_length: Smallint; result_buffer: Pointer): ISC_STATUS;
  stdcall; external IBASE_DLL name 'isc_database_info';

function isc_vax_integer(result_buffer: PChar; result_length: SmallInt): ISC_LONG;
  stdcall; external IBASE_DLL name 'isc_vax_integer';

function isc_detach_database(status_vector: PSTATUS_VECTOR; db_handle:
  pisc_db_handle): ISC_STATUS; stdcall; external IBASE_DLL name 'isc_detach_database';

procedure BuildPBString(var PB: array of char; var PBLen: Integer; item: byte; contents: string);
var
  Len: Integer;
begin
  PB[PBLen]:= char(item);
  inc(PBLen);
  len:= Length(Contents);
  PB[PBLen]:= char(len);
  inc(PBLen);
  StrPCopy(@PB[PBLen], Contents);
  inc(PBLen, len);
end;

function UserSayi(DBName, UserName, Password: string): Integer;
var
  UserFound: boolean;
  DPB: TParamBlock;
  DPBLen: Integer;
  ItemList: TSmallPB;
  UserNames: TLargePB;
  UserCount: Integer;
  i: Integer;
  Item, Pos, Len, namelength: SmallInt;
  UserStr: array[0..255] of char;
begin
  Result:= 0;
  try
    UserFound:= false;
    if (DBName = '') or (UserName = '') then
      Exit;
    for i:= low(StatusVector) to high(StatusVector) do
      StatusVector[i]:= 0;
    DBHandle:= nil;
    fillchar(DPB, sizeof(DPB), #0);
    DPB[0]:= char(isc_dpb_version1);
    DPBLen:= 1;
    BuildPBString(DPB, DPBLen, isc_dpb_user_name, Username);
    BuildPBString(DPB, DPBLen, isc_dpb_password, Password);
    ErrorCode:= isc_attach_database(@StatusVector, Length(DBName), PChar(DBName),
      @DBHandle, DPBLen, @DPB);
    if ErrorCode <> 0 then
    begin
      Exit;
    end;
    fillchar(itemlist, sizeof(itemlist), #0);
    ItemList[0]:= char(isc_info_user_names);
    fillchar(UserNames, sizeof(UserNames), #0);
    ErrorCode:= isc_database_info(@StatusVector, @DBHandle, 1, @itemlist, 1024, @UserNames);
    if ErrorCode = 0 then
    begin
      item:= 0;
      UserCount:= 0;
      while not ((((UserNames[item]) = char(isc_info_end)) or
        ((UserNames[item]) = char(isc_info_error))) or
        ((UserNames[item]) = char(isc_info_truncated))) do
      begin
        pos:= item;
        inc(pos);
        len:= isc_vax_integer(@UserNames[pos], 2);
        inc(pos, 2);
        UserStr:= '';
        NameLength:= byte(UserNames[pos]) + 1;
        fillChar(UserStr, 256, #0);
        for i:= 1 to namelength - 1 do
          UserStr[i - 1]:= UserNames[pos + i];
        if not UserFound and (AnsiCompareText(UserName, UserStr) = 0) then
        begin
          UserFound:= true;
        end;
        inc(UserCount);
        inc(item, len + 3);
      end;
      Result:= UserCount;
    end;
    if assigned(DBHandle) then
      isc_detach_database(@StatusVector, @DBHandle);
  except
    Result:= 0;
    Exit;
  end;
end;

end.
UserSayi fonksiyonu ile o an bağlı kullanıcı sayısını tespit edebilirsiniz.
Kolay gelsin..
Cevapla