コード例 #1
0
        /// <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);
        }
コード例 #2
0
        private void InsertIntoTable(DbConnection con, ITupleSchema tupleSchema, ITuple tuple, string insertCommand)
        {
            OplElementDefinition     elementDefinition = this.Model.ModelDefinition.getElementDefinition(tupleSchema.Name);
            OplTupleSchemaDefinition tupleDef          = elementDefinition.asTupleSchema();

            using (DbCommand insert = con.CreateCommand())
            {
                insert.CommandText = insertCommand;
                for (int i = 0; i < tupleSchema.Size; i++)
                {
                    OplElementDefinitionType.Type oplType = tupleDef.getComponent(i).getElementDefinitionType();
                    object oplValue = null;
                    if (oplType == OplElementDefinitionType.Type.INTEGER)
                    {
                        oplValue = tuple.GetIntValue(i);
                    }
                    else if (oplType == OplElementDefinitionType.Type.FLOAT)
                    {
                        oplValue = tuple.GetNumValue(i);
                    }
                    else if (oplType == OplElementDefinitionType.Type.STRING)
                    {
                        oplValue = tuple.GetStringValue(i);
                    }
                    DbUtils.AddParameterWithValue(insert, "@value" + i, oplValue);
                }
                insert.ExecuteNonQuery();
            }
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
        /// <summary>
        /// Reads the set or tuple from the specified data reader.
        /// </summary>
        /// <param name="name">set or tuple name.</param>
        /// <param name="reader">data source.</param>
        private void ReadSetOrTuple(String name, DbDataReader reader)
        {
            OplElementDefinition def = this.modelDefinition.getElementDefinition(name);

            OplElementDefinitionType.Type type = def.getElementDefinitionType();
            OplElementDefinitionType.Type leaf = def.getLeaf().getElementDefinitionType();
            if (type == OplElementDefinitionType.Type.SET)
            {
                if (leaf == OplElementDefinitionType.Type.TUPLE)
                {
                    this.ReadTupleSet(name, reader);
                }
                else
                {
                    this.ReadSet(leaf, name, reader);
                }
            }
        }