Search in sources :

Example 1 with StatementInsertKeyed

use of com.github.fabriciofx.cactoos.jdbc.statement.StatementInsertKeyed 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));
    }
}
Also used : StatementInsertKeyed(com.github.fabriciofx.cactoos.jdbc.statement.StatementInsertKeyed) ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) Server(com.github.fabriciofx.cactoos.jdbc.Server) StatementUpdate(com.github.fabriciofx.cactoos.jdbc.statement.StatementUpdate) ServerMysql(com.github.fabriciofx.cactoos.jdbc.server.ServerMysql) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) Joined(org.cactoos.text.Joined) QueryKeyed(com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed) Session(com.github.fabriciofx.cactoos.jdbc.Session) Test(org.junit.Test)

Aggregations

Server (com.github.fabriciofx.cactoos.jdbc.Server)1 Session (com.github.fabriciofx.cactoos.jdbc.Session)1 ParamText (com.github.fabriciofx.cactoos.jdbc.param.ParamText)1 QueryKeyed (com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed)1 QuerySimple (com.github.fabriciofx.cactoos.jdbc.query.QuerySimple)1 ServerMysql (com.github.fabriciofx.cactoos.jdbc.server.ServerMysql)1 StatementInsertKeyed (com.github.fabriciofx.cactoos.jdbc.statement.StatementInsertKeyed)1 StatementUpdate (com.github.fabriciofx.cactoos.jdbc.statement.StatementUpdate)1 Joined (org.cactoos.text.Joined)1 Test (org.junit.Test)1