use of com.mysql.cj.xdevapi.RowResult in project aws-mysql-jdbc by awslabs.
the class MetadataTest method testGetTableName.
@Test
public void testGetTableName() throws Exception {
RowResult rows = null;
Table table = null;
try {
sqlUpdate("drop table if exists qatable");
sqlUpdate("create table qatable (_id varchar(32), a varchar(20), b date, c int)");
sqlUpdate("insert into qatable values ('X', 'Abcd', '2016-03-07',10)");
table = this.schema.getTable("qatable");
rows = table.select("_id, a, b, c").execute();
List<Column> metadata = rows.getColumns();
assertEquals(4, metadata.size());
Column idCol = metadata.get(0);
assertEquals("qatable", idCol.getTableName());
Column aCol = metadata.get(1);
assertEquals("qatable", aCol.getTableName());
Column bCol = metadata.get(2);
assertEquals("qatable", bCol.getTableName());
Column cCol = metadata.get(3);
assertEquals("qatable", cCol.getTableName());
assertEquals(table.getName(), cCol.getTableName());
} finally {
sqlUpdate("drop table if exists qatable");
}
}
use of com.mysql.cj.xdevapi.RowResult in project aws-mysql-jdbc by awslabs.
the class MetadataTest method testWithUnsignedData.
@Test
public void testWithUnsignedData() throws Exception {
RowResult rows = null;
Table table = null;
Column myCol = null;
try {
char[] array = new char[1024 * 1024];
Arrays.fill(array, 'X');
char[] array2 = new char[256];
Arrays.fill(array2, 'X');
sqlUpdate("drop table if exists qatable");
sqlUpdate("create table qatable (a int unsigned ,b bigint unsigned,c tinyint unsigned,d smallint unsigned, e float unsigned,f double unsigned, g TEXT,h MEDIUMINT unsigned)");
table = this.schema.getTable("qatable");
table.insert("a", "b", "c", "d").values(1, 10, 1, 321).execute();
rows = table.select("*").execute();
List<Column> metadata = rows.getColumns();
assertEquals(8, metadata.size());
myCol = metadata.get(0);
assertEquals("a", myCol.getColumnName());
assertEquals("a", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.INT, myCol.getType());
assertEquals(10, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
myCol = metadata.get(1);
assertEquals("b", myCol.getColumnName());
assertEquals("b", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.BIGINT, myCol.getType());
assertEquals(20, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
myCol = metadata.get(2);
assertEquals("c", myCol.getColumnName());
assertEquals("c", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.TINYINT, myCol.getType());
assertEquals(3, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
myCol = metadata.get(3);
assertEquals("d", myCol.getColumnName());
assertEquals("d", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.SMALLINT, myCol.getType());
assertEquals(5, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
myCol = metadata.get(4);
assertEquals("e", myCol.getColumnName());
assertEquals("e", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.FLOAT, myCol.getType());
assertEquals(12, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
myCol = metadata.get(5);
assertEquals("f", myCol.getColumnName());
assertEquals("f", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.DOUBLE, myCol.getType());
assertEquals(22, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
myCol = metadata.get(6);
assertEquals("g", myCol.getColumnName());
assertEquals("g", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.STRING, myCol.getType());
assertEquals(65535, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
myCol = metadata.get(7);
assertEquals("h", myCol.getColumnName());
assertEquals("h", myCol.getColumnLabel());
assertEquals(table.getName(), myCol.getTableLabel());
assertEquals(table.getName(), myCol.getTableName());
assertEquals(Type.MEDIUMINT, myCol.getType());
assertEquals(8, myCol.getLength());
assertEquals(0, myCol.getFractionalDigits());
assertEquals(false, myCol.isNumberSigned());
assertEquals(false, myCol.isPadded());
assertEquals(true, myCol.isNullable());
} finally {
sqlUpdate("drop table if exists qatable");
}
}
use of com.mysql.cj.xdevapi.RowResult in project aws-mysql-jdbc by awslabs.
the class MetadataTest method testGetType.
@Test
public void testGetType() throws Exception {
RowResult rows = null;
Table table = null;
try {
sqlUpdate("drop table if exists qatable");
sqlUpdate("create table qatable (_id varchar(32), a char(20), b date, c int,d double,e datetime,f time," + "g linestring,h tinyint,i mediumint,j bigint,k float, l set('1','2'), m enum('1','2'),n decimal(20,10),o bit)");
table = this.schema.getTable("qatable");
table.insert("j").values(10).execute();
rows = table.select("*").execute();
List<Column> metadata = rows.getColumns();
assertEquals(16, metadata.size());
Column idCol = metadata.get(0);
assertEquals(Type.STRING, idCol.getType());
Column aCol = metadata.get(1);
assertEquals(Type.STRING, aCol.getType());
Column bCol = metadata.get(2);
assertEquals(Type.DATE, bCol.getType());
Column cCol = metadata.get(3);
assertEquals(Type.INT, cCol.getType());
Column dCol = metadata.get(4);
assertEquals(Type.DOUBLE, dCol.getType());
Column eCol = metadata.get(5);
assertEquals(Type.DATETIME, eCol.getType());
Column fCol = metadata.get(6);
assertEquals(Type.TIME, fCol.getType());
Column gCol = metadata.get(7);
assertEquals(Type.GEOMETRY, gCol.getType());
Column hCol = metadata.get(8);
assertEquals(Type.TINYINT, hCol.getType());
Column iCol = metadata.get(9);
assertEquals(Type.MEDIUMINT, iCol.getType());
Column jCol = metadata.get(10);
assertEquals(Type.BIGINT, jCol.getType());
Column kCol = metadata.get(11);
assertEquals(Type.FLOAT, kCol.getType());
Column lCol = metadata.get(12);
assertEquals(Type.SET, lCol.getType());
Column mCol = metadata.get(13);
assertEquals(Type.ENUM, mCol.getType());
Column nCol = metadata.get(14);
assertEquals(Type.DECIMAL, nCol.getType());
Column oCol = metadata.get(15);
assertEquals(Type.BIT, oCol.getType());
} finally {
sqlUpdate("drop table if exists qatable");
}
}
use of com.mysql.cj.xdevapi.RowResult in project aws-mysql-jdbc by awslabs.
the class MetadataTest method testGetColumnLabel.
@Test
public void testGetColumnLabel() throws Exception {
RowResult rows = null;
Table table = null;
try {
sqlUpdate("drop table if exists qatable");
sqlUpdate("create table qatable (_id varchar(32), a varchar(20), b date, c int)");
sqlUpdate("insert into qatable values ('X', 'Abcd', '2016-03-07',10)");
table = this.schema.getTable("qatable");
rows = table.select("_id as col1, a as `a+1`, b as `a 1 1`, c as `a``q`").execute();
List<Column> metadata = rows.getColumns();
assertEquals(4, metadata.size());
Column idCol = metadata.get(0);
assertEquals("_id", idCol.getColumnName());
assertEquals("col1", idCol.getColumnLabel());
Column aCol = metadata.get(1);
assertEquals("a", aCol.getColumnName());
assertEquals("a+1", aCol.getColumnLabel());
Column bCol = metadata.get(2);
assertEquals("b", bCol.getColumnName());
assertEquals("a 1 1", bCol.getColumnLabel());
Column cCol = metadata.get(3);
assertEquals("c", cCol.getColumnName());
assertEquals("a`q", cCol.getColumnLabel());
} finally {
sqlUpdate("drop table if exists qatable");
}
}
use of com.mysql.cj.xdevapi.RowResult in project aws-mysql-jdbc by awslabs.
the class MetadataTest method testGetLength.
@Test
public void testGetLength() throws Exception {
assumeTrue(mysqlVersionMeetsMinimum(ServerVersion.parseVersion("8.0.0")), "MySQL 8.0+ is required to run this test.");
RowResult rows = null;
Table table = null;
try {
sqlUpdate("drop database if exists lengthTest");
sqlUpdate("create database lengthTest DEFAULT CHARACTER SET latin1");
sqlUpdate("drop table if exists lengthTest.qatable");
sqlUpdate("create table lengthTest.qatable (_id varchar(32), a char(20), b date, c int,d double,e datetime,f time," + "g linestring,h tinyint,i mediumint,j bigint,k float, l set('1','2'), m enum('1','2'),n decimal(20,10),o bit(3))");
table = this.session.getSchema("lengthTest").getTable("qatable");
table.insert("k").values(10).execute();
rows = table.select("*").execute();
List<Column> metadata = rows.getColumns();
assertEquals(16, metadata.size());
Column myCol = null;
long[] fLen = { 32, 20, 10, 11, 22, 19, 10, 0, 4, 9, 20, 12, 0, 0, 22, 3 };
for (int i = 0; i < 16; i++) {
myCol = metadata.get(i);
assertEquals(fLen[i], myCol.getLength());
}
} finally {
sqlUpdate("drop database if exists lengthTest");
}
}
Aggregations