package cc.smtweb.framework.test;


import cc.smtweb.framework.core.db.sqlbuilder.SelectSqlBuilder;
import cc.smtweb.framework.core.db.sqlbuilder.SqlBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("SqlBuilder测试")
public class SqlBuilderTest {

  @Test
  public void select() {
    SelectSqlBuilder sb = SqlBuilder.createSelect("sw_im_log.im_user_msg_log");
    sb.add("uml_Id,uml_content");
    sb.addWhereOrBegin();
    sb.addWhere("uml_small_uid", 1);
    sb.addWhere("uml_big_uid", 2);
    sb.addWhereOrEnd();

    sb.exec((sql, params) -> {
      Assertions.assertEquals("select uml_Id,uml_content from sw_im_log.im_user_msg_log where (uml_small_uid=? or uml_big_uid=?)", sql);
      return true;
    });

    sb = SqlBuilder.createSelect("sw_im_log.im_user_msg_log");
    sb.add("uml_Id,uml_content");
    sb.addWhere("uml_time", 1);
    sb.addWhereOrBegin();
    sb.addWhere("uml_small_uid", 2);
    sb.addWhere("uml_big_uid", 3);
    sb.addWhereOrEnd();
    sb.addWhere("uml_id", 4);

    sb.exec((sql, params) -> {
      Assertions.assertEquals("select uml_Id,uml_content from sw_im_log.im_user_msg_log where uml_time=? and (uml_small_uid=? or uml_big_uid=?) and uml_id=?", sql);
      return true;
    });

    sb = SqlBuilder.createSelect("sw_im_log.im_user_msg_log");
    sb.add("uml_Id,uml_content");
    sb.addWhere("uml_time", 1);
    sb.addWhereOrBegin();
    sb.addWhere("uml_small_uid", 2);
    sb.addWhere("uml_big_uid", 3);
    sb.addWhereOrEnd();

    sb.exec((sql, params) -> {
      Assertions.assertEquals("select uml_Id,uml_content from sw_im_log.im_user_msg_log where uml_time=? and (uml_small_uid=? or uml_big_uid=?)", sql);
      return true;
    });

    sb = SqlBuilder.createSelect("sw_im_log.im_user_msg_log");
    sb.add("uml_Id,uml_content");
    sb.addWhereOrBegin();
    sb.addWhere("uml_small_uid", 2);
    sb.addWhere("uml_big_uid", 3);
    sb.addWhereOrEnd();
    sb.addWhere("uml_id", 4);

    sb.exec((sql, params) -> {
      Assertions.assertEquals("select uml_Id,uml_content from sw_im_log.im_user_msg_log where (uml_small_uid=? or uml_big_uid=?) and uml_id=?", sql);
      return true;
    });

  }

}
