Sometimes, it's more convenient to call a sequence of SQL statements from within Talend Open Studio instead of through a command line tool like sqlplus. In a previous post, I wrote about using the tFileInputDelimited component to drive the processing. This post suggests using the tFixedFlowInput component with the statements embedded in the Component View.
Basic Job
This job uses an open/process/commit/close pattern on a datasource defined in the Metadata panel. tFixedFlowInput defines a list and uses each iteration to produce a flow record. Each flow record is a valid DDL String -- in this case a DELETE -- which is executed by a tMysqlRow. Once the flow is finished, the results are committed and the connection closed.
Job with tFixedFlowInput |
The list of SQL statements can be defined using a structured editor (Inline Table) or as a block of text (Inline Content). In the Inline Table, each UI row renders an element. In this example, there is only a single field containing the SQL statement, but there could be more than one field.
Inline Table Config of tFixedFlowInput |
Inline Content Config of tFixedFlowInput |
To execute the SQL, output the sqlStatement field of row1. The tFixedFlowInput schema defines a single "sqlStatement" field that is of type String.
tMysqlRow Executing Statement from row1 |
Hi Carl, How can I capture the error that a particular sql statement generates?
ReplyDeleteI know I can use logcatcher with tsendmail, but I want to make sure that I capture the error sql statement and throw that in the email.
Right now I have a tFixedFlowInput -> tMysqlRow -> tJavaRow
tMysqlRow executes the sql statement.
The tJavaRow reads
String progress = (String)globalMap.get("storedProcedureProgress");
if(progress == null) {
progress = "";
}
globalMap.put("storedProcedureProgress", progress + "\nCompleted Step: " + row12.sqlcommand);
(row12 connects tMysqlRow -> tJavaRow)
I'm using the tMySqlRow to call a bunch of stored procedures one after the other.
Even with this approach, I get the last successfully executed sql statement but not the one that errored out. Any ideas?
Take a look at a recent post titled "Handling Database Warnings with Talend Open Studio". See if you can use a Run If after the Row components.
ReplyDeleteSry to be a smartass, but Selete is DML (Data Manipulation) not DDL (Data Definition). As i was searching for DDL possibilities i got stuck here :)
ReplyDeleteYep. This is Part 2 of a post that does feature a DDL ALTER TABLE statement (and more DML). http://bekwam.blogspot.com/2011/02/running-file-of-sql-statements-with.html
DeleteYou might find this DDL-oriented post interesting:
http://bekwam.blogspot.com/2011/10/controlling-ddl-behind-talend-open.html