Hello
Hello,
I just fell over this one with my 1st Delphi project moved to XE7 (previously XE6):
dsQ := TFDQuery.Create(Self);
dsQ.Connection := DM1.FDConnection1; // MySQL Server
dsQ.SQL.Text := 'SELECT gueltig_id FROM gueltig ORDER BY gueltig_id DESC';
dsQ.Open;
if not dsQ.Eof then
ResultID := dsQ.Fields[0].AsInteger + 1 // XE6 gives 156989 = correct XE7 returns 5400 = WRONG!!
else
ResultID := 100; // just dont want to start with 1 or 10
dsQ.Close;
dsQ.Free;
This little code sample returns the correct result in XE6, but completely incorrect in XE7 (both debug mode). Both On exactly the same server.
MySQL Server is v5.6.12
FireDAC version is standard delivered with XE7
Delphi XE7 running on Windows 8.1 Update 1 in a VM (same OS for XE6, but separate VM).
Moving code into another unit (form) doesn't help. Nor using TFDTable instead of TFDQuery.
Anybody any clue?
#delphi #programming #xe7 #firedac #mysql
I just fell over this one with my 1st Delphi project moved to XE7 (previously XE6):
dsQ := TFDQuery.Create(Self);
dsQ.Connection := DM1.FDConnection1; // MySQL Server
dsQ.SQL.Text := 'SELECT gueltig_id FROM gueltig ORDER BY gueltig_id DESC';
dsQ.Open;
if not dsQ.Eof then
ResultID := dsQ.Fields[0].AsInteger + 1 // XE6 gives 156989 = correct XE7 returns 5400 = WRONG!!
else
ResultID := 100; // just dont want to start with 1 or 10
dsQ.Close;
dsQ.Free;
This little code sample returns the correct result in XE6, but completely incorrect in XE7 (both debug mode). Both On exactly the same server.
MySQL Server is v5.6.12
FireDAC version is standard delivered with XE7
Delphi XE7 running on Windows 8.1 Update 1 in a VM (same OS for XE6, but separate VM).
Moving code into another unit (form) doesn't help. Nor using TFDTable instead of TFDQuery.
Anybody any clue?
#delphi #programming #xe7 #firedac #mysql
Same result using FieldByName as Fields[0]?
ReplyDeleteYes! Was previously .FieldByName('gueltig_id').AsInteger
ReplyDeleteAnd checked all TFDConnection params, fetchall, etc...)
What's the mysql data type of gueltig_id ?
ReplyDeletePlease check the FDquery property
ReplyDeleteFechOptions
and
just after open, check the value of
RecordSize
and
RecordCount
then compare to the correct value by other means, for example phpmyadmin or db explorer ...
Oliver Funcke data type in table definition is INT(11)
ReplyDeleteOliver Funcke Sam Shaw
ReplyDelete.RecordCount is incorrect, indeed (by far) !
dsQ.FetchOptions.Mode = fmAll;
(does this is of any importance?)
and
DM1.FDConnection1.FetchOptions = afAll
DM1.FDConnection1.FetchOptions.Mode = fmAll
So, not all the records are returned, and I simply seem to fail to find the (modified?) concerned parameter or property in XE7...
I couldn't test with MySQL, but a local table gives the desired result:
ReplyDeleteFDMTGueltig.Insert;
FDMTGueltig.Fields[0].AsInteger := 156988;
FDMTGueltig.Post;
ShowMessage((FDMTGueltig.FieldByName('gueltig_bis').AsInteger+1).ToString); // 156989
Also, the query you are using is very bad performancewise - I assume you want to retrieve the highest gueltig_bis id to generate the next one. Better with:
SELECT max(coalesce(gueltig_id,99))+1 as gueltig_id FROM gueltig
Yes, I imagine my example is far away from performance-optimized... fact is that even with your suggestion (MAX...) the result is (the same) incorrect one simply because the whole table isn't read, and I don't find the correct property to fetch all the records.
ReplyDeleteSam Shaw Ok, thanks, I will try (but does not explain why XE7 behaves differently from XE6...). I hope I don't fell over too much of such "differences".
ReplyDeleteSam Shaw Tried your suggestion, same wrong result. So, the problem is not TFDQuery, but at TFDConnection in conjunction with MySQL, I suppose.
ReplyDeleteDigging...
Did you check the TField properties? (ftInteger, Datasize etc.)
ReplyDeleteTemporary result:
ReplyDeleteI can't believe it, it not only seems to be, but it IS a problem on the Windows 8.1 Update 1 workstation (VM) !!!
XE6-Version on the XE6-developer-PC: correct result
XE7-Version on the XE6-developer-PC: correct result
XE6-Version on the XE7-developer-PC: wrong result
XE7-Version on the XE7-developer-PC: wrong result
So I'm not sure if it still can be a FireDAC issue which may behaving differently on different PCs, due to whatever. The MySQL-dll (libmysql.dll) is the same on both PCs for both versions.
Thanks to all who participated until now. I will update the thread as soon as I have found a/the solution.
Oliver Funcke Sam Shaw jeff weir
For testing I used :
ReplyDeleteDelphi XE7
Client libmysql.dll 6.1.5
Server 5.6.21-log MySQL Community Server
Windows 8.1 pro x64 all updates applied
VMWare player 6.0.3 build-1895310
Yannick Huberty Are you sure that you are using the exact same database in both instances?
ReplyDeleteYes! Absolutely! Same server, same database.. It happens that on the newer Win8.1 Upd 1 machine (where XE7 is installed), only 1574 records are retrieved resp. counted, where the next +1 value would be 5400, while on the slightly elder machine (XE6 machine, Windows installed from same .iso cd) all records are taken into account, and which gives the correct result.
ReplyDeletePutting now the PCs on same update level, nd will reinstall MySQL client libraries.
Yannick Huberty My reasoning for making sure that it was the exact same database is that you mentioned that from one VM, XE6 and XE7, returned the correct result, and from the other VM, XE6 and XE7, returned the wrong result. And, you also mentioned that using "SELECT max(coalesce(gueltig_id,99))+1 as gueltig_id FROM gueltig" gave you the same incorrect result.
ReplyDeleteTo me, this usually indicates two different databases are being used. Because, "SELECT max(coalesce(gueltig_id,99))+1 as gueltig_id FROM gueltig" is run on the server and not locally on the workstation. So, if this query gives you two different results from two different VMs, then the only logical conclusion that I can come up with, is that they are not connecting to the same database(although it could still be the same server/computer).
Compare the connection strings that you are using within both VMs, just to be certain. And, just to prove me wrong, post those connection strings here.
Daniel Rail YOU ARE RIGHT!
ReplyDeleteI did say it's the same server and database because I select the same combo-entry out of a list of available database profiles on both VMs. Fact is that the underlaying profiles (stored in a local .ini file) differred, even if the database profile name was the same (on which I based my previous answer). Simply said the .ini files had not the same content inside same-named sections.
Your comment incited me to check in detail the value of the selected database for the chosen profile, on both PCs.
Could have done it earlier... thought I simply copied the profile .ini's from one VM to the other, it seems this was definitely not the case.
+1 for you