Exemple #1
0
        public List <T> ExecuteQuery <T>(TableMapping map)
        {
            if (this._conn.Trace)
            {
                Console.WriteLine("Executing Query: " + this);
            }

            var r = new List <T>();

            var stmt = this.Prepare();

            var cols = new TableMapping.Column[SQLite3.ColumnCount(stmt)];

            for (int i = 0; i < cols.Length; i++)
            {
                var name = Marshal.PtrToStringUni(SQLite3.ColumnName16(stmt, i));
                cols[i] = map.FindColumn(name);
            }

            while (SQLite3.Step(stmt) == SQLite3.Result.Row)
            {
                var obj = Activator.CreateInstance(map.MappedType);
                for (int i = 0; i < cols.Length; i++)
                {
                    if (cols[i] == null)
                    {
                        continue;
                    }
                    var colType = SQLite3.ColumnType(stmt, i);
                    var val     = this.ReadCol(stmt, i, colType, cols[i].ColumnType);
                    cols[i].SetValue(obj, val);
                }
                r.Add((T)obj);
            }

            this.Finalize(stmt);
            return(r);
        }