use of com.mysql.cj.xdevapi.SqlResultBuilder in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method testWarnings.
@Test
public void testWarnings() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
this.protocol.send(this.messageBuilder.buildSqlStatement("explain select 1"), 0);
this.protocol.readMetadata();
this.protocol.drainRows();
SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
Iterable<Warning> iterable = () -> res.getWarnings();
List<Warning> warnings = StreamSupport.stream(iterable.spliterator(), false).map(w -> new WarningImpl(w)).collect(Collectors.toList());
assertEquals(1, warnings.size());
Warning w = warnings.get(0);
assertEquals(1, w.getLevel());
assertEquals(1003, w.getCode());
// this message format might change over time and have to be loosened up
assertEquals("/* select#1 */ select 1 AS `1`", w.getMessage());
}
use of com.mysql.cj.xdevapi.SqlResultBuilder in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method testEnableDisableNotices.
@Test
public void testEnableDisableNotices() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
// TODO currently only "warnings" are allowed to be disabled
this.protocol.send(this.messageBuilder.buildDisableNotices("warnings"), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
this.protocol.send(this.messageBuilder.buildSqlStatement("select CAST('abc' as CHAR(1))"), 0);
new XProtocolRowInputStream(this.protocol.readMetadata(), this.protocol, null).next();
SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(0, res.getWarningsCount());
// "produced_message" are already enabled, they're used here to check that multiple parameters are sent correctly
this.protocol.send(this.messageBuilder.buildEnableNotices("produced_message", "warnings"), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
this.protocol.send(this.messageBuilder.buildSqlStatement("select CAST('abc' as CHAR(1))"), 0);
new XProtocolRowInputStream(this.protocol.readMetadata(), this.protocol, null).next();
res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(1, res.getWarningsCount());
}
use of com.mysql.cj.xdevapi.SqlResultBuilder 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());
}
use of com.mysql.cj.xdevapi.SqlResultBuilder in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method testSqlDml.
/**
* Test DML that is executed with <i>StmtExecute</i> and does not return a result set.
*/
@Test
public void testSqlDml() {
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 mysqlx_sqlDmlTest"), 0);
assertFalse(this.protocol.hasResults());
SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(0, res.getAffectedItemsCount());
this.protocol.send(this.messageBuilder.buildSqlStatement("create table mysqlx_sqlDmlTest (w int primary key auto_increment, x int) auto_increment = 7"), 0);
assertFalse(this.protocol.hasResults());
res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(0, res.getAffectedItemsCount());
this.protocol.send(this.messageBuilder.buildSqlStatement("insert into mysqlx_sqlDmlTest (x) values (44),(29)"), 0);
assertFalse(this.protocol.hasResults());
res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(2, res.getAffectedItemsCount());
assertEquals(new Long(7), res.getAutoIncrementValue());
this.protocol.send(this.messageBuilder.buildSqlStatement("drop table mysqlx_sqlDmlTest"), 0);
assertFalse(this.protocol.hasResults());
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
}
Aggregations