Announcement

Collapse
No announcement yet.

executeUpdate in transformer script for 1.71

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • executeUpdate in transformer script for 1.71

    In 1.70 exec of a sql command to do a Replace into MySQL via executeUpdate in a transformer script returned the number of rows affected by the operation. After installing the upgrade to 1.71 I am seeing that the SQL command executes and a new row or an update occurs into the MySQL database just as before but the result returns 0 where I would have expected it to return 1 if only 1 record was inserted. Has anyone else noticed this?

  • #2
    Re:executeUpdate in transformer script for 1.71

    This must be a problem on your end. The code has not changed in years:

    Code:
    	public int executeUpdate(String expression, List<Object> parameters) throws SQLException {
    		PreparedStatement statement = null;
    
    		try {
    			statement = connection.prepareStatement(expression);
    			logger.debug("executing prepared statement:\n" + expression);
    
    			ListIterator<Object> iterator = parameters.listIterator();
    
    			while (iterator.hasNext()) {
    				int index = iterator.nextIndex() + 1;
    				Object value = iterator.next();
    				logger.debug("adding parameter: index=" + index + ", value=" + value);
    				statement.setObject(index, value);
    			}
    
    			boolean results = statement.execute();
    			if (results){
    				return 1;
    			}else{
    				return 0;
    			}
    		} catch (SQLException e) {
    			throw e;
    		} finally {
    			DatabaseUtil.close(statement);
    		}
    	}
    Code:
    	public int executeUpdate(String expression) throws SQLException {
    		Statement statement = null;
    
    		try {
    			statement = connection.createStatement();
    			logger.debug("executing update:\n" + expression);
    			boolean results = statement.execute(expression);
    			if (results){
    				return 1;
    			}else{
    				return 0;
    			}
    		} catch (SQLException e) {
    			throw e;
    		} finally {
    			DatabaseUtil.close(statement);
    		}
    	}
    Post edited by: brendanh, at: 04/24/2008 15:39
    Brendan Haverlock | Mirth Software Engineer | Mirth Corporation

    Comment


    • #3
      Re:executeUpdate in transformer script for 1.71

      It turns out that the display of errors in the dashboard just made the problem I hit with executeUpdate more evident in 1.71 though even in 1.70 an executeUpdate of a sql command for MySQL to UPDATE, INSERT or REPLACE into a table always returns a zero result. My expectation was that it would return the number of rows affected as an integer. In the code segment that you provided the result is forced to boolean.

      When I use the code below in either 1.70 or 1.71 the database operation succeeds but always returns a result of zero. I admit that Java is not my forte but to me what I have used to code should work from all the docs I've read.

      Code:
      var iresult = dbConn.executeUpdate(sql_cmd);
      
      if (iresult)
      	{
      	logger.error("**** SQL SUCCESS ****:" + sql_cmd + " RESULT=" + iresult.toString());
      	}
      else
      	{
      	logger.error("**** SQL FAILED ****:" + sql_cmd + " RESULT=" + iresult.toString());
      	}

      Comment


      • #4
        Re:executeUpdate in transformer script for 1.71

        You mean in the code I provided, the result is boolean and then forced to int? Does JS work like C where ints are implicitly converted to true if they are != 0? If not, maybe you should try checking if result == 1.
        Brendan Haverlock | Mirth Software Engineer | Mirth Corporation

        Comment


        • #5
          Re:executeUpdate in transformer script for 1.71

          Whether the exec succeeds or fails I print out the value of the result to the log and it always returns 0 no matter what succeed of fail. Testing with == 1 will also therefore fail. Bottom line, it looks like the executeUpdate never returns anything other than zero.

          Comment

          Working...
          X