Beispiel #1
0
        public void Fill(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever)
        {
            using (HeavyProfiler.Log("SQL", () => Command.sp_executesql()))
                using (var reader = Executor.UnsafeExecuteDataReader(Command))
                {
                    ProjectionRowEnumerator <KeyValuePair <K, V> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, V> >(reader.Reader, ProjectorExpression, lookups, retriever, CancellationToken.None);

                    IEnumerable <KeyValuePair <K, V> > enumerabe = new ProjectionRowEnumerable <KeyValuePair <K, V> >(enumerator);

                    try
                    {
                        var lookUp = enumerabe.ToLookup(a => a.Key, a => a.Value);

                        lookups.Add(Token, lookUp);
                    }
                    catch (Exception ex)
                    {
                        FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex);
                        fieldEx.Command   = Command;
                        fieldEx.Row       = enumerator.Row;
                        fieldEx.Projector = ProjectorExpression;
                        throw fieldEx;
                    }
                }
        }
    public Exception HandleException(Exception ex, SqlPreCommandSimple command)
    {
        var nex = ReplaceException(ex, command);

        nex.Data["Sql"] = command.sp_executesql();
        return(nex);
    }
    protected internal override object?ExecuteScalar(SqlPreCommandSimple preCommand, CommandType commandType)
    {
        return(EnsureConnectionRetry(con =>
        {
            using (NpgsqlCommand cmd = NewCommand(preCommand, con, commandType))
                using (HeavyProfiler.Log("SQL", () => preCommand.sp_executesql()))
                {
                    try
                    {
                        object?result = cmd.ExecuteScalar();

                        if (result == null || result == DBNull.Value)
                        {
                            return null;
                        }

                        return result;
                    }
                    catch (Exception ex)
                    {
                        var nex = HandleException(ex, preCommand);
                        if (nex == ex)
                        {
                            throw;
                        }

                        throw nex;
                    }
                }
        }));
    }
    protected internal override int ExecuteNonQuery(SqlPreCommandSimple preCommand, CommandType commandType)
    {
        return(EnsureConnectionRetry(con =>
        {
            using (NpgsqlCommand cmd = NewCommand(preCommand, con, commandType))
                using (HeavyProfiler.Log("SQL", () => preCommand.sp_executesql()))
                {
                    try
                    {
                        int result = cmd.ExecuteNonQuery();
                        return result;
                    }
                    catch (Exception ex)
                    {
                        var nex = HandleException(ex, preCommand);
                        if (nex == ex)
                        {
                            throw;
                        }

                        throw nex;
                    }
                }
        }));
    }
    protected internal override DataTable ExecuteDataTable(SqlPreCommandSimple preCommand, CommandType commandType)
    {
        return(EnsureConnectionRetry(con =>
        {
            using (NpgsqlCommand cmd = NewCommand(preCommand, con, commandType))
                using (HeavyProfiler.Log("SQL", () => preCommand.sp_executesql()))
                {
                    try
                    {
                        NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd);

                        DataTable result = new DataTable();
                        da.Fill(result);
                        return result;
                    }
                    catch (Exception ex)
                    {
                        var nex = HandleException(ex, preCommand);
                        if (nex == ex)
                        {
                            throw;
                        }

                        throw nex;
                    }
                }
        }));
    }
Beispiel #6
0
        public void Fill(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever)
        {
            Dictionary <K, MList <V> >?requests = (Dictionary <K, MList <V> >?)lookups.TryGetC(Token);

            if (requests == null)
            {
                return;
            }

            using (HeavyProfiler.Log("SQL", () => Command.sp_executesql()))
                using (var reader = Executor.UnsafeExecuteDataReader(Command))
                {
                    ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> >(reader.Reader, ProjectorExpression, lookups, retriever, CancellationToken.None);

                    IEnumerable <KeyValuePair <K, MList <V> .RowIdElement> > enumerabe = new ProjectionRowEnumerable <KeyValuePair <K, MList <V> .RowIdElement> >(enumerator);

                    try
                    {
                        var lookUp = enumerabe.ToLookup(a => a.Key, a => a.Value);
                        foreach (var kvp in requests)
                        {
                            var results = lookUp[kvp.Key];

                            ((IMListPrivate <V>)kvp.Value).InnerList.AddRange(results);
                            ((IMListPrivate <V>)kvp.Value).InnerListModified(results.Select(a => a.Element).ToList(), null);
                            retriever.ModifiablePostRetrieving(kvp.Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex);
                        fieldEx.Command   = Command;
                        fieldEx.Row       = enumerator.Row;
                        fieldEx.Projector = ProjectorExpression;
                        throw fieldEx;
                    }
                }
        }