Page 1 of 1

asking MySql Variable change from Zeos6.x and Zeos 7

Posted: 05.12.2019, 12:46
by DavideAmelio
Hello with Zeos 6.x i made a function that Result the size ( integer )r of max_allowed_packet and worked, now with zeos 7.x the same function give me back a Bytes result...is there a way to change back or any other walk around?

thnks

Re: asking MySql Variable change from Zeos6.x and Zeos 7

Posted: 05.12.2019, 12:55
by marsupilami
Hello, could you show us the source code, you are talking about?
Best regards, Jan

Re: asking MySql Variable change from Zeos6.x and Zeos 7

Posted: 05.12.2019, 13:01
by DavideAmelio
Thanks, very simple

Qry := TZReadOnlyQuery.Create(nil);
Qry.Connection := pCon;
with Qry do begin
SQL.Text := 'Show variables like '+QuotedStr(pVarName);
Open;
case Fields[1].DataType of
ftString: Result := Fields[1].Value;
ftBlob: Result := Fields[1].Value;
ftMemo: Result := Fields[1].Value;
ftFmtMemo: Result := Fields[1].Value;
ftFixedChar: Result := Fields[1].Value;
ftWideString : Result := Fields[1].Value;
ftVarBytes : Result := Fields[1].Value;
ftBytes : Result := Fields[1].Value; // <======= in the past was Integer
ftInteger
,ftLargeint
,ftAutoInc
,ftSmallint
,ftFloat
,ftCurrency
,ftDateTime
,ftDate : Result := Fields[1].Value;
else Result := Fields[1].Value;

end;
// Result := Fields[1].Value; // <==== Previous and Worked on Zeos6.x

Re: asking MySql Variable change from Zeos6.x and Zeos 7

Posted: 06.12.2019, 08:04
by aehimself
I don't know what exactly you are trying to achieve, but this is BAD code.
TField.Value is variant type, which means it can contain almost anything. When you assign a variant to an other variable Delphi will try to convert it for you; therefore a Result := Query.Fields[0].Value will always work (until the data in the database can be converted to your desired type, that is).

So in order to be able to help:
- What is the problem with your code? Does it throw an exception? Does it not compile? What errors you receive, what do you expect to happen and what happens instead?
- What do you mean ftBytes were Integer in the past...? I don't think a byte array was handled as integer ever.
- What is the return type of the function? Is Result a String or a Variant? (I hope nothing else...)
- Are you absolutely sure that ALL results can be converted to this type? If you are expecting a number then you are in for some nasty surprises. In this sample output your code will throw a variant conversion exception for sure:
Variables.PNG
- Why are you using .Value? Why not .AsString or .AsInteger?