Page 1 of 1

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

Posted: Mon 05 Nov 2007 15:38
by iskywalker
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.

Posted: Mon 05 Nov 2007 16:19
by Antaeus
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;

Posted: Tue 06 Nov 2007 08:11
by iskywalker
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!

Posted: Tue 06 Nov 2007 13:14
by Antaeus
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.

Posted: Wed 07 Nov 2007 17:34
by iskywalker
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

Posted: Fri 09 Nov 2007 09:04
by Antaeus
Thank you, we will fix this in the next MyDAC build.