コード例 #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);
        }
コード例 #2
0
        public IEnumerable <T> ExecuteDeferredQuery <T>(Base.TableMapping map, DaemonCompiledSetter _compiledSetter) where T : class
        {
            DaemonCompiledSetter <T, SqlDataReader> compiledSetter = _compiledSetter as DaemonCompiledSetter <T, SqlDataReader>;
            List <T> result = new List <T>();

            Log.Logger.Debug("Executing:[{0}]", CommandText);
            try
            {
                _conn.Con().Read(this.CommandText, (reader) =>
                {
                    if (reader.Read())
                    {
                        do
                        {
                            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)
                                {
                                    compiledSetter.Setters[i].Invoke((T)obj, reader, i);
                                }
                                else
                                {
                                    var colType = reader.GetFieldType(i);
                                    var val     = ReadCol(reader, i, colType, compiledSetter.Columns[i].ColumnType);
                                    compiledSetter.Columns[i].SetValue(obj, val);
                                }
                            }
                            OnInstanceCreated(obj);
                            result.Add((T)obj);
                        } while ((reader.Read()));
                    }
                }, new CommandConfig()
                {
                    CommandTimeout = _conn.CommandTimeout, ManualRead = true
                }, this.Parameters);
            }
            catch (Exception ex)
            {
                if (Log.IsDBConnectionError(ex))
                {
                    Daemon.Daemon.OffLine = true;
                }
            }
            return(result);
        }
コード例 #3
0
        public DaemonCompiledSetterTuple ExecuteDeferredQueryAndCompile <T>(Base.TableMapping map)
        {
            DaemonCompiledSetter <T, SqlDataReader> compiled = null;
            List <T> result = new List <T>();

            Log.Logger.Debug("Executing:[{0}]", CommandText);
            try
            {
                _conn.Con().Read(this.CommandText, (reader) =>
                {
                    if (reader.Read())
                    {
                        var cols = new Column[reader.FieldCount];
                        var fastColumnSetters = new Action <T, SqlDataReader, int> [reader.FieldCount];
                        for (int i = 0; i < cols.Length; i++)
                        {
                            var name = reader.GetName(i);
                            cols[i]  = map.FindColumn(name);
                            if (cols[i] != null)
                            {
                                fastColumnSetters[i] = FastColumnSetter.GetFastSetter <T>(cols[i]);
                            }
                        }
                        compiled = new DaemonCompiledSetter <T, SqlDataReader>(cols, fastColumnSetters);
                        do
                        {
                            var obj = Activator.CreateInstance(map.MappedType);
                            for (int i = 0; i < cols.Length; i++)
                            {
                                if (cols[i] == null)
                                {
                                    continue;
                                }

                                if (fastColumnSetters[i] != null)
                                {
                                    fastColumnSetters[i].Invoke((T)obj, reader, i);
                                }
                                else
                                {
                                    var colType = reader.GetFieldType(i);
                                    var val     = ReadCol(reader, i, colType, cols[i].ColumnType);
                                    cols[i].SetValue(obj, val);
                                }
                            }
                            OnInstanceCreated(obj);
                            result.Add((T)obj);
                        } while ((reader.Read()));
                    }
                }, new CommandConfig()
                {
                    CommandTimeout = _conn.CommandTimeout, ManualRead = true
                }, this.Parameters);
            }
            catch (Exception ex)
            {
                if (Log.IsDBConnectionError(ex))
                {
                    Daemon.Daemon.OffLine = true;
                }
            }
            return(new DaemonCompiledSetterTuple((IEnumerable <dynamic>)result, compiled));
        }
コード例 #4
0
        public DaemonCompiledSetterTuple ExecuteDeferredQueryAndCompile <T>(Base.TableMapping map)
        {
            DaemonCompiledSetter <T, sqlite3_stmt> compiled = null;
            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]);
                    }
                }
                compiled = new DaemonCompiledSetter <T, sqlite3_stmt>(cols, fastColumnSetters);
                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(new DaemonCompiledSetterTuple((IEnumerable <dynamic>)result, compiled));
        }