Bind packet

A Bind packet is sent by the database client to connect a previously defined prepared statement to a cursor (called a portal in Postgres, for some reason), and provide values for the prepared statement's parameters.

Attributes

Methods

Examples

To change the value of a parameter:

let paramValue = context.packet.getParameter(2);

if (paramValue === "Canada") {

    context.packet.setParameter(3, 883);

}


For parameters of type numeric or decimal, if you don't want to run the risk of precision loss:

let paramValue = context.packet.getJavaParameter(3);

const BigDecimal = Java.type("java.math.BigDecimal");

const rate = new BigDecimal("0.1015");

paramValue = paramValue.multiply(rate);

context.packet.setJavaParameter(3, paramValue);


For parameters of type numeric or decimal, setting an exact value:

const BigDecimal = Java.type("java.math.BigDecimal");

let bd = new BigDecimal("987654321987654321987654321987654321.123456789123456789123456789");

context.packet.setJavaParameter(3, bd);