Working with Dimension Fields

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes some methods of working with data source dimension fields. After starting the example the following operations are executed:

Source Code

Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Data Analysis section):

// Get array of cube dimensions
SNArray allDimensions = [self allDimensions];
// Get first cube dimension in array
SPPLDimension dimension = allDimensions->objectAtIndex<PPLDimension>(0);
// Get information about dimension data table fields in use
SPPLDimensionFields dimensionFields = dimension->fields();
// Get array of table fields
SNArray dimensionFieldsItems = dimensionFields->items();
// Create an object of dimension fields by means of parameterless designer
SPPLDimensionFields createdFields = new PPLDimensionFields();
// Display number of created object fields in the development environment console
printf("Number of first object fields: %d\n", createdFields->items()->count());
// Create the second object of dimension fields based on array of table fields
SPPLDimensionFields createdFields2 = new PPLDimensionFields(dimensionFieldsItems);
// Get text description of second object of dimension fields
SNString fieldsDescription = createdFields2->description();
// Display second object description in the development environment console
printf("Second object description:\n%s\n", fieldsDescription->UTF8String());
// Set field name in string
SNString fieldName = NStr("ID");
// Check if field with this name exists
bool hasFieldWithName = createdFields2->hasFieldWithName(fieldName);
// Execute a series of operations on the field if field with this name exists
if(hasFieldWithName == true)
{
    // Retrieve field object by specified name
    SPPLDimensionField dimensionField = createdFields2->getFieldByName(fieldName);
    // Get field name
    SNString dimensionFieldName = dimensionField->name();
    // Get field type
    SNString dimensionFieldType = dimensionField->type();
    // Get field attribute
    SNString dimensionFieldAttribute = dimensionField->attribute();
    // Display field name, type and attribute in the development environment console
    printf("Second object field: %s, type: %s, attribute: %s\n", dimensionFieldName->UTF8String(), dimensionFieldType->UTF8String(),
    dimensionFieldAttribute->UTF8String());
    // Get field name in quotation marks
    SNString dimensionFieldQuotedName = dimensionField->quotedName();
    // Get field text description
    SNString dimensionFieldDescription = dimensionField->description();
    // Display field name in quotation marks and field text description in the development environment console
    printf("Description of field %s of second object:\n%s\n", dimensionFieldQuotedName->UTF8String(), dimensionFieldDescription->UTF8String());
}
// Set new field name in string
fieldName = NStr("END_DATE");
// Check if field with this name exists
hasFieldWithName = createdFields2->hasFieldWithName(fieldName);
// Create a field if field with this name does not exist
if(hasFieldWithName == false)
{
    // Create a dictionary which contains new field description
    SNMutableDictionary fieldDescription = NMutableDictionary::mutableDictionary();
    // Add field name to dictionary
    fieldDescription->setObjectForKey(fieldName, NStr("name"));
    // Create a new field based on dictionary
    SPPLDimensionField createdField = PPLDimensionField::field(fieldDescription);
    // Display new field name in the development environment console
    printf("Field %s is successfully created\n", createdField->name()->UTF8String());
}

After executing the example the development environment console displays information about created objects containing dimension fields, name, type, description and attributes of one of the obtained fields, and also name of the new dimension field:

Number of first object fields: 0

Second object description:

<NMutableArray:

name: KEY

type: INTEGER

attribute: NULL

name: BLOCK_TYPE

type: INTEGER

attribute: BLOCK_TYPE

name: START_DATE

type: INTEGER

attribute: START_DATE

name: NAME

type: TEXT

attribute: NAME

name: ID

type: TEXT

attribute: ID

name: ORDER

type: INTEGER

attribute: ORDER

name: VISIBLE

type: INTEGER

attribute: NULL

name: PARENT_KEY

type: INTEGER

attribute: NULL

>

Second object field: ID, type: TEXT, attribute: ID

Description of field `ID` of second object:

name: ID

type: TEXT

attribute: ID

Field END_DATE is successfully created

See also:

Example of pplib++ Library Use