Пример #1
0
 @Test
 public void testGetBytes() throws Exception {
   List<Field.Type> types =
       Arrays.asList(
           Field.Type.TYPE_VARCHAR,
           Field.Type.TYPE_BIT,
           Field.Type.TYPE_TINY_BLOB,
           Field.Type.TYPE_MEDIUM_BLOB,
           Field.Type.TYPE_LONG_BLOB,
           Field.Type.TYPE_BLOB,
           Field.Type.TYPE_VAR_STRING,
           Field.Type.TYPE_STRING,
           Field.Type.TYPE_GEOMETRY);
   for (Field.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col0").setType(type).build())
                 .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("hello world")))
                 .build())) {
       cursor.next();
       Assert.assertArrayEquals("hello world".getBytes("UTF-8"), cursor.getBytes("col0"));
     }
   }
 }
Пример #2
0
 @Test
 public void testNull() throws Exception {
   try (Cursor cursor =
       new SimpleCursor(
           QueryResult.newBuilder()
               .addFields(Field.newBuilder().setName("col0").setType(Field.Type.TYPE_NULL).build())
               .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("1234")))
               .build())) {
     cursor.next();
     Assert.assertEquals(null, cursor.getObject("col0"));
   }
 }
Пример #3
0
  @Test
  public void testGetDateTime() throws Exception {
    List<Field.Type> types = Arrays.asList(Field.Type.TYPE_DATETIME, Field.Type.TYPE_TIMESTAMP);
    for (Field.Type type : types) {
      try (Cursor cursor =
          new SimpleCursor(
              QueryResult.newBuilder()
                  .addFields(Field.newBuilder().setName("col0").setType(type).build())
                  .addRows(
                      Row.newBuilder().addValues(ByteString.copyFromUtf8("2008-01-02 14:15:16")))
                  .build())) {
        cursor.next();
        Assert.assertEquals(new DateTime(2008, 1, 2, 14, 15, 16), cursor.getDateTime("col0"));
      }
    }

    types = Arrays.asList(Field.Type.TYPE_DATE, Field.Type.TYPE_NEWDATE);
    for (Field.Type type : types) {
      try (Cursor cursor =
          new SimpleCursor(
              QueryResult.newBuilder()
                  .addFields(Field.newBuilder().setName("col0").setType(type).build())
                  .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("2008-01-02")))
                  .build())) {
        cursor.next();
        Assert.assertEquals(new DateTime(2008, 1, 2, 0, 0, 0), cursor.getDateTime("col0"));
      }
    }

    try (Cursor cursor =
        new SimpleCursor(
            QueryResult.newBuilder()
                .addFields(Field.newBuilder().setName("col0").setType(Field.Type.TYPE_TIME).build())
                .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("12:34:56")))
                .build())) {
      cursor.next();
      Assert.assertEquals(new DateTime(1970, 1, 1, 12, 34, 56), cursor.getDateTime("col0"));
    }
  }
Пример #4
0
 @Test
 public void testGetFloat() throws Exception {
   try (Cursor cursor =
       new SimpleCursor(
           QueryResult.newBuilder()
               .addFields(
                   Field.newBuilder().setName("col0").setType(Field.Type.TYPE_FLOAT).build())
               .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("2.5")))
               .build())) {
     cursor.next();
     Assert.assertEquals(2.5f, cursor.getFloat("col0"), 0.01f);
   }
 }
Пример #5
0
 @Test
 public void testGetLong() throws Exception {
   List<Field.Type> types = Arrays.asList(Field.Type.TYPE_LONG, Field.Type.TYPE_LONGLONG);
   for (Field.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col0").setType(type).build())
                 .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("12345")))
                 .build())) {
       cursor.next();
       Assert.assertEquals(12345L, cursor.getLong("col0"));
     }
   }
 }
Пример #6
0
 @Test
 public void testGetBigDecimal() throws Exception {
   List<Field.Type> types = Arrays.asList(Field.Type.TYPE_DECIMAL, Field.Type.TYPE_NEWDECIMAL);
   for (Field.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col0").setType(type).build())
                 .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("1234.56789")))
                 .build())) {
       cursor.next();
       Assert.assertEquals(
           new BigDecimal(BigInteger.valueOf(123456789), 5), cursor.getBigDecimal("col0"));
     }
   }
 }
Пример #7
0
 @Test
 public void testGetULong() throws Exception {
   try (Cursor cursor =
       new SimpleCursor(
           QueryResult.newBuilder()
               .addFields(
                   Field.newBuilder()
                       .setName("col0")
                       .setType(Field.Type.TYPE_LONGLONG)
                       .setFlags(Field.Flag.VT_UNSIGNED_FLAG_VALUE)
                       .build())
               .addRows(
                   Row.newBuilder().addValues(ByteString.copyFromUtf8("18446744073709551615")))
               .build())) {
     cursor.next();
     Assert.assertEquals(UnsignedLong.fromLongBits(-1), cursor.getULong("col0"));
   }
 }