mirage-sql/mirage

How to use arrays as parameters?

Closed this issue · 2 comments

Please give an example how to use arrays as parameters in dynamic sqls.

Looking at "ParenBindVariableNode.java" seems to be possible to use arrays and lists as parameters.

Thanks in advance.

You can use the Array property as IN parameter as same as the List property.

For example, here is the Java code to invoke the SQL file which has an IN parameter:

public static class BookNamesParam {
  public String[] bookNames;
}

BookNamesParam param = new BookNamesParam();
param.bookNames = new String[]{"Mirage in Action", "Essential Mirage" };

List<Book> results = sqlManager.getResultList(
  Book.class,
  SQL_PREFIX + "SqlManagerImplTest_selectByBookNames.sql",
  param);

The SQL file is below:

SELECT BOOK_ID, BOOK_NAME, AUTHOR, PRICE
FROM BOOK
/*IF bookName != null*/
WHERE BOOK_NAME IN /*bookNames*/('Mirage in Action')
/*END*/

Thank you very much for the very quick response :).