<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Logging errors and affected rows from INSERT,UPDATE,DELETE statements. in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Logging-errors-and-affected-rows-from-INSERT-UPDATE-DELETE/m-p/2414625#M140101</link>
    <description>&lt;P&gt;If I understand the problem well, the reject row will not be triggered if the connection is OK, in your case, you mentioned the connection 1 and connection 2 is ok, but the connection 3 is failed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About the second question, you can add a tJavaFlex replace of tLogRow (or after tLogRow), define a counter on tJavaFlex, +1 for each row, store the counter to a global variable for used later in next subjob. eg:&lt;/P&gt;
&lt;P&gt;in the begin part:&lt;/P&gt;
&lt;P&gt;int total_rows=0;&lt;/P&gt;
&lt;P&gt;in the main part:&lt;/P&gt;
&lt;P&gt;total_rows++;&lt;/P&gt;
&lt;P&gt;in the end part:&lt;/P&gt;
&lt;P&gt;globalMap.put("key",total_rows);&lt;/P&gt;
&lt;P&gt;After all the connections are iterated completed, write the&amp;nbsp;&lt;SPAN&gt;Total amount of rows in the output.csv.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;listConnections....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;|onsubjobok&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;tFixedFlowInput--main--tFileOutputDelimited&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2024 07:47:34 GMT</pubDate>
    <dc:creator>Shicong_Hong</dc:creator>
    <dc:date>2024-02-05T07:47:34Z</dc:date>
    <item>
      <title>Logging errors and affected rows from INSERT,UPDATE,DELETE statements.</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Logging-errors-and-affected-rows-from-INSERT-UPDATE-DELETE/m-p/2413756#M140086</link>
      <description>&lt;P&gt;Hi Community&lt;BR /&gt;&lt;BR /&gt;My goal with the job I need help with is to first add a "title" to a output.csv file. Then in the next step I have a list of database connections that I iterate over and for each of the connection I will run a INSERT query with the tdbrow component for each connection. For each connection I want to append a row to the output.csv file for each connection where I log following. Database connection succesful yes or no. Was there any SQL errors? If yes print errorMessage if no leave empty. If the execution was successful I also want to log the amount of Affected rows.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;In the pictures you can see what I tried so far. &lt;BR /&gt;&lt;BR /&gt;In tJavaFlex_1 I catch if a connection Problem occurs and if that's true I will print that in tLogRow3 (works fine).&lt;BR /&gt;The tDBRow_4 is set to not die on error and it will return a resultSet. I always add returning '1' as rows in the end of my Inserts queries. In tLogRow4 I am then able to see the amount of Inserted rows.&amp;nbsp;&lt;BR /&gt;From tDBRow_4 I also have a reject link that should catch SQL Error and their errorMessages.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;To try everything I have created a test where I have 3 connections&amp;nbsp;&lt;SPAN&gt;where connection 1 and 2 are ok but the 3rd&amp;nbsp; should fail. In this example im running a INSERT INTO custom.test_etl (msg) VALUES('test'), ('jf') returning '1' as rows; query in tdbrow_4. The second connection should cause a SQL Error since the table doesn't exists in that database. &lt;BR /&gt;&lt;BR /&gt;So my wished/expected output should be:&lt;BR /&gt;Connection 1&amp;nbsp;should successfully insert 2 rows and give two lines (rows) with information about the resultSet object and the rows im returning with returning '1' as rows.&amp;nbsp;&lt;BR /&gt;Connection 2 should be rejected an print errorMessage in tLogRow_1&lt;BR /&gt;Connection 3 to show an errorMessage in&amp;nbsp;tLogRow_3&lt;BR /&gt;&lt;BR /&gt;This is what it actually returns:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CONNECTION 1&lt;BR /&gt;tLogRow_4&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;+-------------------------------------------+------+&lt;BR /&gt;| resultSet | rows |&lt;BR /&gt;+-------------------------------------------+------+&lt;BR /&gt;| org.postgresql.jdbc.PgResultSet@50675690 | 1 |&lt;BR /&gt;| org.postgresql.jdbc.PgResultSet@50675690 | 1 |&lt;BR /&gt;+-------------------------------------------+------+&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;tLogRow_1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;+-----------+------+-----------+-------------+&lt;BR /&gt;| resultSet | rows | errorCode | errorMessage |&lt;BR /&gt;+-----------+------+-----------+-------------+&lt;BR /&gt;| | | | |&lt;BR /&gt;+-----------+------+-----------+-------------+&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;CONNECTION 2&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;tLogRow_4&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;+-----------+------+&lt;BR /&gt;| resultSet | rows |&lt;BR /&gt;+-----------+------+&lt;BR /&gt;|&amp;nbsp; |&amp;nbsp; |&lt;BR /&gt;+-----------+------+&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;tLogRow_1&lt;/SPAN&gt;&lt;BR /&gt;+-----------+------+-----------+-------------------------------------------------------------------+&lt;BR /&gt;| resultSet | rows | errorCode | errorMessage |&lt;BR /&gt;+-----------+------+-----------+-------------------------------------------------------------------+&lt;BR /&gt;| null | null | 42P01 | ERROR: relation "custom.test_etl" does not exist Position: 13 - Line: 0 |&lt;BR /&gt;+-----------+------+-----------+-------------------------------------------------------------------+&lt;BR /&gt;&lt;BR /&gt;CONNECTION 3&lt;BR /&gt;&lt;SPAN&gt;tLogRow_3&lt;/SPAN&gt;&lt;BR /&gt;+---------------------------------+&lt;BR /&gt;| errorMessage |&lt;BR /&gt;+---------------------------------+&lt;BR /&gt;| The connection attempt failed. |&lt;BR /&gt;+---------------------------------+&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So first question is why does connection 1 and 2 return a result from both tLogRow_1 and tLogRow_4 when connection 1 wasn't rejected and connection 2 was rejected? I was expecting connection 1 not to trigger the reject path and the same for connection 2 but to not trigger the "success" path.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Next question: When the first question is solved I have the infos that I need to make a insert in the output.csv file. I could add a tmap after each tlogrow component and then map it to tfileoutputdelimited and append my rows. But I have one big challenge left. As it is now i would insert two rows for the Success story since&amp;nbsp;tLogRow_4 returns two rows. That's not what I want. I want the Total amount of rows to be inserted with only 1 entry in the output.csv. The total I can only access after the subjob is finished with&amp;nbsp;globalMap.get("tParseRecordSet_3_NB_LINE"). I have no idea how to solve this since I have to somehow be able to get this value inside the loop for each connection but still it's not accessable inside the loop...Does someone have a good idea?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I add some pictures with important information. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 22:10:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Logging-errors-and-affected-rows-from-INSERT-UPDATE-DELETE/m-p/2413756#M140086</guid>
      <dc:creator>jensej</dc:creator>
      <dc:date>2024-02-01T22:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Logging errors and affected rows from INSERT,UPDATE,DELETE statements.</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Logging-errors-and-affected-rows-from-INSERT-UPDATE-DELETE/m-p/2414625#M140101</link>
      <description>&lt;P&gt;If I understand the problem well, the reject row will not be triggered if the connection is OK, in your case, you mentioned the connection 1 and connection 2 is ok, but the connection 3 is failed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About the second question, you can add a tJavaFlex replace of tLogRow (or after tLogRow), define a counter on tJavaFlex, +1 for each row, store the counter to a global variable for used later in next subjob. eg:&lt;/P&gt;
&lt;P&gt;in the begin part:&lt;/P&gt;
&lt;P&gt;int total_rows=0;&lt;/P&gt;
&lt;P&gt;in the main part:&lt;/P&gt;
&lt;P&gt;total_rows++;&lt;/P&gt;
&lt;P&gt;in the end part:&lt;/P&gt;
&lt;P&gt;globalMap.put("key",total_rows);&lt;/P&gt;
&lt;P&gt;After all the connections are iterated completed, write the&amp;nbsp;&lt;SPAN&gt;Total amount of rows in the output.csv.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;listConnections....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;|onsubjobok&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;tFixedFlowInput--main--tFileOutputDelimited&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 07:47:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Logging-errors-and-affected-rows-from-INSERT-UPDATE-DELETE/m-p/2414625#M140101</guid>
      <dc:creator>Shicong_Hong</dc:creator>
      <dc:date>2024-02-05T07:47:34Z</dc:date>
    </item>
  </channel>
</rss>

