[fpc-devel] Inserting first record
This is second email. Can somebody confirm, that there is Access Violation when we insert (or append) first row into empty dataset ? (or I missed something?) You can use attached program. TIA L. program testOldValue; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes, SysUtils, CustApp, db, sqlite3conn, sqldb, variants; type { TtestOldValue } TtestOldValue = class(TCustomApplication) protected procedure DoRun; override; public constructor Create(TheOwner: TComponent); override; destructor Destroy; override; procedure WriteHelp; virtual; private Forder: integer; procedure Show(Msg: string; Field: TField); procedure QfieldValidate(Sender: TField); procedure QfieldChange(Sender: TField); procedure QBeforePost(DataSet: TDataSet); procedure QAfterPost(DataSet: TDataSet); end; { SQLite3Test } procedure TtestOldValue.DoRun; var ErrorMsg: String; Conn: TSQLite3Connection; Tran: TSQLTransaction; s: string; Q: TSQLQuery; begin Conn:=TSQlite3Connection.Create(Self); Conn.DatabaseName:='test.db'; Tran:=TSQLTransaction.Create(Self); Tran.DataBase:=Conn; Conn.Open; Conn.ExecuteDirect('CREATE TEMPORARY TABLE t (int_field INTEGER PRIMARY KEY, str_field varchar(1))'); //Conn.ExecuteDirect('INSERT INTO t VALUES(1, ''O'')'); Q:=TSQLQuery.Create(Self); Q.Name:='SQLQuery1'; Q.DataBase:=Conn; Q.Transaction:=Tran; Q.BeforePost:=@QBeforePost; Q.AfterPost:=@QAfterPost; Q.SQL.Text:='SELECT * FROM t'; Q.Open; Q.Fields[1].OnValidate:=@QfieldValidate; Q.Fields[1].OnChange :=@QfieldChange; Forder:=1; Q.InsertRecord([1,'O']); Show('Before ApplyUpdates', Q.Fields[1]); Q.ApplyUpdates; Show('After ApplyUpdates', Q.Fields[1]); Tran.CommitRetaining; Forder:=1; Q.Edit; Q.Fields[1].Value:='N'; Q.Post; Show('Before ApplyUpdates', Q.Fields[1]); Q.ApplyUpdates; Show('After ApplyUpdates', Q.Fields[1]); Tran.CommitRetaining; Q.Close; Tran.Commit; Conn.Close; Q.Free; Tran.Free; Conn.Free; readln; // stop program loop Terminate; end; constructor TtestOldValue.Create(TheOwner: TComponent); begin inherited Create(TheOwner); StopOnException:=true; end; destructor TtestOldValue.Destroy; begin inherited Destroy; end; procedure TtestOldValue.WriteHelp; begin { add your help code here } writeln('Usage: ',ExeName,' -h'); end; procedure TtestOldValue.Show(Msg: string; Field: TField); function VarToStr2(v:variant):string; begin if VarIsNull(v) then Result:='null' else Result:=VarToStr(v); end; begin writeln( format('%d. %s: OldValue=%s; Value=%s; NewValue=%s', [Forder, Msg, VarToStr2(Field.OldValue), VarToStr2(Field.Value), VarToStr2(Field.NewValue)]) ); { writeln( format('%d. %s: DataSet=%s; Field=%s; OldValue=%s; Value=%s; NewValue=%s', [Forder, Msg, Field.DataSet.Name, Field.FieldName, VarToStr(Field.OldValue), VarToStr(Field.Value), VarToStr(Field.NewValue)]) ); } inc(Forder); end; procedure TtestOldValue.QfieldValidate(Sender: TField); begin Show('Field.OnValidate', Sender); end; procedure TtestOldValue.QfieldChange(Sender: TField); begin Show('Field.OnChange', Sender); end; procedure TtestOldValue.QBeforePost(DataSet: TDataSet); begin Show('BeforePost', DataSet.Fields[1]); end; procedure TtestOldValue.QAfterPost(DataSet: TDataSet); begin Show('AfterPost', DataSet.Fields[1]); end; var Application: TtestOldValue; {$R *.res} begin Application:=TtestOldValue.Create(nil); Application.Run; Application.Free; end. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
On Thu, 9 Jun 2011, LacaK wrote: This is second email. Can somebody confirm, that there is Access Violation when we insert (or append) first row into empty dataset ? (or I missed something?) You can use attached program. Is the problem only with sqlite ? Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
This is second email. Can somebody confirm, that there is Access Violation when we insert (or append) first row into empty dataset ? (or I missed something?) You can use attached program. Is the problem only with sqlite ? No, I can reproduce it also for example with MySQL. But exception is somehow connected with printing (accessing) OldValue ... when I ommit query to this property, then no exception occurs So It seems, that there must be fill more conditions: 1. Empty dataset 2. accessing OldValue ... If you can, try my test program with your database. TIA -Laco. Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
Here is attached debug output with {$DEFINE DSDebug}. It seems, that exception is related to Append/Insert (it does not depend if dataset is empty before or not) followed by accesing OldValue ... Setting current record to0 Post: Browse mode set Active buffer requested. Returning:0 exception at 0045C732: Access violation. SetBufListSize: -1 Freeing buffers :11 SetBufListSize: Final FBufferCount=-1 L. TFieldDef.Create : int_field(1) TFieldDef.Create : str_field(2) Creating fields Count : 2 Def 0 : int_field(1) Def 1 : str_field(2) About to create fieldint_field Creating field int_field TFieldDef.CReateField : Trying to set dataset TFieldDef.CReateField : Result Fieldno : 1 Self : 1 Setting dataset About to create fieldstr_field Creating field str_field TFieldDef.CReateField : Trying to set dataset TFieldDef.CReateField : Result Fieldno : 2 Self : 2 Setting dataset Found field int_field Calling internal open Calling RecalcBufListSize Recalculating buffer list size - check cursor Recalculating buffer list size Setting buffer list size SetBufListSize: 10 Reallocating memory :44 Filling memory :48 Filled memory : Assigning buffers :40 Assigned buffers 0 :40 SetBufListSize: Final FBufferCount=10 Getting next buffers Getting next record(s), need :10 Getting next record. Internal RecordCount : 0 Result getting next record : TRUE Getting next record. Internal RecordCount : 1 Result getting next record : FALSE Result Getting next record(S), GOT :1 Getting previous record(s), need :10 GetPriorRecord: Getting previous record Setting current record to0 Result getting prior record : FALSE SetBufferCount: FActiveRecord=0 FCurrentRecord=-1 FBufferCount= 10 FRecordCount=1 going to insert mode Active buffer requested. Returning:0 Active buffer requested. Returning:0 Active buffer requested. Returning:0 Done with append Active buffer requested. Returning:0 Active buffer requested. Returning:0 1. Field.OnValidate: OldValue=O; Value=O; NewValue=O Active buffer requested. Returning:0 Active buffer requested. Returning:0 Active buffer requested. Returning:0 2. Field.OnChange: OldValue=null; Value=O; NewValue=O Post: checking required fields Active buffer requested. Returning:0 Active buffer requested. Returning:0 Active buffer requested. Returning:0 3. BeforePost: OldValue=null; Value=O; NewValue=O Trying to do Trying : updatecursorpos Setting current record to0 Trying to do it Active buffer requested. Returning:0 Active buffer requested. Returning:0 Active buffer requested. Returning:0 Active buffer requested. Returning:0 Active buffer requested. Returning:0 Post: Internalpost succeeded Resync called Getting next record(s), need :10 Getting next record. Internal RecordCount : 1 Result getting next record : TRUE Getting next record. Internal RecordCount : 2 Result getting next record : FALSE Result Getting next record(S), GOT :1 Getting previous record(s), need :10 GetPriorRecord: Getting previous record Setting current record to0 Result getting prior record : FALSE Setting current record to0 Post: Browse mode set Active buffer requested. Returning:0 exception at 0045C732: Access violation. SetBufListSize: -1 Freeing buffers :11 SetBufListSize: Final FBufferCount=-1 ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
On Thu, 2011-06-09 at 11:49 +0200, LacaK wrote: Here is attached debug output with {$DEFINE DSDebug}. It seems, that exception is related to Append/Insert (it does not depend if dataset is empty before or not) followed by accesing OldValue Can't you just post the backtrace? Joost. -- My Lazarus blog: http://www.lazarussupport.com/lazarus/weblog ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
May be like this ? Thanks. Laco. On Thu, 2011-06-09 at 11:49 +0200, LacaK wrote: Here is attached debug output with {$DEFINE DSDebug}. It seems, that exception is related to Append/Insert (it does not depend if dataset is empty before or not) followed by accesing OldValue Can't you just post the backtrace? Joost. Program received signal SIGSEGV, Segmentation fault. 0x0045c772 in GETFIELDISNULL (NULLMASK=0x0, X=1) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/bufdataset.pas:686 686 result := ord(NullMask[x div 8]) and (1 shl (x mod 8)) 0 (gdb) backtrace #0 0x0045c772 in GETFIELDISNULL (NULLMASK=0x0, X=1) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/bufdataset.pas:686 #1 0x0045f085 in TCUSTOMBUFDATASET__GETFIELDDATA (FIELD=0x6200c4, BUFFER=0x16bdc00, this=error reading variable) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/bufdataset.pas:1797 #2 0x0045efe6 in TCUSTOMBUFDATASET__GETFIELDDATA (FIELD=0x6200c4, BUFFER=0x16bdc00, NATIVEFORMAT=true, this=error reading variable) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/bufdataset.pas:1766 #3 0x00433441 in TFIELD__GETDATA (BUFFER=0x16bdc00, NATIVEFORMAT=true, this=error reading variable) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/fields.inc:566 #4 0x00433389 in TFIELD__GETDATA (BUFFER=0x16bdc00, this=error reading variable) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/fields.inc:551 #5 0x00434c68 in TSTRINGFIELD__GETVALUE (AVALUE=0x0, this=error reading variable) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/fields.inc:1102 #6 0x00434a98 in TSTRINGFIELD__GETASVARIANT (this=error reading variable, result=...) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/fields.inc:1066 #7 0x00433036 in TFIELD__GETOLDVALUE (this=error reading variable, result=...) at C:/Programy/lazarus/fpc/2.5.1/source/packages/fcl-db/src/base/fields.inc:474 #8 0x00401cde in TTESTOLDVALUE__SHOW (MSG=0x46e3c0 'Before ApplyUpdates', FIELD=0x6200c4, this=error reading variable) at testOldValue.pas:128 #9 0x00401840 in TTESTOLDVALUE__DORUN (this=error reading variable) at testOldValue.pas:71 #10 0x0042b124 in CUSTAPP_TCUSTOMAPPLICATION_$__RUN () #11 0x00401f62 in main () at testOldValue.pas:163 ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
Hi, I committed a possible fix in rev. 17704. Please test. Michael. On Thu, 9 Jun 2011, LacaK wrote: May be like this ? Thanks. Laco. On Thu, 2011-06-09 at 11:49 +0200, LacaK wrote: Here is attached debug output with {$DEFINE DSDebug}. It seems, that exception is related to Append/Insert (it does not depend if dataset is empty before or not) followed by accesing OldValue Can't you just post the backtrace? Joost. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
Very similar to my fix, which I did minute ago. We can more cleanup code by removing unneeded parts. Please look at attached patch. Thanks L. PS1: Yes it fixes AV PS2: But still remains OldValue=null problem (see me 1st email) Hi, I committed a possible fix in rev. 17704. Please test. Michael. On Thu, 9 Jun 2011, LacaK wrote: May be like this ? Thanks. Laco. On Thu, 2011-06-09 at 11:49 +0200, LacaK wrote: Here is attached debug output with {$DEFINE DSDebug}. It seems, that exception is related to Append/Insert (it does not depend if dataset is empty before or not) followed by accesing OldValue Can't you just post the backtrace? Joost. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel --- bufdataset.pas.ori Thu Jun 09 13:37:02 2011 +++ bufdataset.pas Thu Jun 09 13:40:18 2011 @@ -1803,29 +1803,18 @@ begin if state = dsOldValue then begin if not GetActiveRecordUpdateBuffer then - begin - // There is no old value available - result := false; - exit; - end; -currbuff := FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer; + Exit; // There is no old value available +CurrBuff := FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer; end else CurrBuff := GetCurrentBuffer; - if not assigned(CurrBuff) then -begin -result := false; -exit; -end; + if not assigned(CurrBuff) then Exit; If Field.Fieldno 0 then // If = 0, then calculated field or something similar begin -if GetFieldIsnull(pbyte(CurrBuff),Field.Fieldno-1) then - begin - result := false; - exit; - end; +if GetFieldIsNull(pbyte(CurrBuff),Field.FieldNo-1) then + Exit; if assigned(buffer) then begin inc(CurrBuff,FFieldBufPositions[Field.FieldNo-1]); ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
On Thu, 9 Jun 2011, LacaK wrote: Very similar to my fix, which I did minute ago. We can more cleanup code by removing unneeded parts. Please look at attached patch. Applied the patch. Thanks L. PS1: Yes it fixes AV Good :-) PS2: But still remains OldValue=null problem (see me 1st email) What email is that, I only find a message about AV ? Michael. Hi, I committed a possible fix in rev. 17704. Please test. Michael. On Thu, 9 Jun 2011, LacaK wrote: May be like this ? Thanks. Laco. On Thu, 2011-06-09 at 11:49 +0200, LacaK wrote: Here is attached debug output with {$DEFINE DSDebug}. It seems, that exception is related to Append/Insert (it does not depend if dataset is empty before or not) followed by accesing OldValue Can't you just post the backtrace? Joost. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Inserting first record
Applied the patch.Thanks a lot What email is that, I only find a message about AV ?Message with subject TField.OldValue (today some minutes before my first message with subject "Inserting first record"-Laco. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel