insertid works with debug mode one, without it returns always 0

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
iskywalker
Posts: 16
Joined: Mon 25 Jun 2007 15:00

insertid works with debug mode one, without it returns always 0

Post by iskywalker » Mon 05 Nov 2007 15:38

After using TMyCommand with the insert command, insertid is only different to 0 if the program is compiled with debug info.
Got the newest (520) mydac build, and could reproduce it.
Some idea what i could do wrong?
It seems i must compiledf with assertion on!!!
Why that? Is there any workaround?
I found the place where the assertion take places:
procedure TMyCommand.Execute(Iters: integer);
var
v: variant;
begin
BeginConnection;
try
inherited;

Assert(Connection.IConnection.GetProp(prLastInsertId, v));
{$IFDEF VER6P}
FInsertId := v;
{$ELSE}
FInsertId := PInt64(@TVarData(v).VInteger)^;
{$ENDIF}
finally
EndConnection;
end;
end;
Is there anyway to get the info that is stored in v outside myaccess.pas?
Since i normally work with asssertion off.
Thx in advance.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 05 Nov 2007 16:19

There is a known bug with the InsertId value in the AfterExecure event. It will be fixed in the next build of MyDAC.

With the current MyDAC build the following code should work correctly:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  MyCommand1.Execute;
  ShowMessage(IntToStr(MyCommand1.InsertId));
end;

iskywalker
Posts: 16
Joined: Mon 25 Jun 2007 15:00

Post by iskywalker » Tue 06 Nov 2007 08:11

Well it works already, but only if i set the assertion flag in delphi project options (compiler), normally this isnt needed!
The assert function will only be used (activated) if the assert flag is set.
So the code below will be only executed if this flag is set:
Assert(Connection.IConnection.GetProp(prLastInsertId, v));
I wonder why! since it should work without the assert flag, or?
Thx for the Answer!

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 06 Nov 2007 13:14

Disabling this flag is not a solution.
Could you send us a complete small sample at mydac*crlab*com to demonstrate the problem, including script to create and fill tables used in the sample? It is necessary for us to make sure that the problem has been fixed completely.

Also supply the following information:
- exact version of MyDAC. You can see it in the About sheet of TMyConnection Editor;
- exact version of your IDE;
- exact version of MySQL server and MySQL client. You can see it in the Info sheet of TMyConnection Editor.

iskywalker
Posts: 16
Joined: Mon 25 Jun 2007 15:00

Post by iskywalker » Wed 07 Nov 2007 17:34

Hi!
http://delphi.about.com/library/rtl/blrtlAssert.htm
There is written:
Since assertions are not usually used in final product version, Delphi compiler includes directives to disable the generation of assertion code:

$ASSERTIONS ON/OFF (long form)

But you use in the source code:
Assert(Connection.IConnection.GetProp(prLastInsertId, v));
So if the assert would be deleted and only
if not Connection.IConnection.GetProp(prLastInsertId, v) then
DatabaseError('Couldn't get Property);


Thx

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Fri 09 Nov 2007 09:04

Thank you, we will fix this in the next MyDAC build.

Post Reply