Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SQLDataSource.getSQLClause() bug when using includeFrom attribute on datasource field

    SmartClient*Version:*v9.0p_2014-03-06/PowerEdition Deployment*(built*2014-03-06)

    We have discovered an issue using SQLDataSource.getSQLClause() to generate SQL when using a datasource field in AdvancedCriteria that is specified using an includeFrom attribute in the datasource.

    The code originally used DSRequest.execute() on all datasources to perform the operations, but we needed to add a transaction around the operations. The code executes in a background thread, so we can't use the RPCManager to manage the transaction.

    We have a datasource that uses an includeFrom attribute to reference a foreign key column in another datasource. If I construct my DSRequest with AdvancedCriteria and pass it into SQLDataSource.getSQLClause(), the SQL is generated without the join clause on the datasource table referenced in the includeFrom. This creates invalid SQL because it is missing the join and it still uses the column name from the referenced table which doesn't exist in the primary table. If I call DSRequest.execute(), the correct SQL is generated and executed. I think DSRequest.execute() must be performing some extra logic to resolve includeFrom attributes that SQLDataSource.getSQLClause() does not perform.

    Also, if I call SQLDataSource.getSQLClause() a second time after calling DSRequest.execute(), the proper SQL is returned by SQLDataSource.getSQLClause().

    Code:
    AdvancedCriteria criteria = null;
    if (onlyAssortments != null) {
    	criteria = new AdvancedCriteria(DefaultOperators.And, new Criterion[] {
    		new SimpleCriterion("la_strategy_id", "equals", strategyId),
    		new SetCriterion("la_ast_id", "inSet", storeGradeIds)
    	});
    } else {
    	criteria = new AdvancedCriteria(DefaultOperators.And, new Criterion[] {
    		new SimpleCriterion("la_strategy_id", "equals", strategyId)
    	});
    }
    
    request = new DSRequest("ccCalcWorkDS", DataSource.OP_FETCH, rpcManager);
    request.setAdvancedCriteria(criteria);
    
    List<Map> records = null;
    ResultSet rs = null;
    Statement statement = null;
    String query = SQLDataSource.getSQLClause(SQLClauseType.All, request);
    LOG.debug(query);
    
    request.execute();
    
    LOG.debug("after request run " + SQLDataSource.getSQLClause(SQLClauseType.All, request));
    statement = connection.createStatement();
    rs = statement.executeQuery(query);
    records = SQLTransform.toListOfMaps(rs);
    Attached Files

    #2
    This is fixed now, you may download next (2014-05-02) nightly build and try it out.

    Comment


      #3
      I am having a different issue now that I've incorporated build version 4.1p-20140306.

      I have a data source with SQL clauses defined to join another table that enables storing of "favorites" for each user.

      The SQL generated for SQL Server now results in the following error:
      Code:
      Error: The multi-part identifier "LA_STRGY_FAV.FAV" could not be bound.
      SQLState:  S0001
      ErrorCode: 4104
      The error is occurring due to the generated SQL in the clause that is performing the paginated query. My prior version of the 4.0p-20140306 was generating the clause with the aliased name from the datasource, while the new library is generating it with [tablename.columnname] in the clause - which is causing the error.

      I've attached the data source and both versions of SQL.
      Attached Files

      Comment


        #4
        This is fixed now as well, you may download next (2014-05-13) nightly build and try it out.

        Comment

        Working...
        X