Help translating some subclassed functions from V7.2x to V8

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
BytePlayer
Fresh Boarder
Fresh Boarder
Posts: 24
Joined: 21.09.2012, 10:13

Help translating some subclassed functions from V7.2x to V8

Post by BytePlayer »

In version 7.2.x I had subclassed the tzConnection component to add some convenience functions and there are two of them I am having no luck recreating in Version 8. The first is as follows, and since the fDatasets property has been removed, I don't know how to go about getting either the TableCount or the actual tables/datasets used by connection. Here was my original code:

Code: Select all

function kZConnection.GetTable(inTableName: string):kZTable;
var
  ResultIndex: Integer;
begin
     result:=Nil;
     for ResultIndex:=0 to Pred(FDatasets.Count) do
       if Assigned(FDataSets[ResultIndex]) and (Tobject(FDataSets[ResultIndex]) is tzTable) and
          SameText(tzTable(FDataSets[ResultIndex]).TableName,inTableName) then
            begin
                result:=kZTable(FDataSets[ResultIndex]);
                exit;
            end;
end;
I did see some FindTables functions but they only return table names not the datasets/tables themselves, and they require schemas which I am not entirely clear how to access. Another thought I had was using the FindComponent function of the kzConnection but I wasn't sure if that was the best way (or if it would even work) do accomplish this.

The Second function I'm struggling with was one that took an SQL String and returned a TObjectList of all the tables affected by an UPDATE, INSERT OR DELETE. I had used some tokenizer functions in V7.2.x but the tokenizer functions in Version 8 have changed so much I'm not even sure where to start.

Code: Select all

type
  tzTableList = TObjectList<tzTables>;

function kzConnection.FindAllTablesAffectedBySQL(const InSQL:String);tzTableList;
Any and all help on this would be GREATLY appreciated!
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Help translating some subclassed functions from V7.2x to V8

Post by marsupilami »

Hello BytePlayer

@FDataSets:
you might want to take a look at FLinkedComponents. This is a list of all components that link to a TZConnection object. Note: These are not only TZQuery and TZReadOnlyQurery. It also contains TZSequence and other objects. So pleas do a good check before you do things. Otherwide you might get unpredictable memory corruptions.

@FindAllTablesAffectedBySQL:
I didn't do the tokenizer changes, so maybe you will have to look into this on your own. If you publish your source code, I could try to take a look.

Best regards,

Jan
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 797
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Help translating some subclassed functions from V7.2x to V8

Post by aehimself »

You'll need something like TZGenericStatementAnalyser and DefineSelectSchemaFromQuery but instead of SELECT and FROM, you'll have to search to DELETE FROM, INSERT INTO and UPDATE SET.

Most probably you'll end up with a class helper / derived analyzer.

I just wrote one for myself, that's why I know :)

@ Jan,
We could move the logic in DefineSelectSchemaFromQuery to a protected method, with the two keywords to look for as parameters. That way deriving and writing custom analyzers would be a lot more easy.
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
BytePlayer
Fresh Boarder
Fresh Boarder
Posts: 24
Joined: 21.09.2012, 10:13

Re: Help translating some subclassed functions from V7.2x to V8

Post by BytePlayer »

Thanks guys! The FLinkedComponents was exactly what I needed.

As to the tokenizer issue I think that may really be using a pneumatic pile driver when a hammer will do. I think I just need to look at the table names following INSERT INTO, UPDATE and DELETE FROM and go from there.
Post Reply