Mega Code Archive

 
Categories / Delphi / ADO Database
 

Bde fonksiyonları 14

Release the record lock on either the current record or all the record locks in the current session. This example uses the following input: fDbiRelRecordLock(Table1.Handle, True); The procedure is: procedure fDbiRelRecordLock(hTmpHandle:hDBICur; bAll: Boolean); begin Check(DbiRelRecordLock(hTmpHandle, bAll)); end; //********************************************************************************* Release all locks placed on a table by DbiAcqTableLock. Delphi users can use the TTable.UnLockTable method rather than directly calling DbiRelTableLock. This method is defined as: Procedure TTable.UnLockTable(LockType: TLockType); This example uses the following input: fDbiRelTableLock(Table1, True, dbiWRITELOCK); The procedure is: procedure fDbiRelTableLock(TblName: TTable; All: Boolean; Lock: DBILockType); var hNewCur: hDbiCur; begin Check(DbiGetCursorForTable(TblName.DBHandle, PChar(TblName.TableName), '', hNewCur)); Check(DbiRelTableLock(hNewCur, All, Lock)); end; Release all locks on the specified table. Delphi users can use the TTable.UnlockTable method rather than directly calling DbiRelTableLock. This example uses the following input: fDbiRelTableLock(Table1); The procedure is: procedure fDbiRelTableLock(TblName: TTable); begin Check(DbiRelTableLock(TblName.Handle, True, dbiWRITELOCK)); end; //************************************************************************************* Rename the table to the new table name. If ReOpen is True, reset the table's TableName and reopen the table. Note: Most Delphi users should use TTable.RenameTable method. procedure fDbiRenameTable(Table: TTable; NewName: string; ReOpen: Boolean); var hDb: hDBIDb; Props: CURProps; begin if not Table.Active then EDatabaseError.Create('Table must be open to complete operation'); if not Table.Exclusive then EDBEngineError.Create(DBIERR_NEEDEXCLACCESS); Check(DbiGetCursorProps(Table.Handle, Props)); // Get the Database Handle from the table cursor since Table.DBHandle will // be invalid once the table is closed Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb))); Table.Close; Check(DbiRenameTable(hDb, PChar(Table.TableName), Props.szTableType, PChar(NewName))); if ReOpen then begin Table.TableName := NewName; Table.Open; end; end; //************************************************************************************ Reset the range of a table after using DbiSetRange. This example removes constraints on a result set. function fDbiResetRange(Handle: hDBICur): DBIResult; begin Return := DbiResetRange(Handle); { remove range } Check(Return); { raise an exception if that failed } end; //*********************************************************************************** Save all updated records associated with hTmpHandle to disk. This example uses the following input fDbiSaveChanges(Table1.Handle); The procedure is: procedure fDbiSaveChanges(hTmpHandle:hDBICur); begin Check(DbiSaveChanges(hTmpHandle)); end; //*********************************************************************************** Set the current session. Note: Most Delphi users should use Sessions (TSessionList) and Session (TSession) to alter the current session. This example uses the following input: fDbiSetCurrSession(Session.Handle); The procedure is: procedure fDbiSetCurrSession(hSes: hDBISes); begin Check(DbiSetCurrSession(hSes)); end; //*********************************************************************************** Set the date format for the current session. This example uses the following input: fDbiSetDateFormat; The procedure is: procedure fDbiSetDateFormat; var fDate : FMTDate; begin // Specifies date separator character fDate.szDateSeparator := '/'; { } // Date format. 0 = MDY, 1 = DMY, 2 = YMD fDate.iDateMode := 0; // If TRUE, write year as four digits fDate.bFourDigitYear := False; // On input add 1900 to year if True fDate.bYearBiased := False; // Month displayed with a leading zero if True fDate.bMonthLeadingZero := False; //. Day displayed with leading zero if True fDate.bDayLeadingZero := False; Check(DbiSetDateFormat(fDate)); end; //********************************************************************************* Set the current working directory. The function fDbiSetDirectory for the database specified in the hdb parameter to the directory in the Dir parameter. This example uses the following input: fDbiSetDirectory(Database1.Handle, 'C:\Tables'); The procedure is: procedure fDbiSetDirectory(hdb: hDbiDb; Dir: string); begin Check(DbiSetDirectory(hdb, PChar(Dir))); end; //********************************************************************************* Set a field map for the current table. Note: Most Delphi users should use the Fields Editor of a TTable to set the field mapping. This example uses the following input: fDbiSetFieldMap(CustomerTbl, [CustomerTbl.FieldByName('Company'), CustomerTbl.FieldByName('City')]); The procedure is: procedure fDbiSetFieldMap(Table: TTable; const Fields: array of TField); var CurrentElement, Elements, FldNum: Integer; pFields, pOrigFields, pF, pOF: pFLDDesc; begin Elements := sizeof(Fields) div sizeof(TField); pFields := AllocMem(Elements * sizeof(FLDDesc)); pOrigFields := AllocMem(Table.FieldCount * sizeof(FLDDesc)); pF := pFields; try // Get the original field descriptors Check(DbiGetFieldDescs(Table.Handle, pOrigFields)); // Iterate through the original fields and create a pFLDDesc structure // for the new field map structure for CurrentElement := 0 to (Elements – 1) do begin pOF := pOrigFields; for FldNum := 1 to Table.FieldCount do begin // Add only the field names that match if (StrIComp(PChar(Fields[CurrentElement].FieldName), pOF.szName) = 0) then begin // Move the original FLDDesc to the new FLDDesc move(pOF^, pF^, sizeof(FLDDesc)); Inc(pF); break; end else Inc(pOF); end; end; Check(DbiSetFieldMap(Table.Handle, Elements, pFields)); finally FreeMem(pFields, Elements * sizeof(FLDDesc)); FreeMem(pOrigFields, Table.FieldCount * sizeof(FLDDesc)); end; end; //******************************************************************************** Set the specified session's lock retry time. This example uses the following input: fDbiSetLockRetry(Session, 100); The procedure is: procedure fDbiSetLockRetry(LockSession: TSession; Wait: Integer); var OriginalSession: TSession; begin // Save the current session OriginalSession := Sessions.CurrentSession; // Set the current session to the specified session Sessions.CurrentSession := LockSession; // Set the lock retry time Check(DbiSetLockRetry(Wait)); // Set the current session back to the original session Sessions.CurrentSession := OriginalSession; end; //********************************************************************************* Set the private directory. Delphi programs should use the TSession, PrivateDir property rather than using the dbi function directly. This sets the private directory for Paradox tables. For all drivers, all temporary or auxiliary files are created/kept in this directory. This example uses the following input: fDbiSetPrivateDir('C:\Temp'); The procedure is: procedure fDbiSetPrivateDir(Dir: string); begin Check(DbiSetPrivateDir(PChar(Dir))); end; //********************************************************************************** Example1: Enable or disable soft deletes. Set soft deletes to True or False depending on the Boolean parameter SoftDelete in the TTable specified in the Table parameter. This example uses the following input: fDbiSetProp1(AnimalTbl, True); The procedure is: procedure fDbiSetProp1(Table: TTable; SoftDelete: Boolean); var rslt: DBIResult; Props: CURProps; begin Check(DbiGetCursorProps(Table.Handle, Props)); if (Props.szTableType <> szDBASE) then raise EDBEngineError.Create(DBIERR_NOTSUPPORTED); // Make sure that the property can be set rslt := DbiValidateProp(hDBIObj(Table.Handle), curSOFTDELETEON, True); if (rslt = DBIERR_NONE) then // Set the property Check(DbiSetProp(hDBIObj(Table.Handle), curSOFTDELETEON, Longint(SoftDelete))) else raise EDBEngineError.Create(rslt); end; Example 2: Specify the maximum number of rows to be fetched from an SQL statement. Set the maximum rows fetched in the parameter MaxRows, for the SQL table specified in the Table parameter. This example uses the following input: fDbiSetProp2(IBTable, 100); The procedure is: procedure fDbiSetProp2(Table: TTable; MaxRows: Longint); var rslt: DBIResult; DBType: string; Len: Word; begin SetLength(DBType, DBIMAXNAMELEN); Check(DbiGetProp(hDBIObj(Table.DBHandle), dbDATABASETYPE, PChar(DBType), DBIMAXNAMELEN, Len)); SetLength(DBType, StrLen(PChar(DBType))); // Make sure the table type is not dBASE or Paradox (must be SQL based) if (DBType = 'STANDARD') then raise EDBEngineError.Create(DBIERR_NOTSUPPORTED); // Make sure that the property can be set rslt := DbiValidateProp(hDBIObj(Table.Handle), curMAXROWS, True); if (rslt = DBIERR_NONE) then // Set the property Check(DbiSetProp(hDBIObj(Table.Handle), curMAXROWS, MaxRows)) else raise EDBEngineError.Create(rslt); end;