use of com.github.fabriciofx.cactoos.jdbc.server.ServerMysql in project cactoos-jdbc by fabriciofx.
the class StatementSelectTest method any.
@Test
public void any() throws Exception {
try (Servers servers = new Servers(new ServerH2(), new ServerMysql(), new ServerPgsql())) {
for (final Session session : servers.sessions()) {
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE person (id INT, name VARCHAR(30),", "created_at DATE, city VARCHAR(20),", "working BOOLEAN, height DECIMAL(20,2),", "PRIMARY KEY (id))"))).result();
new StatementBatch(session, new QueryBatch(new Joined(" ", "INSERT INTO person", "(id, name, created_at, city, working, height)", "VALUES (:id, :name, :created_at, :city,", ":working, :height)"), new ParamsNamed(new ParamInt("id", 1), new ParamText("name", "Rob Pike"), new ParamDate("created_at", LocalDate.now()), new ParamText("city", "San Francisco"), new ParamBool("working", true), new ParamDecimal("height", "1.86")), new ParamsNamed(new ParamInt("id", 2), new ParamText("name", "Ana Pivot"), new ParamDate("created_at", LocalDate.now()), new ParamText("city", "Washington"), new ParamBool("working", false), new ParamDecimal("height", "1.62")))).result();
MatcherAssert.assertThat("Can't select a person name", new ResultSetAsValue<>(new StatementSelect(session, new QuerySimple("SELECT name FROM person"))), new HasValue<>("Rob Pike"));
}
}
}
use of com.github.fabriciofx.cactoos.jdbc.server.ServerMysql 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.server.ServerMysql in project cactoos-jdbc by fabriciofx.
the class StatementBatchTest method batch.
@Test
public void batch() throws Exception {
try (Servers servers = new Servers(new ServerH2(), new ServerMysql(), new ServerPgsql())) {
for (final Session session : servers.sessions()) {
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE client (id INT,", "name VARCHAR(50), age INT, PRIMARY KEY (id))"))).result();
new StatementBatch(session, new QueryBatch(new Joined(" ", "INSERT INTO client (id, name, age)", "VALUES (:id, :name, :age)"), new ParamsNamed(new ParamInt("id", 1), new ParamText("name", "Jeff Bridges"), // @checkstyle MagicNumber (1 line)
new ParamInt("age", 34)), new ParamsNamed(new ParamInt("id", 2), new ParamText("name", "Anna Miller"), // @checkstyle MagicNumber (1 line)
new ParamInt("age", 26)), new ParamsNamed(// @checkstyle MagicNumber (3 lines)
new ParamInt("id", 3), new ParamText("name", "Michal Douglas"), new ParamInt("age", 32)))).result();
}
}
}
use of com.github.fabriciofx.cactoos.jdbc.server.ServerMysql in project cactoos-jdbc by fabriciofx.
the class StatementInsertTest method insert.
@Test
public void insert() throws Exception {
try (Servers servers = new Servers(new ServerH2(), new ServerMysql(), new ServerPgsql())) {
for (final Session session : servers.sessions()) {
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t01 (id INT, name VARCHAR(50),", "PRIMARY KEY (id))"))).result();
MatcherAssert.assertThat("Can't insert into table", new ResultAsValue<>(new StatementInsert(session, new QuerySimple(new Joined(" ", "INSERT INTO t01 (id, name)", "VALUES (:id, :name)"), new ParamInt("id", 1), new ParamText("name", "Yegor Bugayenko")))), new HasValue<>(false));
}
}
}
use of com.github.fabriciofx.cactoos.jdbc.server.ServerMysql 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