Beispiel #1
0
        public IEnumerable <T> ExecuteDeferredQuery <T>(Base.TableMapping map, DaemonCompiledSetter _compiledSetter) where T : class
        {
            DaemonCompiledSetter <T, sqlite3_stmt> compiledSetter = _compiledSetter as DaemonCompiledSetter <T, sqlite3_stmt>;
            List <T> result = new List <T>();

            if (_conn.IsClosed)
            {
                _conn.RenewConnection();
            }

            Log.Logger.Debug(this.CommandText);
            var stmt = Prepare();

            try
            {
                while (SQLite3.Step(stmt) == SQLite3.Result.Row)
                {
                    var obj = Activator.CreateInstance(map.MappedType);
                    for (int i = 0; i < compiledSetter.Columns.Length; i++)
                    {
                        if (compiledSetter.Columns[i] == null)
                        {
                            continue;
                        }

                        if (compiledSetter.Setters[i] != null)
                        {
                            if (obj is not T)
                            {
                            }
                            compiledSetter.Setters[i].Invoke((T)obj, stmt, i);
                        }
                        else
                        {
                            var colType = SQLite3.ColumnType(stmt, i);
                            var val     = ReadCol(stmt, i, colType, compiledSetter.Columns[i].ColumnType);
                            compiledSetter.Columns[i].SetValue(obj, val);
                        }
                    }

                    OnInstanceCreated(obj);
                    result.Add((T)obj);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, "SqliteCommand.ExecuteDeferredQuery");
            }
            finally
            {
                SQLite3.Finalize(stmt);
            }

            return(result);
        }
        private void Dispose(bool disposing)
        {
            var s = Statement;

            Statement  = NullStatement;
            Connection = null;
            if (s != NullStatement)
            {
                SQLite3.Finalize(s);
            }
        }
Beispiel #3
0
 private void Finalize(sqlite3_stmt stmt)
 {
     SQLite3.Finalize(stmt);
 }
Beispiel #4
0
        public override IEnumerable <T> ExecuteDeferredQuery <T>(Kit.Sql.Base.TableMapping map)
        {
            List <T> result = new List <T>();

            if (_conn.IsClosed)
            {
                _conn.RenewConnection();
            }

            Log.Logger.Debug(this.CommandText);
            var stmt = Prepare();

            try
            {
                var cols = new Column[SQLite3.ColumnCount(stmt)];
                var fastColumnSetters = new Action <T, sqlite3_stmt, int> [SQLite3.ColumnCount(stmt)];

                for (int i = 0; i < cols.Length; i++)
                {
                    var name = SQLite3.ColumnName16(stmt, i);
                    cols[i] = map.FindColumn(name);
                    if (cols[i] != null)
                    {
                        fastColumnSetters[i] = FastColumnSetter.GetFastSetter <T>(_conn, cols[i]);
                    }
                }

                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;
                        }

                        if (fastColumnSetters[i] != null)
                        {
                            if (obj is not T)
                            {
                            }
                            fastColumnSetters[i].Invoke((T)obj, stmt, i);
                        }
                        else
                        {
                            var colType = SQLite3.ColumnType(stmt, i);
                            var val     = ReadCol(stmt, i, colType, cols[i].ColumnType);
                            cols[i].SetValue(obj, val);
                        }
                    }

                    OnInstanceCreated(obj);
                    result.Add((T)obj);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, "SqliteCommand.ExecuteDeferredQuery");
            }
            finally
            {
                SQLite3.Finalize(stmt);
            }

            return(result);
        }