Page 1 of 1

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

Posted: 19.09.2022, 23:06
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!

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

Posted: 20.09.2022, 16:52
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

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

Posted: 20.09.2022, 20:47
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.

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

Posted: 21.09.2022, 12:27
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.