1
I have a problem: I have a datasnap/Rest server, in the same I have the following method:
Function TServerMethods.getComandoSQL(ASQL: string): TFDJSONDataSets;
begin
qryComando.Active := False;
qryComando.SQL.Clear;
qryComando.SQL.Add(ASQL);
Result := TFDJSONDataSets.Create;
TFDJSONDataSetsWriter.ListAdd(Result, qryComando);
end;
The method created by Delphi itself on the client:
function TServerMethodsClient.getComandoSQL(ASQL: string; const ARequestFilter: string): TFDJSONDataSets;
begin
if FgetComandoSQLCommand = nil then
begin
FgetComandoSQLCommand := FConnection.CreateCommand;
FgetComandoSQLCommand.RequestType := 'GET';
FgetComandoSQLCommand.Text := 'TServerMethods.getComandoSQL';
FgetComandoSQLCommand.Prepare(TServerMethods_getComandoSQL);
end;
FgetComandoSQLCommand.Parameters[0].Value.SetWideString(ASQL);
FgetComandoSQLCommand.Execute(ARequestFilter);
if not FgetComandoSQLCommand.Parameters[1].Value.IsNull then
begin
FUnMarshal := TDSRestCommand(FgetComandoSQLCommand.Parameters[1].ConnectionHandler).GetJSONUnMarshaler;
try
Result := TFDJSONDataSets(FUnMarshal.UnMarshal(FgetComandoSQLCommand.Parameters[1].Value.GetJSONValue(True)));
if FInstanceOwner then
FgetComandoSQLCommand.FreeOnExecute(Result);
finally
FreeAndNil(FUnMarshal)
end
end
else
Result := nil;
end;
When requesting this method at the customer:
var
dataset: TFDJSONDataSets;
begin
dataset := DataModule1.ServerMethodsClient.getComandoSQL( _SQL )
self.AppendData( TFDJSONDataSetsReader.GetListValue(dataset, 0) );
end;
So far so good, the problem is when I send an sql like: select code, Description from table Where Description like '%AD%'
On the server is: select code, Description from table Where Description like ''%''
This happens with AD, FA, FE among others... if you put for example %FARM% the result is '' ZENDA%''
Can debug to see when the script goes wrong?
– Matheus Ribeiro
I tried at this point: Fgetcomanqlcommand.Parameters[0].Value.Setwidestring(ASQL); ...
– Magno Costa
Try using Utf8encode(_SQL), maybe this is it...
– Junior Moreira
Unsuccessful.. same result
– Magno Costa
There is something wrong there, where you sent ''%AD%' consider sending in double quotes if the database allows, the problem is the ENCODE!
– Junior Moreira
@Magnocosta, do you send an SQL to the server run via Datasnap?... it was not easier to let the server do this by receiving a code that references this SQL.
– Jefferson Rudolf
I could not understand so far what happens, the problem is in the set %FA (or %AD or %FE, etc) because it can be in double quotes, without quotation marks or qq another character q the problem occurs, I did a gambiarra exchanging % for & and on the server I do the reverse, for now solved..
– Magno Costa
@Jefferson, I thought about it, I’ll implement it later.
– Magno Costa
@Magno Costa Good morning.. I’m starting to implement a datasnap/Rest server, I did by Delphi Tokyo Wizard. I even understood how this server works.. But from what I saw it only works with JSON.. When I try to send one . XML he error saying he could not validate JSON. My question to you, who has more experience than I am next.. This type of datasnap/Rest server it really doesn’t work for . XML?
– Ricardo M.Souza