Search in sources :

Example 41 with Row

use of com.mysql.cj.xdevapi.Row in project aws-mysql-jdbc by awslabs.

the class TableUpdateTest method testUpdates.

@Test
public void testUpdates() {
    try {
        sqlUpdate("drop table if exists updates");
        sqlUpdate("drop view if exists updatesView");
        sqlUpdate("create table updates (_id varchar(32), name varchar(20), birthday date, age int)");
        sqlUpdate("create view updatesView as select _id, name, age from updates");
        sqlUpdate("insert into updates values ('1', 'Sakila', '2000-05-27', 14)");
        sqlUpdate("insert into updates values ('2', 'Shakila', '2001-06-26', 13)");
        Table table = this.schema.getTable("updates");
        table.update().set("name", expr("concat(name, '-updated')")).set("age", expr("age + 1")).where("name == 'Sakila'").execute();
        Table view = this.schema.getTable("updatesView");
        view.update().set("name", expr("concat(name, '-updated')")).set("age", expr("age + 3")).where("name == 'Shakila'").orderBy("age", "name").execute();
        RowResult rows = table.select("name, age").where("_id == :theId").bind("theId", 1).execute();
        Row r = rows.next();
        assertEquals("Sakila-updated", r.getString(0));
        assertEquals(15, r.getInt(1));
        assertFalse(rows.hasNext());
        rows = table.select("name, age").where("_id == :theId").bind("theId", 2).execute();
        r = rows.next();
        assertEquals("Shakila-updated", r.getString(0));
        assertEquals(16, r.getInt(1));
        assertFalse(rows.hasNext());
    } finally {
        sqlUpdate("drop table if exists updates");
        sqlUpdate("drop view if exists updatesView");
    }
}
Also used : RowResult(com.mysql.cj.xdevapi.RowResult) Table(com.mysql.cj.xdevapi.Table) Row(com.mysql.cj.xdevapi.Row) Test(org.junit.jupiter.api.Test)

Aggregations

Row (com.mysql.cj.xdevapi.Row)41 Test (org.junit.jupiter.api.Test)35 RowResult (com.mysql.cj.xdevapi.RowResult)22 Table (com.mysql.cj.xdevapi.Table)22 SqlResult (com.mysql.cj.xdevapi.SqlResult)20 JsonString (com.mysql.cj.xdevapi.JsonString)16 DbDoc (com.mysql.cj.xdevapi.DbDoc)11 DbDocImpl (com.mysql.cj.xdevapi.DbDocImpl)9 DocResult (com.mysql.cj.xdevapi.DocResult)8 Session (com.mysql.cj.xdevapi.Session)8 ExecutionException (java.util.concurrent.ExecutionException)8 JsonNumber (com.mysql.cj.xdevapi.JsonNumber)6 HashMap (java.util.HashMap)6 CoreSession (com.mysql.cj.CoreSession)5 SessionFactory (com.mysql.cj.xdevapi.SessionFactory)5 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)4 SessionImpl (com.mysql.cj.xdevapi.SessionImpl)4 SelectStatement (com.mysql.cj.xdevapi.SelectStatement)3 SqlStatement (com.mysql.cj.xdevapi.SqlStatement)3 CompletableFuture (java.util.concurrent.CompletableFuture)3