/// <summary> /// Returns a table definition from an OPL tuple schema. /// /// The table definition is an array of N strings, each describing an element of the tuple. /// </summary> /// <param name="tupleSchema">The OPL Tuple schema</param> /// <param name="includeType">If True, The table definition has the form "NAME TYPE" otherwise just "NAME"</param> /// <returns>The table definition</returns> private String[] TableDefinitionFromOplTupleSchema(ITupleSchema tupleSchema, bool includeType) { OplElementDefinition elementDefinition = this.Model.ModelDefinition.getElementDefinition(tupleSchema.Name); OplTupleSchemaDefinition oplTupleSchema = elementDefinition.asTupleSchema(); String[] fields = new String[tupleSchema.Size]; for (int i = 0; i < tupleSchema.Size; i++) { String columnName = tupleSchema.GetColumnName(i); String field = columnName; if (includeType) { OplElementDefinitionType.Type oplType = oplTupleSchema.getComponent(i).getElementDefinitionType(); String sqlType = null; if (oplType == OplElementDefinitionType.Type.INTEGER) { sqlType = "INT"; } else if (oplType == OplElementDefinitionType.Type.FLOAT) { sqlType = "FLOAT"; } else if (oplType == OplElementDefinitionType.Type.STRING) { sqlType = "VARCHAR(30)"; } field += " " + sqlType; } fields[i] = field; } return(fields); }
/// <summary> /// Populates array names and types with the information from the tuple schema. /// </summary> /// <param name="schema">The tuple definition</param> /// <param name="names">Contains the field names</param> /// <param name="types">Contains the field types</param> private void FillNamesAndTypes(ITupleSchema schema, string[] names, OplElementDefinitionType.Type[] types) { OplElementDefinition elementDefinition = this.modelDefinition.getElementDefinition(schema.Name); OplTupleSchemaDefinition tupleSchema = elementDefinition.asTupleSchema(); for (int i = 0; i < schema.Size; i++) { types[i] = tupleSchema.getComponent(i).getElementDefinitionType(); names[i] = schema.GetColumnName(i); } }
/// <summary> /// Look for a string field in a tuple and return its value. /// </summary> /// <param name="tuple">The tuple to search.</param> /// <param name="field">The name of the field to find.</param> /// <param name="def">The value to return if the field is not found or is not of string type.</param> /// <returns></returns> private static string tryLoadField(ITuple tuple, String field, string def = null) { ITupleSchema schema = tuple.Schema; int size = schema.Size; for (int i = 0; i < size; ++i) { if (schema.IsSymbol(i) && field.Equals(schema.GetColumnName(i))) { return(tuple.GetStringValue(i)); } } return(def); }