Howto get dependent table rows

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Howto get dependent table rows

BOEVINK Peter

Hi,

 

I have a lot of tables with foreign key relations. For this example, suppose I've a USER table and an ADDRESS table:

 

ADDRESS

|id|street            |nr |city                 |

=========================

|1|Abbeystreet|2  |London          |

|2|Amstelstraat|12|Amsterdam|

 

USER

|id|name                      |address(FK)|

==========================

|1|Charlie Chaplin     |1                      |

|2|Shirley Chaplin      |1                     |

|3|Vincent van Gogh|2                     |

|4|Theo van Gogh     |2                      |

 

 

I've succesfully exported all data and its dependent tables using the USER table as 'main' table:

QueryDataSet queryDataSetToExport = new QueryDataSet(connection);

String[] depTableNames = TablesDependencyHelper.getAllDependentTables( connection, "USER" );

for (String tableName : depTableNames) {

      queryDataSetToExport.addTable(tableName);

}

 

But now comes my problem. I would like to export only the data of USER 'Vincent van Gogh'  but including its dependent data (address).

I know I could use a QueryDataSet to do a select, but how to resolve the dependent table rows without exporting the addresses I'm not interrested in?

QueryDataSet queryDataSetToExport = new QueryDataSet(connection);

queryDataSetToExport.addTable("USER", "SELECT * FROM USER WHERE name='Vincent van Gogh'");

 

Does anybody have a solution for this?

 

Thanks.

 



------------------------------------------------------------------------------------------------------------
Disclaimer:

If you are not the intended recipient of this email, please notify the sender and delete it. 
Any unauthorized copying, disclosure or distribution of this email or its attachment(s) is forbidden. 
Thales Nederland BV will not accept liability for any damage caused by this email or its attachment(s). 
Thales Nederland BV is seated in Hengelo and is registered at the Chamber of Commerce under number 06061578.
------------------------------------------------------------------------------------------------------------


------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user