use of com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed in project cactoos-jdbc by fabriciofx.
the class StatementInsertTest method insertWithKeysH2.
@Test
public // @checkstyle MethodNameCheck (1 line)
void insertWithKeysH2() throws Exception {
try (Server server = new ServerH2()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id INT AUTO_INCREMENT,", "name VARCHAR(50), PRIMARY KEY (id))"))).result();
MatcherAssert.assertThat("Can't insert with an integer keys", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed("INSERT INTO t02 (name) VALUES (:name)", new ParamText("name", "Jeff Malony")))), new HasValue<>(1));
}
}
use of com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed in project cactoos-jdbc by fabriciofx.
the class StatementInsertTest method insertWithKeysPsql.
@Test
public void insertWithKeysPsql() throws Exception {
try (Server server = new ServerPgsql()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id SERIAL,", "name VARCHAR(50), PRIMARY KEY (id))"))).result();
MatcherAssert.assertThat("Can't insert with an integer keys", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed("INSERT INTO t02 (name) VALUES (:name)", new ParamText("name", "Jeff Malony")))), new HasValue<>(1));
}
}
use of com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed in project cactoos-jdbc by fabriciofx.
the class ResultAsValueTest method insertWithKeys.
@Test
public void insertWithKeys() throws Exception {
try (Server server = new ServerMysql()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE contact (", "id INT AUTO_INCREMENT,", "name VARCHAR(50) NOT NULL,", "CONSTRAINT pk_contact PRIMARY KEY(id))"))).result();
MatcherAssert.assertThat("Can't get a generated key value", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed(() -> "INSERT INTO contact (name) VALUES (:name)", "id", new ParamText("name", "Leonardo da Vinci")))), new HasValue<>(BigInteger.ONE));
}
}
use of com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed in project cactoos-jdbc by fabriciofx.
the class StatementInsertTest method insertWithKeysMysql.
@Test
public void insertWithKeysMysql() throws Exception {
try (Server server = new ServerMysql()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id INT AUTO_INCREMENT,", "name VARCHAR(50), PRIMARY KEY (id))"))).result();
MatcherAssert.assertThat("Can't insert with an integer keys", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed(() -> "INSERT INTO t02 (name) VALUES (:name)", "id", new ParamText("name", "Jeff Malony")))), new HasValue<>(BigInteger.ONE));
}
}
Aggregations