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
byte tokenType: the type code for this token (0xD1 for Row, 0xD2 for NBCRow).
String tokenTypeName: the name corresponding to this token's type ("Row" or "NBCRow").
List<ColumnMetadata> columnMetadata: the metadata for this row - one entry per column
DataClassification dataClassification: the data classification for this result set, if defined and available. This is useful only if you need to dynamically look up the classifications, otherwise it is easier to use getSensitivityPropertiesForColumn (see below).
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
int getIndexOfColumn(string): returns the zero-based index of the column with the given name. If more than one column has the given name, the first one is returned. If no column has the specified name, -1 is returned.
List<ClassificationEntry> getSensitivityPropertiesForColumn(string): returns the data classification entry (see below for details)
ColumnMetadata getMetadataForColumn(string columnName): returns the metadata for the specified column, or null if the name is not that of a column. If the name appears more than once in the row, the first one is returned. If no column has the specified name, null is returned.
InputStream getJavaStream(string): returns the value of the specified column as a Java InputStream. The column must be of type text or binary. Returns null if the column is null, or if the column does not exist.
void remove(): remove this row from the result set
object duplicate(): creates a copy of this row
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();