Mega Code Archive

 
Categories / Delphi / ADO Database
 

Bde fonksiyonları 9

Return the user's network login name. User names are available for all networks supported by Microsoft Windows. This example uses the following input: MyName := GetMyNetUserName; The function is: function GetMyNetUserName: string; begin SetLength(Result, dbiMaxUserNameLen + 1); Check(DbiGetNetUserName(PChar(Result))); SetLength(Result, StrLen(PChar(Result))); end; //*********************************************************************************** Return the number format for the current session. The number format is appended to the TStringList passed in. This example uses the following input:fDbiGetNumberFormat(MyNumberFormat); The procedure is: procedure fDbiGetNumberFormat(var NumberFormat: TStringList); var FormatNumber: fmtNumber; begin Check(DbiGetNumberFormat(FormatNumber)); with NumberFormat do begin Add('Decimal Separator: ' + FormatNumber.cDecimalSeparator); Add('Thousand Separator: ' + FormatNumber.cThousandSeparator); Add('Decimal Digits: ' + IntToStr(FormatNumber.iDecimalDigits)); if (fmtNumber.bLeadingZero) then Add('Leading Zero: True') else Add('Leading Zero: False'); end; end; //************************************************************************************* Show the driver name associated with the given parameters. Delphi users will rarely need to call this function because most of this information is available through methods and properties of the TTable object. // Arguments: // hTmpDb: Database handle // pszTableName: Name of an existing table in the specified database // fDbiGetObjFromObj(hTmpDb, 'Employee.DB'); procedure fDbiGetObjFromObj(hTmpDb: hDBIDb; TblName: string); var hCursor: hDBICur; szName: array[0..DBIMAXPATHLEN] of char; nLen: Word; hObj: hDBIObj; rslt: DBIResult; begin // Open the specified table Check(DbiOpenTable(hTmpDb, PChar(TblName), nil, nil, nil, 0, dbiREADONLY, dbiOPENSHARED, xltFIELD, True, nil, hCursor)); // Retrieve driver handle given cursor handle Check(DbiGetObjFromObj(hDBIObj(hCursor), DBIOBJType(objDRIVER), hObj)); // Display driver name associated with the object handle rslt := DbiGetProp(hObj, drvDRIVERTYPE, @szName, sizeof(DBIPATH),nLen); if (rslt <> DBIERR_NONE) then Check(DbiCloseCursor(hCursor)) else ShowMessage('Drive type: '+szName); // Close table Check(DbiCloseCursor(hCursor)); end; Return the driver name for the specified table Return the driver name for the specified table. This example uses the following input: DriverStr := fDbiGetObjFromObj(hTmpDb, CustomerTbl); The function is: function fDbiGetObjFromObj(Table: TTable): string; var nLen: Word; hObj: hDBIObj; begin // Retrieve driver handle given cursor handle Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDRIVER, hObj)); SetLength(Result, DBIMAXDRIVELEN); // Get driver name associated with the driver handle Check(DbiGetProp(hObj, drvDRIVERTYPE, PChar(Result), DBIMAXDRIVELEN, nLen)); SetLength(Result, StrLen(PChar(Result))); end; //************************************************************************************* 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; //************************************************************************************** Get the record ID of the current record in the specified TTable. This example uses the following input: fDbiGetRecord(Table1, Num); The procedure is: procedure fDbiGetRecord(ATable: TTable; var RecID: Longint); var CP: CurProps; RP: RecProps; begin with ATable do begin // Make sure it is a Paradox table! UpdateCursorPos; // sync BDE with Delphi // Find out if table support Seq nums or Physical Rec nums Check(DbiGetCursorProps(Handle, CP)); Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RP)); if (StrComp(CP.szTableType, szDBASE) = 0) then RecID := RP.iPhyRecNum else if (StrComp(CP.szTableType, szPARADOX) = 0) then RecID := RP.iSeqNum else // raise exception if it's not a Paradox or dBASE table raise EDatabaseError.Create('Not a Paradox or dBASE table'); end; end; //*********************************************************************************** Return the record count of the TDataSet descendant (TTable, TQuery, TStoredProc) passed in parameter D. This example uses the following input: ShowMessage(IntToStr(fDbiGetRecordCount(Table1))); The function is: function fDbiGetRecordCount(D: TDataSet): LongInt; begin Check(DbiGetRecordCount(D.Handle, Result)); end; //*********************************************************************************** Return and fill a TStringList with information on the referential integrity. This example uses the following input: fDbiGetRIntDesc(OrdersTbl, 1, MyList); The function is: function fDbiGetRIntDesc(Table: TTable; SeqNo: Word; RIntList: TStringList): RINTDesc; var ThisTable, OtherTable: string; Props: CURProps; B: Byte; begin ThisTable := ''; OtherTable := ''; FillChar(Result, sizeof(Result), #0); Check(DbiGetCursorProps(Table.Handle, Props)); if (Props.iRefIntChecks = 0) then raise EDatabaseError.Create('There are no referential integrity checks on this table'); Check(DbiGetRIntDesc(Table.Handle, SeqNo, @Result)); if (RIntList <> nil) then begin with RIntList do begin Add(Format('NUMBER=%d', [Result.iRintNum])); Add(Format('NAME=%s', [Result.szRintName])); case Result.eType of rintMASTER: Add('TYPE=MASTER'); rintDEPENDENT: Add('TYPE=DEPENDENT'); else Add('TYPE=UNKNOWN'); end; Add(Format('OTHER TABLE=%s', [Result.szTblName])); case Result.eModOp of rintRESTRICT: Add('MODIFY=RESTRICT'); rintCASCADE: Add('MODIFY=CASCADE'); else Add('MODIFY=UNKNOWN'); end; case Result.eDelOp of rintRESTRICT: Add('DELETE=RESTRICT'); rintCASCADE: Add('DELETE=CASCADE'); else Add('DELETE=UNKNOWN'); end; Add(Format('FIELD COUNT=%d', [Result.iFldCount])); for B := 0 to DBIMAXFLDSINKEY do begin if (Result.aiThisTabFld[B] <> 0) then begin if (B <> 0) then ThisTable := Format('%s, %d', [ThisTable, Result.aiThisTabFld[B]]) else ThisTable := IntToStr(Result.aiThisTabFld[B]); end else Break; end; Add('FIELDS=' + ThisTable); for B := 0 to DBIMAXFLDSINKEY do begin if (Result.aiOthTabFld[B] <> 0) then begin if (B <> 0) then OtherTable := Format('%s, %d', [OtherTable, Result.aiOthTabFld[B]]) else OtherTable := IntToStr(Result.aiOthTabFld[B]); end else Break; end; Add('FIELDS OTHER=' + OtherTable); end; end; end; //*********************************************************************************** Get BDE session information. This function can return the SESInfo structure or clear and add the information to the SesInfoList TStringList. If nil is passed in, only the SESInfo structure is returned. This example uses the following input: Ses := fDbiGetSesInfo(MyList); The function is: function fDbiGetSesInfo(SesInfoList: TStringList): SESInfo; begin Check(DbiGetSesInfo(Result)); if (SesInfoList <> nil) then begin with SesInfoList do begin Clear; Add(Format('SESSION ID=%d', [Result.iSession])); Add(Format('SESSION NAME=%s', [Result.szName])); Add(Format('DATABASES=%d', [Result.iDatabases])); Add(Format('CURSORS=%d', [Result.iCursors])); Add(Format('LOCK WAIT=%d', [Result.iLockWait])); Add(Format('NET DIR=%s', [Result.szNetDir])); Add(Format('PRIVATE DIR=%s', [Result.szPrivDir])); end; end; end; //******************************************************************************** Get system configuration information: DbiGetSysConfig retrieves the BDE system configuration information and appends it to the TStringList passed in. This example uses the following input: fDbiGetSysConfig(MySysInfo); The procedure is: procedure fDbiGetSysConfig(var IdapiSysConfig: TStringList); var SysConfigInfo: SYSConfig; begin Check(DbiGetSysConfig(SysConfigInfo)); if SysConfigInfo.bLocalShare then IdapiSysConfig.Add('Local Share: ON') else IdapiSysConfig.Add('Local Share: OFF'); IdapiSysConfig.Add('Net Protocol: ' + IntToStr(SysConfigInfo.iNetProtocol)); if SysConfigInfo.bNetShare then IdapiSysConfig.Add('Net Share: ON') else IdapiSysConfig.Add('Net Share: OFF'); IdapiSysConfig.Add('Network Type: ' + StrPas(SysConfigInfo.szNetType)); IdapiSysConfig.Add('User Name: ' + StrPas(SysConfigInfo.szUserName)); IdapiSysConfig.Add('Ini File: ' + StrPas(SysConfigInfo.szIniFile)); IdapiSysConfig.Add('Language Driver: ' + StrPas(SysConfigInfo.szLangDriver)); end; //************************************************************************************ Get BDE system status information. This function can return the SYSInfo structure or clear and add the information to the SysInfoList TStringList. lf nil is passed in, only the SYSInfo structure is returned. This example uses the following input: Sys := fDbiGetSysInfo(MyList); The function is: function fDbiGetSysInfo(SysInfoList: TStringList): SYSInfo; begin Check(DbiGetSysInfo(Result)); if (SysInfoList <> nil) then begin with SysInfoList do begin Clear; Add(Format('BUFFER SPACE=%d', [Result.iBufferSpace])); Add(Format('HEAP SPACE=%d', [Result.iHeapSpace])); Add(Format('DRIVERS=%d', [Result.iDrivers])); Add(Format('CLIENTS=%d', [Result.iClients])); Add(Format('SESSIONS=%d', [Result.iSessions])); Add(Format('DATABASES=%d', [Result.iDatabases])); Add(Format('CURSORS=%d', [Result.iCursors])); end; end; end; //**************************************************************************************