DomaのSQLファイルでelseifやelseのブロックコメントをサポート
これまで elseif や else をラインコメントでサポートしていました。
select * from table1 where /*%if column1 != null */ column1 = /* foo */'aaa' --elseif column2 != null-- column2 = /* hoge */'aaa' --else column2 is null /*%end */
この書き方には次のような問題点がありました。
ブロックコメントをサポートしたのでこう書けます。
select * from table1 where /*%if column1 != null */ column1 = /* foo */'aaa' /*%elseif column2 != null */ and column2 = /* hoge */'aaa' /*%else */ and column2 is null /*%end */
これで問題点が解決します。
- 読みやすい
- SQLツールでcolumn2の存在チェックができる
全体としては、プログラムからは発行されることのないSQLになる(if,elseif,elseの全条件が有効なので)と思いますが、利点のほうが大きいと思います。
上のSQLは条件によって次のように変換されます。
column1 != null ならば
select * from table1 where column1 = ?
column1 == null && column2 != null ならば
select * from table1 where column2 = ?