
Anonymous
Not applicable
2013-05-28
11:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[resolved] Delete MySQL row on condition
Hi,
I have a simple tMap between 2 different MySQL databases.
When a row from DB1 (input) is inserted (after mapping) into DB2 (output) with no error, I want the row from DB1 to be deleted. However, the ID from DB1 is not sent to DB2, and I don't know how to get this ID.
Is anyone can help me ?
I have a simple tMap between 2 different MySQL databases.
When a row from DB1 (input) is inserted (after mapping) into DB2 (output) with no error, I want the row from DB1 to be deleted. However, the ID from DB1 is not sent to DB2, and I don't know how to get this ID.
Is anyone can help me ?
245 Views
1 Solution
Accepted Solutions

Specialist
2013-05-30
04:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use a row link instead of OnComponentOk.
You can perhaps also pass the ID to the tMysqlOuput for DB2 but use the "Field options" in the advanced settings to not insert it, then it is available to pass through to another tMysqlOuput for the deletion from DB1.
Or just have a second flow from the tMap to another tMysqlOuput for the deletion from DB1.
You can perhaps also pass the ID to the tMysqlOuput for DB2 but use the "Field options" in the advanced settings to not insert it, then it is available to pass through to another tMysqlOuput for the deletion from DB1.
Or just have a second flow from the tMap to another tMysqlOuput for the deletion from DB1.
245 Views
6 Replies

Anonymous
Not applicable
2013-05-28
12:43 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two obvious ways to do this:
1) Iterate over each row from DB1. For each row, do the transform save the ID to a context variable. If successfully inserted to DB2, execute a delete statement on DB1 using the saved ID.
2) Maintain a list of ID's from DB1 that were successfully inserted, Then delete after all rows have been processed. This can be done within memory in Talend by using a tHashOutput/tHashInput pair. Alternatively, you could write the successful inserts ID's to file and re-read it once done.
1) Iterate over each row from DB1. For each row, do the transform save the ID to a context variable. If successfully inserted to DB2, execute a delete statement on DB1 using the saved ID.
2) Maintain a list of ID's from DB1 that were successfully inserted, Then delete after all rows have been processed. This can be done within memory in Talend by using a tHashOutput/tHashInput pair. Alternatively, you could write the successful inserts ID's to file and re-read it once done.
245 Views

Anonymous
Not applicable
2013-05-29
06:50 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. I tried the first solution.
See what I've done in attached screenshot .
I save the ID in the tMap and I use it in the tMySQLRow (deleteProcessedEvent)
But I don't know how to execute deleteProcessedEvent for each row inserted.
I tried OnComponentOk but it is executed once the all rows have been inserted, so it delete only the last one.
See what I've done in attached screenshot .
I save the ID in the tMap and I use it in the tMySQLRow (deleteProcessedEvent)
But I don't know how to execute deleteProcessedEvent for each row inserted.
I tried OnComponentOk but it is executed once the all rows have been inserted, so it delete only the last one.
245 Views

Specialist
2013-05-30
04:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use a row link instead of OnComponentOk.
You can perhaps also pass the ID to the tMysqlOuput for DB2 but use the "Field options" in the advanced settings to not insert it, then it is available to pass through to another tMysqlOuput for the deletion from DB1.
Or just have a second flow from the tMap to another tMysqlOuput for the deletion from DB1.
You can perhaps also pass the ID to the tMysqlOuput for DB2 but use the "Field options" in the advanced settings to not insert it, then it is available to pass through to another tMysqlOuput for the deletion from DB1.
Or just have a second flow from the tMap to another tMysqlOuput for the deletion from DB1.
246 Views

Anonymous
Not applicable
2013-05-30
10:46 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! It works!
However, how do I know if the row is deleted only if the insert succeed ?
What happen if an error occurs ? Is the row deleted anyway ?
However, how do I know if the row is deleted only if the insert succeed ?
What happen if an error occurs ? Is the row deleted anyway ?
245 Views

Specialist
2013-05-30
08:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the insert fails, the tMysqlOuput will not pass a row on to any following components and so they will not do anything. This is easy enough to test.
245 Views

Anonymous
Not applicable
2013-05-31
12:07 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for you answer.
Indeed, I could test it by myself.
Indeed, I could test it by myself.
245 Views
