[patch_done] TZSQLProcessor Tokenizer problem and decision

Code patches written by our users to solve certain "problems" that were not solved, yet.

Moderators: gto, cipto_kh, EgonHugeist, mdaems

Post Reply
GeorgeKP
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 28.08.2008, 14:50
Location: Russia, Moscow

[patch_done] TZSQLProcessor Tokenizer problem and decision

Post 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.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
GeorgeKP
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 28.08.2008, 14:50
Location: Russia, Moscow

Post 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.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Also committed to 6.6-patches branch. (SVN rev. 446)

Mark
Image
Post Reply