lockrecord

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
Kullanıcı avatarı
kadirkurtoglu
Üye
Mesajlar: 748
Kayıt: 22 May 2005 01:20
Konum: Uzakta Görünen Tepeden...

lockrecord

Mesaj gönderen kadirkurtoglu »

s.a.

arkadaşlar FIBPlus IB/FB bağlantı bileşen setinin 6.30 versionunda

Kod: Tümünü seç

Function pFIBDataset.LockRecord(RaiseErr : Boolean = True) = TLockstatus
TLockstatus değerleri ise

isSuccess //Başarılı
isDeadLock //KayıtKilitli
isNotExist //Kilit Bulunmaması
isMultiply //Bilmiyorum
isUnknownError //Bilinmeyen Hata

Genel kullanımla ilgili deneme yapmadım. İlgilenen arkadaşlara duyrulur.
Bir mum, yanındaki mumları tutuşturmakla,
ışığında hiç bir şey kaybetmez.

Mevlana

OS win.10, IDE Delphi 10.3, RDBMS Firebird and MSSQL, BROWSER Chrome
Kullanıcı avatarı
kadirkurtoglu
Üye
Mesajlar: 748
Kayıt: 22 May 2005 01:20
Konum: Uzakta Görünen Tepeden...

Mesaj gönderen kadirkurtoglu »

ilgili Function detayı

Kod: Tümünü seç

function TpFIBDataSet.LockRecord(RaiseErr:boolean = True):TLockStatus;
var
  ExceptMessage:string;
  Retry:boolean;
  tf:TField;
  i:integer;
  UnknownErrorMsg, LockTxt:string;
  TableName:string;
  Where:string;
begin
  if (EmptyStrings(QUpdate.SQL) or
   (AutoUpdateOptions.AutoReWriteSqls and (AutoUpdateOptions.UpdateOnlyModifiedFields)))
  then
   with AutoUpdateOptions do
   if AutoReWriteSqls then
   begin
    LockTxt:=UpdateTableName;
    if KeyFieldList.Count>0 then
    begin
     Where:=KeyFieldList[0]+'=?'+KeyFieldList[0];
     for i:=1 to KeyFieldList.Count-1 do
      Where:=Where+' and '+KeyFieldList[i]+'=?'+KeyFieldList[i];
    end
    else
     raise Exception.Create(SFIBErrorUnableLock)
   end
   else
    raise Exception.Create(SFIBErrorUnableLock)
  else
  begin
   LockTxt:=GetModifyTable(QUpdate.ReadySQLText(False),True);
   Where:=QUpdate.WhereClause[1]
  end;
  if (LockTxt<>'') then
  begin
    TableName:=ExtractWord(1,LockTxt,CharsAfterClause);
    tf:= GetFieldForTable(TableName);
    if tf<>nil then
    begin
      LockTxt:='UPDATE '+LockTxt+' SET '
       +FormatIdentifier(Database.SQLDialect, GetRelationFieldName(tf))+'= ?'
       +FormatIdentifier(Database.SQLDialect, tf.FieldName)+' WHERE '
       +Where;
    end
    else
      LockTxt:= ''
  end;
  if LockTxt<>'' then
  begin
    if (vLockQry.SQL.Count=0) or (vLockQry.SQL.Text<>LockTxt+#13#10) then
      vLockQry.SQL.Text:= LockTxt
  end
  else
    vLockQry.SQL.Assign(QUpdate.SQL);
  if vLockQry.Database<>Database then
    vLockQry.Database:= Database;
  if vLockQry.Transaction<>UpdateTransaction then
    vLockQry.Transaction:= UpdateTransaction;

  if not CachedUpdates and not (State in [dsEdit, dsInsert]) then
    SaveOldBuffer(GetActiveBuf);
  SetQueryParams(vLockQry, GetActiveBuf);
  if CachedUpdates then
    for i:= 0 to Pred(vLockQry.Params.Count) do
    begin
      tf:= FindField(vLockQry.Params[i].Name);
      if (tf<>nil) and not tf.IsBlob then
        if tf.isNull then
          vLockQry.Params[i].IsNull:= True
        else
        if tf is TDateTimeField then
          vLockQry.Params[i].AsDateTime:= tf.OldValue
        else
          vLockQry.Params[i].Value:= tf.OldValue
    end;
  Result:= lsUnknownError;
  Retry:= True;
  while Retry do
  begin
    try
      if (not UpdateTransaction.InTransaction) and (poStartTransaction in Options)
      then
        UpdateTransaction.StartTransaction;
      vLockQry.ExecQuery;
      if vLockQry.RowsAffected = 1 then
        Result:= lsSuccess
      else
      if vLockQry.RowsAffected = 0 then
        Result:= lsNotExist
      else
        Result:= lsMultiply;
    except
      on E:EFIBError do
        case E.SQLCode of
         sqlcode_deadlock:
           Result:= lsDeadLock;
         sqlcode_901:
           if E.IBErrorCode= isc_lock_conflict then
            Result:= lsDeadLock
           else
           begin
            UnknownErrorMsg:= E.Message;
            Result:= lsUnknownError
           end;
        else
          UnknownErrorMsg:= E.Message;
          Result:= lsUnknownError
        end;
    end;
    if (Result<>lsSuccess) and RaiseErr then
    begin
      case Result of
        lsDeadLock:ExceptMessage:= SEdDeadLockMess;
        lsNotExist:ExceptMessage:= SEdNotExistRecord;
        lsMultiply:ExceptMessage:= SEdMultiplyRecord;
        lsUnknownError:ExceptMessage:= UnknownErrorMsg;
      end;
      ExceptMessage:= SEdErrorPrefix+ExceptMessage;
      Retry:= RaiseLockError(Result, ExceptMessage) = daRetry
    end
    else
      Retry:= False
  end;
end;
Bir mum, yanındaki mumları tutuşturmakla,
ışığında hiç bir şey kaybetmez.

Mevlana

OS win.10, IDE Delphi 10.3, RDBMS Firebird and MSSQL, BROWSER Chrome
Kullanıcı avatarı
White Rose
Üye
Mesajlar: 726
Kayıt: 06 Tem 2005 09:41
Konum: Güneyden
İletişim:

Mesaj gönderen White Rose »

Dataset in BeforeEdit ve BeforeDelete olaylarına

Try
Table.LockRecord(True);
except
Raise Exception.Create('Bu kayıt kilitli kardeş....');
end;

kodunu yaz

// DBNavigator'un da confirmdelete özelliğini False yap
Cevapla