Print Thread
Inserting empty record in DBGrid.
#46983 05/03/13 10:33 AM
Joined: May 2013
Posts: 10
V
vlad_n Offline OP
Member
OP Offline
Member
V
Joined: May 2013
Posts: 10
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 by vlad_n; 05/03/13 10:34 AM.
Re: Inserting empty record in DBGrid.
vlad_n #46986 05/04/13 10:00 AM
Joined: Aug 1999
Posts: 22,219
Member
Offline
Member
Joined: Aug 1999
Posts: 22,219
What exactly do you mean by an "empty" record? Can you also let me know the SQL of the dataset?


Marco Kalter
Allround Automations
Re: Inserting empty record in DBGrid.
Marco Kalter #46989 05/04/13 11:45 AM
Joined: May 2013
Posts: 10
V
vlad_n Offline OP
Member
OP Offline
Member
V
Joined: May 2013
Posts: 10
"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 by vlad_n; 05/04/13 11:51 AM.
Re: Inserting empty record in DBGrid.
vlad_n #47136 05/28/13 11:20 AM
Joined: May 2013
Posts: 10
V
vlad_n Offline OP
Member
OP Offline
Member
V
Joined: May 2013
Posts: 10
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 by vlad_n; 05/28/13 11:24 AM.

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.075s Queries: 14 (0.039s) Memory: 2.5174 MB (Peak: 3.0423 MB) Data Comp: Off Server Time: 2024-05-15 14:55:26 UTC
Valid HTML 5 and Valid CSS