コード例 #1
0
        /// <summary>
        /// Creates the table.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="collection">The collection.</param>
        private void CreateTable(ref DataTable table, IDfCollection collection)
        {
            if (table != null)
            {
                return;
            }
            table = new DataTable();

            DqlDataType    converter = new DqlDataType();
            IDfTypedObject typedObj  = collection.getTypedObject();
            IDfAttr        attr      = null;

            int count = collection.getAttrCount();

            for (int i = 0; i < count; i++)
            {
                attr = collection.getAttr(i);
                string field = attr.getName();

                tagDfValueTypes dataType = attr.isRepeating()
                    ? tagDfValueTypes.DF_STRING
                    : (tagDfValueTypes)attr.getDataType();

                if (converter.ContainsKey(dataType))
                {
                    table.Columns.Add(converter[dataType](field));
                }
            }
            typedObj = null;
            attr     = null;
        }
コード例 #2
0
        /// <summary>
        /// Fills the specified data set.
        /// </summary>
        /// <param name="dataSet">The data set.</param>
        /// <param name="token">The token.</param>
        /// <returns>System.Int32.</returns>
        public int Fill(DataSet dataSet, CancellationToken token)
        {
            DqlReader formatter = new DqlReader();

            List <DqlCommand> commands = new List <DqlCommand>();

            command.CommandText.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
            .ToList().Where(w => string.IsNullOrEmpty(w) == false).ToList()
            .ForEach(commandText => commands.Add(new DqlCommand(commandText, (DqlConnection)command.Connection)));

            foreach (var cmd in commands)
            {
                if (token.IsCancellationRequested)
                {
                    throw new OperationCanceledException("A cancellation token associated with this operation was canceled");
                }

                DqlConnection cn = cmd.Connection;
                if (cn == null)
                {
                    throw new Exception("Connection is null");
                }

                IDfCollection  records  = cn.ExecuteQuery(cmd);
                DataTable      table    = null;
                IDfTypedObject typedObj = null;
                #region Row Iterator
                while (records.next())
                {
                    if (token.IsCancellationRequested)
                    {
                        throw new OperationCanceledException("A cancellation token associated with this operation was canceled");
                    }

                    CreateTable(ref table, records);
                    typedObj = records.getTypedObject();

                    DataRow row = table.NewRow();
                    table.Rows.Add(row);

                    #region Column Iterator
                    int count = records.getAttrCount();
                    for (int i = 0; i < count; i++)
                    {
                        var     collection = records;
                        IDfAttr attr       = collection.getAttr(i);
                        string  field      = attr.getName();

                        if (formatter.ContainsKey((tagDfValueTypes)attr.getDataType()))
                        {
                            row[field] = formatter[(tagDfValueTypes)attr.getDataType()](attr, collection);
                        }
                    }
                    #endregion
                }
                #endregion

                records.close();
                records = null; typedObj = null;

                if (table != null)
                {
                    dataSet.Tables.Add(table);
                }
            }

            commands.ForEach(item => item.Dispose());

            return(1);
        }