CalculatedField

CalculatedField

Evaulate calculated fields in SELECT statement. This is achieved by converting the request into javascript and then using 'Function' to evaulate it.

Constructor

new CalculatedField(masterTable, primaryTable, tableFields)

Source:
Parameters:
Name Type Description
masterTable Table

JOINed table (unless not joined, then primary table)

primaryTable Table

First table in SELECT

tableFields TableFields

All fields from all tables

Members

mapMasterFields

Source:
Properties:
Type Description
Map.<String, TableField>

masterFields

Source:
Properties:
Type Description
Array.<TableField>

masterTable

Source:
Properties:
Type Description
Table

primaryTable

Source:
Properties:
Type Description
Table

sqlServerFunctionCache

Source:
Properties:
Type Description
Map.<String, String>

Map key=calculated field in SELECT, value=javascript equivalent code

Methods

createAssignmentStatments(vField, objectsDeclared, variablesDeclared, varData) → {String}

Description:
  • Creates a javascript code block. For the current field (vField), a variable is assigned the appropriate value from 'varData'. For example, if the column was 'ID' and the table was 'BOOKS'.

    "let BOOKS = {};BOOKS.ID = '9';"
    

    If the BOOKS object had already been declared, later variables would just be:

    "BOOKS.NAME = 'To Kill a Blue Jay';"
    
Source:
Parameters:
Name Type Description
vField TableField

current field that LET statements will be assigning to.

objectsDeclared Map.<String, Boolean>

tracks if TABLE name was been encountered yet.

variablesDeclared Map.<String, Boolean>

tracks if variables has already been assigned.

varData String

the data from the table that will be assigned to the variable.

Returns:
  • the javascript code block.
Type
String

evaluateCalculatedField(calculatedFormula, masterRecordID) → {any}

Description:
  • Evaluate the calculated field for the current table record and return a value.

Source:
Parameters:
Name Type Description
calculatedFormula String

calculation from SELECT statement

masterRecordID Number

current record ID.

Returns:
  • Evaluated data from calculation.
Type
any

getData(fldName, masterRecordID) → {any}

Description:
  • Get data from the table for the requested field name and record number

Source:
Parameters:
Name Type Description
fldName String

Name of field to get data for.

masterRecordID Number

The row number in table to extract data from.

Returns:
  • Data from table. undefined if not found.
Type
any

sqlServerCalcFields(calculatedFormula, masterRecordID) → {String}

Description:
  • The program is attempting to build some javascript code which we can then execute to find the value of the calculated field. There are two parts.

    1. Build LET statements to assign to all possible field name variants,
    2. Add the 'massaged' calculated field so that it can be run in javascript.
Source:
Parameters:
Name Type Description
calculatedFormula String

calculation from SELECT statement

masterRecordID Number

current table record ID.

Returns:
  • String to be executed. It is valid javascript lines of code.
Type
String

sqlServerFunctions(calculatedFormula) → {String}

Source:
Parameters:
Name Type Description
calculatedFormula String
Returns:
Type
String