#1 2019-10-29 10:37:23

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 50

Error: project1 raised exception class 'External: SIGSEGV'.

Hello,
I have this function that connect to Server and get a text record from DB.
But it generate an exception :

Error
Project project1 raised exception class 'External: SIGSEGV'.
 At address 5B7A2D
function TMORMotObject.fGetQRSQLList: Boolean;
var
  oQuery: TQuery;
  oStream: TMemoryStream;
  sSQLstring: String;
  fld: TField;
begin
  Result := False;
  try
    // replace Rqsql_id
    sSQLstring := fRQSQL_txt;
    sSQLstring := StringReplace( sSQLstring, ':fRQSQL_id', IntToStr(fRQSQL_id), [rfReplaceAll]);
    // Create a Stream
    oStream := TMemoryStream.Create;
    // Create Connection.
    oQuery := TQuery.Create( fP.ThreadSafeConnection );
    oQuery.SQL.Clear;
    //oQuery.SQL.Add( 'SELECT QRSQL_C_TEXT     ' + sLineBreak + '  FROM T_QRSQL          ' + sLineBreak +  ' WHERE QRSQL_B_ACTIV = 1' + sLineBreak + '   AND QRSQL_B_SUP   = 0' + sLineBreak + '   AND QRSQL_N_ID    = ' +  IntToStr(fRQSQL_id) );
    oQuery.SQL.Add( sSQLstring );
    //oQuery.ParamByName('fRQSQL_id').AsString := fRQSQL_id;
    oQuery.Open;
    //
    if oQuery.IsEmpty then
      raise Exception.Create('No QRSQL for this ID');
    // Save to stream
    TMemoField( oQuery.FieldByName('QRSQL_SQL')).SaveToStream( oStream ) ;       < -- here where exception is fired
    // fSQL.Text := TField(oQuery.FieldByName('QRSQL_SQL')).AsString;                    < -- this not work.
    //oQuery.FieldByName('QRSQL_SQL').SaveToStream( oStream ) ;
    if oStream.Size <= 0 then
      raise exception.Create('No SQL inside ...');
    oStream.Position := 0;
    // return the QRSQL to StringList
    fSQL.LoadFromStream(oStream);
  finally
    FreeAndNil(oQuery);
    FreeAndNil(oStream);
  end;
end;   

Thanks for help.

Offline

#2 2019-10-29 21:49:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Error: project1 raised exception class 'External: SIGSEGV'.

I guess you are messing with classes.

oQuery.FIeldByName is NOT returning a TMemoField.

Offline

#3 2019-10-30 08:09:09

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 50

Re: Error: project1 raised exception class 'External: SIGSEGV'.

ab wrote:

I guess you are messing with classes.

oQuery.FIeldByName is NOT returning a TMemoField.

No, this is my uses clause.

uses
  Classes, SysUtils, JsonConf , Db,  
  mORMot, SynDB, SynTable, SynDBRemote, SynDBDataset;

and even the lazarus code completion gives an error while I try to push CTRL+SPACE after a point in

 oQuery.FieldByName('QRSQL_SQL'). 

Error is : Codetools, Errors: 1
mormotclassfuncs.pas(290,27) Error: illegal qualifier . found

PS : Note the point.

Offline

#4 2019-10-30 12:42:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Error: project1 raised exception class 'External: SIGSEGV'.

SynDB TQuery has NOTHING in common with DB.pas TQuery.

It is not a class, but a pointer to a record, so you need to write oQuery.FieldByName('....')^. for completion.
(unless you use Delphi mode which doesn't require the ^)

Offline

#5 2019-10-30 13:28:51

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 50

Re: Error: project1 raised exception class 'External: SIGSEGV'.

ab wrote:

SynDB TQuery has NOTHING in common with DB.pas TQuery.

It is not a class, but a pointer to a record, so you need to write oQuery.FieldByName('....')^. for completion.
(unless you use Delphi mode which doesn't require the ^)


Ooops !! ah d'accord ! cool

Last edited by Bsaidus (2019-10-30 13:29:20)

Offline

#6 2019-10-30 15:21:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Error: project1 raised exception class 'External: SIGSEGV'.

Just a tip:

Never force the trans-typing as

TMemoField( oQuery.FieldByName('QRSQL_SQL')) 

if you are not SURE both pointers do match.

So write

(oQuery.FieldByName('QRSQL_SQL') as TMemoField)

first, which may be slightly slower, but will give you much more information about types compatibility!

In your case, your code would never have compiled, and you may have found why by yourself. smile

It could avoid a lot of unexpected GPF in your code.

Offline

Board footer

Powered by FluxBB