mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
52 lines
1.7 KiB
Java
52 lines
1.7 KiB
Java
package com.mysema.query.sql;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import org.junit.Test;
|
|
|
|
import com.mysema.query.sql.domain.QSurvey;
|
|
import com.mysema.query.types.expr.Param;
|
|
|
|
public class SQLBindingsTest {
|
|
|
|
private QSurvey survey = QSurvey.survey;
|
|
|
|
private SQLQuery query = new SQLQuery(SQLTemplates.DEFAULT);
|
|
|
|
@Test
|
|
public void Empty() {
|
|
SQLBindings bindings = query.getSQL();
|
|
assertEquals("\nfrom dual", bindings.getSQL());
|
|
assertTrue(bindings.getBindings().isEmpty());
|
|
}
|
|
|
|
@Test
|
|
public void SingleArg() {
|
|
query.from(survey).where(survey.name.eq("Bob"));
|
|
SQLBindings bindings = query.getSQL(survey.id);
|
|
assertEquals("select SURVEY.ID\nfrom SURVEY SURVEY\nwhere SURVEY.NAME = ?", bindings.getSQL());
|
|
assertEquals(Arrays.asList("Bob"), bindings.getBindings());
|
|
}
|
|
|
|
@Test
|
|
public void TwoArgs() {
|
|
query.from(survey).where(survey.name.eq("Bob"), survey.name2.eq("A"));
|
|
SQLBindings bindings = query.getSQL(survey.id);
|
|
assertEquals("select SURVEY.ID\nfrom SURVEY SURVEY\nwhere SURVEY.NAME = ? and SURVEY.NAME2 = ?", bindings.getSQL());
|
|
assertEquals(Arrays.asList("Bob", "A"), bindings.getBindings());
|
|
}
|
|
|
|
@Test
|
|
public void Params() {
|
|
Param<String> name = new Param<String>(String.class, "name");
|
|
query.from(survey).where(survey.name.eq(name), survey.name2.eq("A"));
|
|
query.set(name, "Bob");
|
|
SQLBindings bindings = query.getSQL(survey.id);
|
|
assertEquals("select SURVEY.ID\nfrom SURVEY SURVEY\nwhere SURVEY.NAME = ? and SURVEY.NAME2 = ?", bindings.getSQL());
|
|
assertEquals(Arrays.asList("Bob", "A"), bindings.getBindings());
|
|
}
|
|
}
|