Print Thread
New row in TOracleDataSet with SQL JOIN
#48420 12/30/13 08:50 AM
Joined: Mar 2013
Posts: 8
N
nrsgzz Offline OP
Member
OP Offline
Member
N
Joined: Mar 2013
Posts: 8
Hi all.

How can I insert a new row in a dataset when it is formed by multiple tables connected with a JOIN statement?
For example I have this SQL

SQL Query
SELECT t1.rowid, t1.name, t1.address, t1.age, t2.role FROM t1, t2 WHERE t1.id = t2.id

I want to be able to insert a new row in table t1 via a data aware grid (devexpress cxgrid to be precise).
However, even if I fill out the UpdatingTable property, the INSERT operation fails because the dataset tries to include columns from table t2.

Is there any way to accomplish this?

Re: New row in TOracleDataSet with SQL JOIN
nrsgzz #48421 12/30/13 10:42 AM
Joined: Aug 1999
Posts: 22,220
Member
Offline
Member
Joined: Aug 1999
Posts: 22,220
You can set TOracleDataSet.OracleDictionary.FieldKinds to True:

[quote]property FieldKinds: Boolean;
Automatically check which fields belong to the updating table. These fields will become data fields (FieldKind = fkData), and all other fields will become read-only InternalCalc fields (FieldKind = fkInternalCalc).[/quote]


Marco Kalter
Allround Automations
Re: New row in TOracleDataSet with SQL JOIN
Marco Kalter #48431 01/01/14 10:50 AM
Joined: Mar 2013
Posts: 8
N
nrsgzz Offline OP
Member
OP Offline
Member
N
Joined: Mar 2013
Posts: 8
Thank you, exactly what I needed.

Re: New row in TOracleDataSet with SQL JOIN
nrsgzz #48432 01/01/14 03:27 PM
Joined: Mar 2013
Posts: 8
N
nrsgzz Offline OP
Member
OP Offline
Member
N
Joined: Mar 2013
Posts: 8
The solution works however I realized it is not exactly what I want. Using the previous SQL as example:

SQL Query
SELECT t1.rowid, t1.name, t1.address, t1.age, t2.role FROM t1, t2 WHERE t1.id = t2.id

Using the FieldKinds property allows me to post data to the right table but it also makes the column from t2 a read-only field! This means no value can be selected and I actually need that value further on.
Is there any way around this problem?

Thank you.

Re: New row in TOracleDataSet with SQL JOIN
nrsgzz #48434 01/02/14 11:17 AM
Joined: Aug 1999
Posts: 22,220
Member
Offline
Member
Joined: Aug 1999
Posts: 22,220
What exactly do you mean by "no value can be selected"?


Marco Kalter
Allround Automations
Re: New row in TOracleDataSet with SQL JOIN
Marco Kalter #48436 01/02/14 11:59 AM
Joined: Mar 2013
Posts: 8
N
nrsgzz Offline OP
Member
OP Offline
Member
N
Joined: Mar 2013
Posts: 8
The columns that do not belong to the UpdatingTable have become read only thus cannot be modified in the data-aware grid.
However I need to be able to select a value and pass it to the OnBeforePost() event for further manipulation

Re: New row in TOracleDataSet with SQL JOIN
nrsgzz #48437 01/03/14 01:14 PM
Joined: Aug 1999
Posts: 22,220
Member
Offline
Member
Joined: Aug 1999
Posts: 22,220
I haven't tried this, but what happens if you disable TField.ReadOnly for the fkInternalCalc field?


Marco Kalter
Allround Automations

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.040s Queries: 14 (0.014s) Memory: 2.5252 MB (Peak: 3.0430 MB) Data Comp: Off Server Time: 2024-05-18 20:45:28 UTC
Valid HTML 5 and Valid CSS