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

            var stmt = 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);
                map.SetConnection(obj, _conn);
                for (int i = 0; i < cols.Length; i++)
                {
                    if (cols[i] == null)
                    {
                        continue;
                    }
                    var val = ReadCol(stmt, i, cols[i].ColumnType);
                    cols[i].SetValue(obj, val);
                }
                yield return(obj);
            }

            SQLite3.Finalize(stmt);
        }
Beispiel #2
0
        /// <summary>
        /// Executes the query.
        /// </summary>
        /// <param name="maxRows">
        /// The maximum rows.
        /// </param>
        /// <returns>
        /// The <see cref="ResultCollection"/>.
        /// </returns>
        public virtual ResultCollection ExecuteQuery(int maxRows)
        {
            ResultCollection results;
            IntPtr           stmt = IntPtr.Zero;

            try
            {
                stmt = this.Prepare();
                var cols = new ColumnInfoExt[SQLite3.ColumnCount(stmt)];

                for (var i = 0; i < cols.Length; i++)
                {
                    cols[i] = new ColumnInfoExt {
                        Name = SQLite3.ColumnName16(stmt, i), ColumnIndex = i
                    };
                }

                results = new ResultCollection(cols);

                var rows = 0;
                while (SQLite3.Step(stmt) == SQLite3.Result.Row)
                {
                    var obj = new ResultRow();
                    for (var i = 0; i < cols.Length; i++)
                    {
                        if (cols[i] == null)
                        {
                            continue;
                        }

                        var colType = SQLite3.ColumnType(stmt, i);
                        cols[i].ColumnMainType = colType;

                        var val = this.ReadCol(stmt, i, colType, cols[i].ColumnClrType);
                        obj[cols[i].ColumnIndex] = val;
                    }

                    results.Add(obj);

                    if (maxRows != 0 && ++rows == maxRows)
                    {
                        break;
                    }
                }
            }
            finally
            {
                if (stmt != IntPtr.Zero)
                {
                    SQLite3.Finalize(stmt);
                }
            }

            return(results);
        }
Beispiel #3
0
 public IEnumerable <T> ExecuteDeferredQuery <T>(TableMapping map)
 {
     if (_conn.Trace)
     {
         _conn.InvokeTrace("Executing Query: " + this);
     }
     lock (_conn.SyncObject)
     {
         IntPtr stmt = Prepare();
         try
         {
             TableMapping.Column[] cols = new TableMapping.Column[SQLite3.ColumnCount(stmt)];
             for (int j = 0; j < cols.Length; j++)
             {
                 string name = SQLite3.ColumnName16(stmt, j);
                 cols[j] = map.FindColumn(name);
             }
             while (SQLite3.Step(stmt) == SQLite3.Result.Row)
             {
                 object obj = Activator.CreateInstance(map.MappedType);
                 for (int i = 0; i < cols.Length; i++)
                 {
                     if (cols[i] != null)
                     {
                         SQLite3.ColType colType = SQLite3.ColumnType(stmt, i);
                         object          val     = ReadCol(stmt, i, colType, cols[i].ColumnType);
                         cols[i].SetValue(obj, val);
                     }
                 }
                 OnInstanceCreated(obj);
                 yield return((T)obj);
             }
         }
         finally
         {
             ((_003CExecuteDeferredQuery_003Ec__Iterator3 <T>) /*Error near IL_0234: stateMachine*/)._003C_003E__Finally0();
         }
     }
 }
Beispiel #4
0
        public IEnumerable <T> ExecuteDeferredQuery <T>(TableMapping map)
        {
            if (_conn.Trace)
            {
                Debug.WriteLine("Executing Query: " + this);
            }

            var stmt = Prepare();

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

                for (int i = 0; i < cols.Length; i++)
                {
                    var name = 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     = ReadCol(stmt, i, colType, cols[i].ColumnType);
                        cols[i].SetValue(obj, val);
                    }
                    OnInstanceCreated(obj);
                    yield return((T)obj);
                }
            } finally {
                SQLite3.Finalize(stmt);
            }
        }