Page 1 of 1

[patch_done] TZSQLProcessor Tokenizer problem and decision

Posted: 28.08.2008, 15:12
by GeorgeKP
The problem is in ZSQLStrings module near line 335.

The original code is:

Code: Select all

  Tokenizer := CommonTokenizer;
  if FDataset is TZAbstractRODataset then
  begin
    if Assigned(TZAbstractRODataset(FDataset).Connection) then
    begin
      Driver := TZAbstractRODataset(FDataset).Connection.DbcDriver;
      if Assigned(Driver) then
        Tokenizer := Driver.GetTokenizer;
    end;
  end;
As we can see, AbstractRODataset and every its decsendant will get right Tokenizer, but SQLProcessor will get only CommonTokenizer wich cannot understad escaped quotes like \' in PostgreSQL (for example).

Here is my suggestion:

Code: Select all

  Tokenizer := CommonTokenizer;
  if FDataset is TZAbstractRODataset then
  begin
    if Assigned(TZAbstractRODataset(FDataset).Connection) then
    begin
      Driver := TZAbstractRODataset(FDataset).Connection.DbcDriver;
      if Assigned(Driver) then
        Tokenizer := Driver.GetTokenizer;
    end;
  end
  else if FDataset is TZSQLProcessor then
  begin
    if Assigned(TZSQLProcessor(FDataset).Connection) then
    begin
      Driver := TZSQLProcessor(FDataset).Connection.DbcDriver;
      if Assigned(Driver) then
        Tokenizer := Driver.GetTokenizer;
    end;
  end;
Also we should change some lines in ZSQLProcessor unit to initialize field FDataset of ZSQLProcessor correctly.

Near line 161

Code: Select all

constructor TZSQLProcessor.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FParams := TParams.Create(Self);
  FScript := TZSQLStrings.Create;
  FScript.Dataset := Self; //----- add this ----
  FScript.OnChange := UpdateSQLStrings;
  FScriptParser := TZSQLScriptParser.Create;
  FScriptParser.DelimiterType := dtDefault;
  FScriptParser.Delimiter := ';';
  FScriptParser.CleanupStatements := False;
end;
and near line 369

Code: Select all

    SQL := TZSQLStrings.Create;
    SQL.Dataset := Self; //----- add this -----
    SQL.ParamCheck := FScript.ParamCheck;
    SQL.MultiStatements := False;
So, I ask any person on this forum who can accept patches to ZeosLib to review my patch and accept it, if it seems to be useful.

Posted: 29.08.2008, 00:19
by mdaems
I move this to the User patches directory. No time to do it right now, but this way we will not forget it.

My first impression : you're assigning a TComponent as if it is a TDataset. Seems like a dirty hack... No way to get to the TZSQLProcessor.Connection directly?

Mark

Posted: 29.08.2008, 16:41
by GeorgeKP
mdaems wrote: My first impression : you're assigning a TComponent as if it is a TDataset. Seems like a dirty hack... No way to get to the TZSQLProcessor.Connection directly?

Mark
I really have found no other way to access TZSQLProcessor instance from TZSQLStrings method.

By the way, FDataset property of TZSQLStrings has type TObject
and original code made the same type conversion as my patch does.

And I made a little inspection of the code and found no other usage of property TZSQLStrings.FDataset except in these lines to get right Tokenizer.

Posted: 11.09.2008, 07:19
by mdaems
Done in SVN rev. 434. It's not ported to the 6.6-patches branch yet. Reviewing the mpact of the patch it may be pretty safe, however. I'll consider doing this soon.

Mark

Posted: 13.09.2008, 00:48
by mdaems
Also committed to 6.6-patches branch. (SVN rev. 446)

Mark