Search in sources :

Example 1 with InsertParams

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

the class XProtocolTest method tableInsert.

@Test
public void tableInsert() {
    assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
    this.protocol.send(this.messageBuilder.buildSqlStatement("drop table if exists tableInsert"), 0);
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
    this.protocol.send(this.messageBuilder.buildSqlStatement("create table tableInsert (x int, y varchar(20), z decimal(10, 2))"), 0);
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
    InsertParams insertParams = new InsertParams();
    insertParams.setProjection(new String[] { "z", "x", "y" });
    insertParams.addRow(Arrays.asList("10.2", 40, "some string value"));
    insertParams.addRow(Arrays.asList("10.3", 50, "another string value"));
    this.protocol.send(this.messageBuilder.buildRowInsert(getTestDatabase(), "tableInsert", insertParams), 0);
    SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
    assertEquals(2, res.getAffectedItemsCount());
    FilterParams filterParams = new TableFilterParams(getTestDatabase(), "tableInsert");
    filterParams.setOrder("x DESC");
    filterParams.setFields("z, y, x");
    this.protocol.send(this.messageBuilder.buildFind(filterParams), 0);
    ColumnDefinition metadata = this.protocol.readMetadata();
    Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
    Row r = ris.next();
    assertEquals("10.30", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("another string value", r.getValue(1, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("50", r.getValue(2, new StringValueFactory(this.protocol.getPropertySet())));
    r = ris.next();
    assertEquals("10.20", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("some string value", r.getValue(1, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("40", r.getValue(2, new StringValueFactory(this.protocol.getPropertySet())));
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
    this.protocol.send(this.messageBuilder.buildSqlStatement("drop table tableInsert"), 0);
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
}
Also used : XProtocolRowInputStream(com.mysql.cj.protocol.x.XProtocolRowInputStream) TableFilterParams(com.mysql.cj.xdevapi.TableFilterParams) SqlResult(com.mysql.cj.xdevapi.SqlResult) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) SqlResultBuilder(com.mysql.cj.xdevapi.SqlResultBuilder) StringValueFactory(com.mysql.cj.result.StringValueFactory) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) TableFilterParams(com.mysql.cj.xdevapi.TableFilterParams) FilterParams(com.mysql.cj.xdevapi.FilterParams) Row(com.mysql.cj.result.Row) InsertParams(com.mysql.cj.xdevapi.InsertParams) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnDefinition (com.mysql.cj.protocol.ColumnDefinition)1 StatementExecuteOkBuilder (com.mysql.cj.protocol.x.StatementExecuteOkBuilder)1 XProtocolRowInputStream (com.mysql.cj.protocol.x.XProtocolRowInputStream)1 Row (com.mysql.cj.result.Row)1 StringValueFactory (com.mysql.cj.result.StringValueFactory)1 DocFilterParams (com.mysql.cj.xdevapi.DocFilterParams)1 FilterParams (com.mysql.cj.xdevapi.FilterParams)1 InsertParams (com.mysql.cj.xdevapi.InsertParams)1 SqlResult (com.mysql.cj.xdevapi.SqlResult)1 SqlResultBuilder (com.mysql.cj.xdevapi.SqlResultBuilder)1 TableFilterParams (com.mysql.cj.xdevapi.TableFilterParams)1 Test (org.junit.jupiter.api.Test)1