Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: IN values are all null when using IN operator in mapper xml #8

Closed
enix223 opened this issue Sep 23, 2024 · 1 comment
Closed

Comments

@enix223
Copy link
Collaborator

enix223 commented Sep 23, 2024

Scenario:

When we use SQL IN with djolar query together, all in values are turn to null

Sample code:

try (SqlSession session = this.sessionFactory.openSession()) {
      setDjolarParameter(session, DjolarProperty.KEY_THROW_IF_EXPRESSION_INVALID,
        DjolarProperty.VALUE_OFF);
      BlogMapper mapper = session.getMapper(BlogMapper.class);
      QueryRequest queryRequest = new QueryRequest();
      queryRequest.setQuery("n__eq__abc1|user_id__in__1,2");
      List<Integer> ids1 = new ArrayList<>();
      ids1.add(1);
      ids1.add(2);
      ids1.add(3);
      List<Blog> results = mapper.findBlogWithIdRange(queryRequest, ids1);
      Assertions.assertEquals(1, results.size());
}

blog_mapper.xml

<select id="findBlogWithIdRange" resultType="com.enixyu.djolar.mybatis.domain.Blog"
    parameterType="list">
    SELECT `blog`.`id`, `blog`.`name`, `blog`.`user_id`
    FROM (
      SELECT `blog`.`id`, `blog`.`name`, `blog`.`user_id` FROM `blog`
      <where>
        `id` IN
        <foreach item="id" collection="ids" separator="," open="(" close=")">
          #{id, jdbcType=NUMERIC}
        </foreach>
      </where>
    ) AS `blog`
  </select>

Result:

14:50:21.702 [main] DEBUG o.a.i.t.jdbc.JdbcTransaction - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@aa10649]
14:50:21.703 [main] DEBUG c.e.d.m.m.B.findBlogWithIdRange - ==>  Preparing: SELECT `blog`.`id`, `blog`.`name`, `blog`.`user_id` FROM ( SELECT `blog`.`id`, `blog`.`name`, `blog`.`user_id` FROM `blog` WHERE `id` IN ( ? , ? , ? ) ) AS `blog` WHERE `blog`.`name` = ? AND `blog`.`user_id` IN (?,?)
14:50:21.704 [main] DEBUG c.e.d.m.m.B.findBlogWithIdRange - ==> Parameters: null, null, null, abc1(String), 1(Integer), 2(Integer)
14:50:21.705 [main] DEBUG c.e.d.m.m.B.findBlogWithIdRange - <==      Total: 0
@enix223
Copy link
Collaborator Author

enix223 commented Sep 23, 2024

Fixed fea6e53

@enix223 enix223 closed this as completed Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant