It pains me to come here because I know I'm the least knowledgeable guy in the Forum. But I need help with this.
This is master/detail relationship stuff. In the pic below, you'll see three grids. Top: master. Other two are for details. I can make all of this work, but it's really clumsy, like a first-grader did it.
Top grid has a field
client_id. I use that as a
FK in the other two detail grids. The second grid will hold a recipe name and
client_id. And the third will hold the many ingredients for that recipe. By using the grids for all the data entry, I'm having trouble sending the
client_id from grid1 to the other two grids. This is what I have that isn't working:
procedure TForm1.SQLQuery2AfterPost(DataSet: TDataSet);
begin
SQLQuery2.Open;
SQLQuery2.FieldByName('client_id').AsInteger:=SQLQuery1.FieldByName('client_id').AsInteger;
SQLQuery2.ApplyUpdates;
SQLTransaction1.CommitRetaining;
end;
The error I get is:
SQLQuery2: Field recipe_id is required but not supplied
So to better understand that, here are the tables:
SQLQuery1.SQL.Text:='CREATE TABLE IF NOT EXISTS clients('+
'client_id INT AUTO_INCREMENT,'+
'client_email VARCHAR(50),'+
'client_password VARCHAR(50),'+
'PRIMARY KEY(client_id));';
SQLQuery1.ExecSQL;
SQLQuery1.SQL.Text:='CREATE TABLE IF NOT EXISTS recipes('+
'recipe_id INT PRIMARY KEY,'+
'client_id INT,'+
'recipe_name VARCHAR(50),'+
'FOREIGN KEY(client_id) REFERENCES clients(client_id) '+
'ON DELETE CASCADE);';
SQLQuery1.ExecSQL;
SQLQuery1.SQL.Text:='CREATE TABLE IF NOT EXISTS ingredients('+
'ingredient_id INT PRIMARY KEY,'+
'recipe_id INT,'+
'ingredient_name VARCHAR(50),'+
'amount FLOAT,'+
'FOREIGN KEY(recipe_id) REFERENCES recipes(recipe_id) '+
'ON DELETE CASCADE);';
SQLQuery1.ExecSQL;
recipe_id is suppose to be added automatically, but it isn't. And I know it's because I'm interfering with the ApplyUpdates by trying to make sure the client_id gets added to SQLQuery2. If you understand what I'm talking abt and can help, I appreciate you.