APISonar


com.google.cloud.spanner.Type.date

> com > google > cloud > spanner > Type > date
com APIs google APIs cloud APIs spanner APIs Type APIs date APIs

Example 1
public void bindDate() {
    Date d = Date.parseDate("2016-09-18");
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(d), Type.date());
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getDate(0)).isEqualTo(d);
  }
Example 2
public void bindEmptyArrayOfStruct() {
    Type elementType = Type.struct(asList(Type.StructField.of("f1", Type.date())));
    List<Struct> p = asList();
    assertThat(p).isEmpty();

    List<Struct> rows =
        resultRows(
            Statement.newBuilder("SELECT * FROM UNNEST(@p)")
                .bind("p")
                .toStructArray(elementType, p)
                .build(),
            elementType);
    assertThat(rows).isEmpty();
  }
Example 3
private int getSqlType(Type type) {
    if (type == Type.bool()) return Types.BOOLEAN;
    if (type == Type.bytes()) return Types.BINARY;
    if (type == Type.date()) return Types.DATE;
    if (type == Type.float64()) return Types.DOUBLE;
    if (type == Type.int64()) return Types.BIGINT;
    if (type == Type.string()) return Types.NVARCHAR;
    if (type == Type.timestamp()) return Types.TIMESTAMP;
    if (type.getCode() == Code.ARRAY) return Types.ARRAY;
    return Types.OTHER;
  }