コード例 #1
0
ファイル: SQLite.cs プロジェクト: azcoov/Monospace09
        public IEnumerable <T> ExecuteQuery <T> () where T : new()
        {
            var stmt = Prepare();

            var props = Orm.GetColumns(typeof(T));
            var cols  = new System.Reflection.PropertyInfo[SQLite3.ColumnCount(stmt)];

            for (int i = 0; i < cols.Length; i++)
            {
                cols[i] = MatchColProp(SQLite3.ColumnName(stmt, i), props);
            }

            while (SQLite3.Step(stmt) == SQLite3.Result.Row)
            {
                var obj = new T();
                for (int i = 0; i < cols.Length; i++)
                {
                    if (cols[i] == null)
                    {
                        continue;
                    }
                    var val = ReadCol(stmt, i, cols[i].PropertyType);
                    cols[i].SetValue(obj, val, null);
                }
                yield return(obj);
            }

            SQLite3.Finalize(stmt);
        }