Error while converting SQL - Datasnap Rest

Asked

Viewed 144 times

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?

  • I tried at this point: Fgetcomanqlcommand.Parameters[0].Value.Setwidestring(ASQL); ...

  • 1

    Try using Utf8encode(_SQL), maybe this is it...

  • Unsuccessful.. same result

  • There is something wrong there, where you sent ''%AD%' consider sending in double quotes if the database allows, the problem is the ENCODE!

  • 1

    @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.

  • 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..

  • @Jefferson, I thought about it, I’ll implement it later.

  • @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?

Show 4 more comments

1 answer

0

This happens because it is done automatically a encounter of your URL.

In short, to get you through %FAZENDA% would have to be %25FAZENDA%25, because the character % is represented by %25.

That’s not Delphi’s... any language will happen that.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.