You are not logged in.
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
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
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
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 !
Last edited by Bsaidus (2019-10-30 13:29:20)
Offline
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.
It could avoid a lot of unexpected GPF in your code.
Offline