Row token

The Row token is sent by the server for every row in a result set, either from a SQL query or a stored procedure call.

The NBCRow packet is exactly the same as the Row packet, it is often used for rows that contain null values (NBC stands for null bitmap compression).

Properties

Additional properties are the values in the row and can be retrieved by their column name, e.g.:

let name = context.packet.first_name;

If the column name contains characters such as spaces, dashes, punctuation, etc... you can use the array notation, e.g. context.packet["My special$column"]. Column names are case-sensitive.

You can also retrieve a column value by its column index:

let name = context.packet[3];


Methods

The ClassificationEntry object

Properties

string sensitivityLabel: the sensitivity label

string informationType: the information type label

int sensitivityRank: the rank for this entry

Examples

Change the value of a column

if (context.packet.country === 'FR') {
    context.packet.balance = 0;
}


Hide columns based on the metadata

Hide the value of all the columns of type varchar:

let pkt = context.packet;

for (let meta of pkt.columnMetadata) {

    if (meta.typeInfo.typeName === "varchar") {

        pkt[meta.columnName] = "<hidden>";

    }

}


Modify a bitmap stored in a column (1.8.6 and later)

// Get the value of the image column as a byte stream

let stream = context.packet.getJavaStream("image");

if (stream === null) {

    return;

}


// The text to use as watermark

const now = new Date();

const WATERMARK = "Retrieved by " + context.connectionContext.userName + 

    " on " + now.getFullYear() + "/" + (now.getMonth()+1) + "/" + now.getDate();


// We need to do this, otherwise it may fail on headless servers

const System = Java.type("java.lang.System");

System.setProperty("java.awt.headless", "true");


// Read the image

const ImageIO = Java.type("javax.imageio.ImageIO");

let img = ImageIO.read(stream);


// Create the Graphics to draw the text

let g = img.createGraphics();

const Color = Java.type("java.awt.Color");

g.setColor(new Color(100, 200, 200, 150));

const Font = Java.type("java.awt.Font");

g.setFont(new Font("serif", Font.BOLD, 16));


// Draw the text at the bottom of the image

let rect = textFont.getStringBounds(WATERMARK, g.getFontRenderContext());

g.drawString(WATERMARK, (img.getWidth() / 2) - (rect.getWidth() / 2),

                img.getHeight() - (rect.getHeight() / 2));


// Write the image back to the row

const ByteArrayOutputStream = Java.type("java.io.ByteArrayOutputStream");

let outStream = new ByteArrayOutputStream();

ImageIO.write(img, "png", outStream);

context.packet.image = outStream.toByteArray();