Master-Detail & MySQL. How to get the Id of the parent tabl

Forum related to MySQL

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
wowan
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 13.04.2014, 07:53

Master-Detail & MySQL. How to get the Id of the parent tabl

Post by wowan »

Excuse me for my English .
How to get the Id of the parent table for Detail?

Hello.
Help out with a problem.
I have 2 dataset (mySQL)
1) Parent: Id (Autoincrement), Name
2) Child: Id, Id_parent (not NULL), Name
For Child organized by dbgrideh.
To configure the Child property: dsParent=Masterdetail,
MasterField=Id,
LinkedFields=Id_parent
I add new record Parent.
When doing Parent.Post, I get the error: ' Column cannot be null ' Id_Parent'
How can I find out in advance the auto-incrementing Id (Parent) and assign it a value for ID_Parent ?
wowan
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 13.04.2014, 07:53

Re: Master-Detail & MySQL. How to get the Id of the parent t

Post by wowan »

Так, зарубежные коллеги не могут помочь в решении данной проблемы. Попробуем попросить помощи у русскоязычного населения.
Перевод.

У меня 2 dataset (mySQL)
1) Parent: Id (Autoincrement), Name
2) Child: Id, Id_parent (not NULL), Name
Для таблицы Child я организовал dbgrideh на той же форме, что и текущая запись Parent.
В свойствах датасета Child проставил следующее: dsParent=Masterdetail,
MasterField=Id,
LinkedFields=Id_parent
Итак при добавлении новой записи Parent открывается эта формочка, в табличной части Child добавляю записи, связанные с Parent
Проблема в том, что на этот момент Id_parent таблицы Child неизвестна, тк не известна id таблицы Parent
Поэтому когда я делаю Parent.Post, то соответственно получаю ошибку: ' Column cannot be null ' Id_Parent'
Вопрос.
Какие есть способы (надежные) получения заранее следующего Id для Parent, ну и соответственно для Id_Parent? Сейчас оно автоинкреминируемое, соответственно заранее не известное. Так же к сожалению MySQL не поддерживает последовательности. Может есть какой то мелкий ньюанс в zeos про который я просто не знаю?
kecap
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 05.05.2012, 14:27
Location: slovakia

Re: Master-Detail & MySQL. How to get the Id of the parent t

Post by kecap »

If I understand right
You can ask your database
select LAST_INSERT_ID()
Post Reply