How to enable ftAutoInc in TBufDataSet? lazarus / 16-Databases ---------------------------------------------------------------------- tatamata · 2011-08-16 07:14 It seems that ftAutoInc can't be inserted or edited in TBufDataset. How could it be enabled in a TBufDataset descendents? ---------------------------------------------------------------------- Lacak2 · 2011-08-17 05:48 IMO it is as expected. Auto increment (generated) fields can not be set/modified by user they are handled by underlaying database. BTW which error message do you receive ? "AutoInc Fields are read-only" ? ---------------------------------------------------------------------- tatamata · 2011-08-17 06:58 Well, I want to make autoincrement generator in ZMQueryDataset, that is TBufDataSet descendent, and is meant not to be connected to any external database, but to work as stand-alone database. So, the question is how to override this read-only behavior and to enable TZMQueryDataSet to have ftAutoInc fields with internal autoincrement generator... ---------------------------------------------------------------------- BigChimp · 2011-08-17 07:45 Quote from: Lacak2 on August 17, 2011, 07:48:11 amIMO it is as expected. Auto increment (generated) fields can not be set/modified by user they are handled by underlaying database. BTW which error message do you receive ? "AutoInc Fields are read-only" ? In my tests with BufDataset, autoinc didn't get any values. If you create an autoinc field, I'd expect the values to be filled when adding records, but that didn't happen. Also, see http://bugs.freepascal.org/view.php?id=19930 where ftAutoInc support is proposed to be removed from bufdataset.. Lacak, if you have a solution for getting autoinc to work in Bufdataset (yes, read only, but at least with some auto-incrementing values), I'm all ears (and Tatamata too, probably ---------------------------------------------------------------------- Lacak2 · 2011-08-18 05:24 Your question is very correct. IMO there is really missing such possibility ATM. Read-only property of TAutoIncField is coded in fields.inc, so it has no direct relation to TBufDataSet (or any other TDataSet descendant). TBufDataSet only holds values in their local record buffers and allocates proper size to hold value (in this aspect ftAutoInc is equal to ftInteger field). So it does not matter if your dataset is local or "connected" to any SQL database. IMO there must be any new internal dynamic (with possibility to override) function (for example GetNextAutoIncValue()) which will be called just after insert if in current row will be ftAutoInc field. But implementing this will require change deep in DB units ;-) May be, that we can look at Delphi if there is support for such feature. ---------------------------------------------------------------------- BigChimp · 2011-08-21 06:06 Quote from: Lacak2 on June 02, 1970, 02:00:50 amIMO there must be any new internal dynamic (with possibility to override) function (for example GetNextAutoIncValue()) which will be called just after insert if in current row will be ftAutoInc field. But implementing this will require change deep in DB units ;-) May be, that we can look at Delphi if there is support for such feature. It seems that the FPC dbase units (source\packages\fcl-db\src\dbase) have support for ftAutoInc (eg files dbf.pas, db_dbffile - procedure procedure TDbfFile.ApplyAutoIncToBuffer(DestBuf: PChar); Of course, it's file based but some ideas might be useful... ---------------------------------------------------------------------- tatamata · 2014-01-19 11:11 Hello, guys, I have just successfully implemented ftAutoInc in TZMQueryDataset. 1. I searched for any "ftInteger" string in ZMBufDataset and just added ",ftAutoInc" wherever "ftInteger" is. 2. I overrided OnNewRecord this way: Code: [Select]procedure TZMQueryDataSet.DoOnNewRecord; var i:integer; begin   inherited DoOnNewRecord;  {New behavior}   //Increase value of autoincrement fields   for i:=0 to self.Fields.Count-1 do begin      if self.Fields[i].DataType=ftAutoInc then begin        self.Fields[i].AsInteger:=self.RecordCount+1;      end;   end; end; So, the same or similar should be done in TBufDataset, in order to implement ftAutoInc fields. ---------------------------------------------------------------------- BigChimp · 2014-01-19 13:32 Tatamata, could you please open a bug report for that so it won't be forgotten? Thanks a lot! ---------------------------------------------------------------------- tatamata · 2014-01-20 22:37 BigChimp, no need for that, somebody already implemented ftAutoInc in meantime (fpc 2.7.1 has working ftAutoInc in BufDataset) ---------------------------------------------------------------------- BigChimp · 2014-01-21 06:34 Probably revision r21757. Strange that I missed that one... Edit: updated docs: http://wiki.lazarus.freepascal.org/FPC_New_Features_Trunk#Bufdataset_s upports_ftAutoInc_fields ---------------------------------------------------------------------- tatamata · 2014-01-26 18:18 Hm, it seems that there is a problem: When TBufDataset is created and opened first time, ftAutoInc field is working correctly, but, if daatset is closed and then reopened again, autoincrementing stops working, the field value is null when appending new records. I submitted a bug: http://bugs.freepascal.org/view.php?id=25628 ---------------------------------------------------------------------- BigChimp · 2014-01-26 18:55 Please see bug report for info request. Thanks. ---------------------------------------------------------------------- LacaK · 2014-01-30 09:07 Patch was commited to trunk, can you test it please?