Inserting empty record in DBGrid.

vlad_n

Member²
DOA 4.1.2.2
Delphi XE SP1

OracleDataset - DataSource - DBGrid.
1. On DBGrid I press "Insert" key. The new record append.
2. Then I enter any value to field on new record and remove this value.
3. Click "Apply updates" button on DBNAvigator. The changes saved to new record.
4. When I try to edit this new empty record then error occured:
A lock, refresh or check cannot be performed without a rowid.
Provide a rowid in the query or handle this action in the OnApplyRecord event.

Because the record is not inserted into table.

How I can really insert new empty record through DBGrid?
 
Last edited:
"Empty" record is a record in which all the fields is null.
For example SQL of dataset is:
SELECT TABLE1.*, TABLE1.ROWID FROM TABLE1

After my actions described in the first post, record is added to the internal buffer of OracleDataset and is not added to the database table.
 
Last edited:
Because the developers don't want to correct this bug I did to fix it.

unit OracleData procedure TOracleDataSet.InternalInsertUpdate;

Code:
// Update or insert the record in the collection
    if not (CachedUpdates and Applying) then
    begin
      if Updating then
      begin
        // Log the change
        RecordToChangeLog(Records.RecordAt(FCurRec), b, 'U', 0, FCurRec);
        // Save the change to the Record collection
        SaveRecordData(b, FCurRec);
      end else begin
        // Create a new item in the Record collection
        r := Records.NewRecord(FCurRec, Filtered);
        if (FCurRec < 0) or (FCurRec >= Records.RecordCount) then
          FCurRec := Records.RecordCount - 1;
        SaveRecordData(b, FCurRec);
        Inc(FLastBookmark);
        if not CachedUpdates then Inc(RowsAdded);
        r.Bookmark := FLastBookmark;
        r.BookmarkFlag := bfCurrent;
        b.Bookmark := r.Bookmark;
        // Log the change
        RecordToChangeLog(nil, b, 'I', r.Bookmark, FCurRec);
      end;
    end;

Replace with this code:

Code:
// Update or insert the record in the collection
    if not (CachedUpdates and Applying) then
    begin
      if Updating then
      begin
        // Log the change
        RecordToChangeLog(Records.RecordAt(FCurRec), b, 'U', 0, FCurRec);
        // Save the change to the Record collection
        SaveRecordData(b, FCurRec);
      end else if not NoChanges then begin
        // Create a new item in the Record collection
        r := Records.NewRecord(FCurRec, Filtered);
        if (FCurRec < 0) or (FCurRec >= Records.RecordCount) then
          FCurRec := Records.RecordCount - 1;
        SaveRecordData(b, FCurRec);
        Inc(FLastBookmark);
        if not CachedUpdates then Inc(RowsAdded);
        r.Bookmark := FLastBookmark;
        r.BookmarkFlag := bfCurrent;
        b.Bookmark := r.Bookmark;
        // Log the change
        RecordToChangeLog(nil, b, 'I', r.Bookmark, FCurRec);
      end else
      begin
        Cancel;
        Abort;
      end;
    end;
 
Last edited:
Back
Top