package io.vertx.pgclient.impl.codec;
import io.vertx.sqlclient.impl.PreparedStatement;
import io.vertx.sqlclient.impl.ParamDesc;
import java.util.Arrays;
import java.util.List;
class PgPreparedStatement implements PreparedStatement {
private static final PgColumnDesc[] EMPTY_COLUMNS = new PgColumnDesc[0];
final String sql;
final Bind bind;
final PgParamDesc paramDesc;
final PgRowDesc rowDesc;
PgPreparedStatement(String sql, long statement, PgParamDesc paramDesc, PgRowDesc rowDesc) {
if (rowDesc != null) {
rowDesc = new PgRowDesc(Arrays.stream(rowDesc.columns)
.map(c -> new PgColumnDesc(
c.name,
c.relationId,
c.relationAttributeNo,
c.dataType,
c.length,
c.typeModifier,
c.dataType.supportsBinary ? DataFormat.BINARY : DataFormat.TEXT))
.toArray(PgColumnDesc[]::new));
}
this.paramDesc = paramDesc;
this.rowDesc = rowDesc;
this.sql = sql;
this.bind = new Bind(statement, paramDesc != null ? paramDesc.paramDataTypes() : null, rowDesc != null ? rowDesc.columns : EMPTY_COLUMNS);
}
@Override
public ParamDesc paramDesc() {
return paramDesc;
}
@Override
public PgRowDesc rowDesc() {
return rowDesc;
}
@Override
public String sql() {
return sql;
}
@Override
public String prepare(List<Object> values) {
return paramDesc.prepare(values);
}
}