Search in sources :

Example 16 with SqlToyResult

use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.

the class SqlConfigParseUtilsTest method testProcessSql.

@Test
public void testProcessSql() {
    String sql = FileUtil.readFileAsStr("classpath:scripts/ifScriptSql.sql", "UTF-8");
    SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { null, "chen", "1" });
    System.err.println("id==null:" + JSON.toJSONString(result));
    SqlToyResult result1 = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { "1", "chen", "1" });
    System.err.println("id<>null:" + JSON.toJSONString(result1));
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult) Test(org.junit.jupiter.api.Test)

Example 17 with SqlToyResult

use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.

the class SqlConfigParseUtilsTest method testNull.

@Test
public void testNull() throws Exception {
    String sql = "select * from table where 1=1 #[and id=:id and name like :name] #[and status=:status]";
    SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { "1", null, "1" });
    System.err.println(JSON.toJSONString(result));
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult) Test(org.junit.jupiter.api.Test)

Example 18 with SqlToyResult

use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.

the class SqlConfigParseUtilsTest method testOptSign.

@Test
public void testOptSign() throws Exception {
    String sql = "select * from table where #[id=id+:id ]#[and name like :name] #[and status=:status]";
    SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { "1", null, "1" });
    System.err.println(JSON.toJSONString(result));
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult) Test(org.junit.jupiter.api.Test)

Example 19 with SqlToyResult

use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.

the class SqlConfigParseUtilsTest method testLoop.

@Test
public void testLoop() throws Exception {
    String sql = "select * from table where #[id=:id and name like :name] #[and @loop(:status,' status=':status[i]'','or')]";
    SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { "1", null, new Object[] { "1", "2", "3" } });
    System.err.println(JSON.toJSONString(result));
    result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { "1", null, null });
    System.err.println(JSON.toJSONString(result));
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult) Test(org.junit.jupiter.api.Test)

Example 20 with SqlToyResult

use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.

the class SqlConfigParseUtilsTest method testAllNull.

@Test
public void testAllNull() throws Exception {
    String sql = "select * from table where #[id=:id and name like :name] #[and status=:status]";
    SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { null, null, null });
    System.err.println(JSON.toJSONString(result));
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult) Test(org.junit.jupiter.api.Test)

Aggregations

SqlToyResult (org.sagacity.sqltoy.config.model.SqlToyResult)74 QueryExecutorExtend (org.sagacity.sqltoy.model.inner.QueryExecutorExtend)19 List (java.util.List)16 ArrayList (java.util.ArrayList)15 SqlToyConfig (org.sagacity.sqltoy.config.model.SqlToyConfig)12 Connection (java.sql.Connection)11 DataSourceCallbackHandler (org.sagacity.sqltoy.callback.DataSourceCallbackHandler)11 QueryResult (org.sagacity.sqltoy.model.QueryResult)11 Test (org.junit.jupiter.api.Test)9 EntityMeta (org.sagacity.sqltoy.config.model.EntityMeta)8 BaseException (org.sagacity.sqltoy.exception.BaseException)6 SqlWithAnalysis (org.sagacity.sqltoy.config.model.SqlWithAnalysis)5 DataAccessException (org.sagacity.sqltoy.exception.DataAccessException)5 Type (java.lang.reflect.Type)4 HashMap (java.util.HashMap)4 OneToManyModel (org.sagacity.sqltoy.config.model.OneToManyModel)4 TableCascadeModel (org.sagacity.sqltoy.config.model.TableCascadeModel)4 DBType (org.sagacity.sqltoy.utils.DataSourceUtils.DBType)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2