Get output of TMSSqlRow in Talend

戏子无情 提交于 2019-12-24 09:23:11

问题


I would like to get the number of row affected / deleted / updated with a TMSSqlRow.

Here is how the job is:

the file use contains a lot of sql statement like DELETE ... INSERT ... UPDATE... each row are separate by ";"

But now, I would like to get result of each statement (x rows updated, like results are display in management studio).

When I go to "advanced settings" tab of tmssqlrow, I select " Propagate QUERY's recordset" and select a column I created before (Object Type).

On execution, I have this error:

The executeQuery method must return a result set.

So, how I can get the result of each statement and insert it (by example) in a database / file?


回答1:


The option "Propagate QUERY's recordset" must be used in combination with a tParseRecordSet in order to extract info from the returned recordset. However, that is not sufficent: you must explicitly write the query to return the number of records updated/deleted.

Here's what I did:

My tJDBCRow (same as tMSSqlRow) query looks like this (notice how I had to add 'set nocount on' before the update query, and 'select @@rowcount' after)

tParseRecordSet retrieves the number of lines from the column resultset (nbLines is the alias of my rowcount)




回答2:


If you need the number of rows affected, a better option is to use the tMSSqlOutput component which can update,insert or delete rows. After execution, the component provides global variables to show how many rows were affected by the operation.

((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE")) 
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_UPDATED"))   
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_INSERTED"))    
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_DELETED"))


来源:https://stackoverflow.com/questions/48110549/get-output-of-tmssqlrow-in-talend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!