Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation  Back up to About Overview 
  
[+] Expand All
[-] Collapse All

Data Conversion Rules

This section describes the data conversions that occur when you use the SQL and LDAP data accessors. It provides the rules you need to specify variable types in your scripts, external databases, and data conversion files.

A single data variable can be represented differently in a script, a data accessor, and an external database. You must configure all three components correctly so that Steel-Belted Radius Carrier can perform the correct data conversions. Improper configuration can cause data corruption or runtime errors.

The SQL or LDAP schema determines how data are stored in external databases. Use the [VariableTypes] section of the LDAP or SQL data accessor .gen file to specify the corresponding data types for input and output container variables. You must also use the appropriate JavaScript syntax in your scripts.

Note: The examples in this section refer to SQL database queries, tables, and columns, but can apply to LDAP searches, records, and tables.

Output Container

SQL and LDAP data accessor plug-ins require that output container variables map to database columns of type string. When the DataAccessor.Execute() function is called, the result strings returned from the database are parsed according to the respective output container variable types declared in the data accessor configuration (.gen) file. The parsed data values are stored in the output container.

Subsequently, when the DataAccessor.GetOutputVariable() function is called, a second conversion is performed. Output container variables of type integer are returned to the script as JavaScript integer data. All other output container variable types are returned as strings. To avoid unnecessary data conversions, output container variables that refer to integer data should be declared as integer in the [VariableTypes] section of the .gen file. All other output container variables should be declared as string.

Note: It is legal, but inefficient, to declare an output container variable to be a type other than integer or string. For example, if an output container variable is declared to be type ipaddress, when the data accessor executes, the string representation of the address in the database must first be converted to a binary IP address structure, then when the script retrieves the value from the output container, the binary IP address must be converted back to a string representation. This conversion process wastes a significant amount of computing resources.

Attempting to map an output container variable to a non-string database column causes a runtime error when the data accessor is executed regardless of the variable type declaration in the .gen file.

Input Container

Data conversions are not performed when data are passed from the script to the input container, and from the input container to the database. Input container variables might refer to string, numeric, or binary column data in the database. The data types must all match across the script, the .gen file, and the database schema.

In most cases, the only input container variable types used with the JavaScript API (and the corresponding database column types) are integer and string. Other data types can be stored in the input container by coding the binary data directly as unformatted JavaScript strings using the standard String.fromCharCode() function. You are responsible for programming the binary coding correctly.

Examples

Example 1

When DataAccessor.SetInputVariable() is called for an integer variable, the JavaScript API can determine how to convert the supplied argument. For example, the following .gen file configuration declares an input container variable Count of type integer:

Select FooVar FROM bar WHERE index = @Count[VariableTypes]FooVar=stringCount=integer [Results]FooVar=1/64

Both of these statements result in the correct integer data type being passed to the Count variable in the SQL query:

DataAccessor.SetInputVariable(“Count”, 1234);DataAccessor.SetInputVariable(“Count”, “1234” );

In this example, the index column in the database must also be of integer type to match the Count input container variable. If not, a type mismatch error occurs when the plug-in attempts to execute the SQL statement.

Example 2

Represent types other than integer as strings. In this configuration file, the ipaddress column in database table bar contains IP address values represented as formatted strings. The input container variable IP-Address is declared as a string in the .gen file; and in the call to DataAccessor.SetInputVariable(), the argument value is also passed as a string:

Select FooVar FROM bar WHERE address = @ip-address [VariableTypes]FooVar=stringIP-Address=string [Results]FooVar=1/64
 DataAccessor.SetInputVariable(“IP-Address”, “128.18.40.1” );

You can change the .gen file to make IP-Address a binary (ipaddress) input container variable.

[VariableTypes]FooVar=stringIP-Address=ipaddress

Then the script might have to pass the data to SetInputVariable() as an integer or unformatted binary string.

var intData = 47276480;DataAccessor.SetInputVariable(“IP-Address”, intData);

or:

var binData = String.fromCharCode(0x80, 0x12, 0x28, 0x01);

DataAccessor.SetInputVariable(“IP-Address”, binData);

Because the container variable ip-address is declared as type ipaddress, the data accessor expects the input container data to be in a binary format appropriate to the type and passes it along unchanged to the database. The definition of the database address column must be changed to an appropriate binary type.

Example 3

This example shows how to retrieve an IP address value from the database. Because column IP-Address is mapped to an output container variable, the database schema must declare IP-Address to be of string type.

Select IP-Address FROM foobar WHERE username = @User-Name [VariableTypes]IP-Address=stringUser-Name=string [Results]IP-Address=1/64
 DataAccessor.SetInputVariable(“User-Name”, “testuser” );DataAccessor.Execute();var addrStr = DataAccessor.GetOutputVariable(“IP-Address” );

Similar results can be generated by declaring output container variable IP-Address to be of type ipaddress. As noted, this causes the data value to be converted to a binary form internal to the data accessor, but wastes some computing resources.

Supported Data Types and Conversions

Table 136 lists supported data types and conversions for input container variables.

Table 136: Data Types and Conversions for Input Container Variables

Input Container Variable Type

JavaScript Type

Database Type

Integer

Integer, String

Integer

String

String

String

  • IPv4 Address
  • IPv6 Address
  • IPv6 Prefix
  • IPv6 Interface
  • Time

Unformatted Binary String (not recommended)

<Binary Type>

The JavaScript Type column refers to the JavaScript variable types to be passed to the DataAccessor.SetInputVariable() function for each input container variable type.

Note: We recommend that you not configure the .gen file with input container variables of these types:

  • IPv4 Address
  • IPv6 Address
  • IPv6 Prefix
  • IPv6 Interface
  • Time

Instead, represent these data types as formatted strings within the script, the data accessor, and the database.

Table 137 lists supported data types and conversions for output container variables.

Table 137: Data Types and Conversions for Output Container Variables

Output Container Variable Type

JavaScript Type

Database Type

Integer

Integer

String

String

String

String

  • IPv4 Address
  • IPv6 Address
  • IPv6 Prefix
  • IPv6 Interface

Type-Specific Formatted String

String

Time

Time-String ( yyyy/mm/dd [hh[:mm[:ss]]] )

String

All columns and fields referred to by output container variables must contain string data. Integer output container variables are returned to the script as JavaScript integers. All other types are converted to formatted JavaScript strings.

Modified: 2017-03-07