Delphi 7 tables added

I am working with Delphi 7 and Firebird databases. I am using TIBDatabase, TIBTransaction, TIBQuery, TIBDataSet and DBGrid to establish a connection and provide a UI to work with a table. There are two tables in my database:

Ships
fields
Id integer
Name varchar(20)
Type_Id(Fk) integer
Longth integer

Ship_types
fields
Id(Pk) integer
Ship_type varchar(10)

      

So the resulting dataset that I am getting through the join query has fields like this

Name
Type
Longth

      

Enter the Ship_type field from the Ship_types table, joined by a foreign key Type_Id query to this table from the Ships table.

The data is displayed correctly.

Then I need to edit my data directly via DBGrid. For this I am using the TIBUpdateSQL component. To display the Type (search) field, I have selected the DBGrid.Columns.PickList property.

So my question is, how can I get TIBUpdateSQL to work with this type of field? Cause. I know that if it were a separate table with no foreign keys, I should write an update statement to the ModifySQL property of the update component. But what do I do with fk fields? Can I write an update join statement in the UpdateSQL component, or if not, what else can I do?

I don't need to update the two tables, I just need to update only the Ships table, but there is a varchar (word) field in the dataset display, and when updating the dataset, it must be integer (corresponding id) to match the table structure.

An editor in TIBUpdateSQL is not a solution for me because I am assigning a TIBQuery query at runtime.

+3


source to share


1 answer


You cannot update tables using select with a JOIN, only with subqueries.

Subselection example:



SELECT TABLE_NAME.*
     , (SELECT TABLE_NAME2.NAME FROM TABLE_NAME2 WHERE TABLE_NAME2.ID = TABLE_NAME.ID)
FROM TABLE_NAME

      

+3


source







All Articles