Exemplo n.º 1
0
        /// <summary>
        /// Enumerates over all records in the table.
        /// </summary>
        /// <returns></returns>
        public IEnumerator<TRecord> GetEnumerator()
        {
            string query = this.tableInfo.SqlSelectString;

            TextWriter log = this.db.Log;
            if (log != null)
            {
                log.WriteLine();
                log.WriteLine(query);
            }

            using (View view = db.OpenView(query))
            {
                view.Execute();

                ColumnCollection columns = this.tableInfo.Columns;
                int columnCount = columns.Count;
                bool[] isBinary = new bool[columnCount];

                for (int i = 0; i < isBinary.Length; i++)
                {
                    isBinary[i] = columns[i].Type == typeof(System.IO.Stream);
                }

                foreach (Record rec in view) using (rec)
                {
                    string[] values = new string[columnCount];
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = isBinary[i] ? "[Binary Data]" : rec.GetString(i + 1);
                    }

                    TRecord trec = new TRecord();
                    trec.Database = this.Database;
                    trec.TableInfo = this.TableInfo;
                    trec.Values = values;
                    trec.Exists = true;
                    yield return trec;
                }
            }
        }