Exemple #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);
        }
        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);
        }
        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));
        }
 public override List <T> ExecuteQuery <T>(Base.TableMapping map)
 {
     return(ExecuteDeferredQuery <T>(map).ToList());
 }
Exemple #5
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));
        }
Exemple #6
0
 public static NotNullConstraintViolationException New(SqlServerException exception, Base.TableMapping mapping, object obj)
 {
     return(new NotNullConstraintViolationException(exception.Result, exception.Message, mapping, obj));
 }
Exemple #7
0
 public static NotNullConstraintViolationException New(SQLite3.Result r, string message, Base.TableMapping mapping, object obj)
 {
     return(new NotNullConstraintViolationException(r, message, mapping, obj));
 }
Exemple #8
0
 protected NotNullConstraintViolationException(SQLite3.Result r, string message, Base.TableMapping mapping, object obj)
     : base(r, message)
 {
     if (mapping != null && obj != null)
     {
         this.Columns = from c in mapping.Columns
                        where c.IsNullable == false && c.GetValue(obj) == null
                        select c;
     }
 }
Exemple #9
0
 public NotifyTableChangedEventArgs(Base.TableMapping table, NotifyTableChangedAction action)
 {
     Table  = table;
     Action = action;
 }