Page 1 of 1
Does InsertID works for MyTable?
Posted: Wed 20 Jun 2007 14:25
by Willo
Hi;
im trying to obtain the last id after an Mytable.Append...Mytable.Post;
but MyTable.InsertId returns 0 every time.
Any Advice?
Posted: Thu 21 Jun 2007 09:51
by Antaeus
Please make sure that your table has a columns marked as AUTO_INCREMENT. If it has, specify what options of MySQL or MyDAC have you changed. Also provide a piece of code that you use to append records.
Posted: Thu 21 Jun 2007 10:58
by Antaeus
Also specify what MyDAC version do you use.
Posted: Thu 21 Jun 2007 12:18
by Antaeus
Values for the fields marked as AUTO_INCREMENT are automatically obtained from the server, and reflected in the dataset field if the SQLInsert property is empty.
Posted: Thu 04 Oct 2007 10:45
by Poerenstamper
I'm afraid I'm having some trouble with 'InsertID' too. Some data:
- MyDAC 5 Pro
- MySQL 5.0.38
- Delphi 7
I use the TMyCommand to insert a records, in the following way:
Code: Select all
with MyCommand1 do
begin
SQL.Clear;
SQL.Add('INSERT INTO mailings (date) VALUES (NOW())');
Prepare;
Execute;
end;
The scheme of this table 'mailings' is (ID is an AUTO_INCREMENT field):
In the event handler MyCommand1AfterExecute I have:
Code: Select all
if Result then
MailingID := MyCommand1.InsertId;
Now the problem: the first I insert a record, MailingID remains the default value (0), however the second time it works just fine.
I tried several things, like refreshes and so on, but the result stays the same.
Thanks in advance for your answers!
Wessel
Posted: Thu 04 Oct 2007 12:48
by Poerenstamper
Poerenstamper wrote:..however the second time it works just fine.
Actually, that was a bit too optimistic; every n'th time the (n-1)'th ID is retrieved. So the second time, the inserted ID from the first try is returned.
Posted: Fri 05 Oct 2007 12:15
by Antaeus
Thank you for information. We have reproduced this problem. The investigation of the problem is in progress. As soon as we solve it, we will let you know.
Posted: Fri 05 Oct 2007 12:29
by Poerenstamper
Thank you very much!
Posted: Fri 19 Oct 2007 12:36
by Antaeus
We have fixed this problem. This fix will be included in the next MyDAC build. Please watch for announcements at the forum.
Posted: Fri 19 Oct 2007 12:40
by Poerenstamper
Very nice, thanks!