示例#1
0
        internal static void ThrowZeroRows(RowEnum row)
        {
            switch (row)
            { // get the standard exception from the runtime
            case RowEnum.First: ErrZeroRows.First(); break;

            case RowEnum.Single: ErrZeroRows.Single(); break;

            default: throw new InvalidOperationException();
            }
        }
示例#2
0
文件: Row.cs 项目: W4TR1X/ViewTable
        public Row(RowEnum type = RowEnum.Record, bool orderable = false, string identifier = "")
        {
            Orderable = orderable;

            CustomOrderValues = new List <double>();

            Styles = new List <ICellStyle>();

            RowType    = type;
            Identifier = (identifier ?? "").Length == 0 ? $"row_{Guid.NewGuid().ToString().Replace("-", "")}" : identifier;
            Cells      = new List <ICell>();
            Rows       = new List <IRow>();
        }
示例#3
0
        /******************************************************************************************/



        /// <summary>
        /// 查询单行
        /// </summary>
        private static async Task <T> QueryRowAsync <T>(this IDbConnection cnn, RowEnum row, Type effectiveType, CommandDefinition command)
        {
            DynamicParameters param = command.Parameters;
            var  identity           = new Identity(command.CommandText, command.CommandType, cnn, effectiveType, param?.GetType());
            var  info      = GetCacheInfo(identity);
            bool needClose = cnn.State == ConnectionState.Closed;

            using (var cmd = command.TrySetupAsyncCommand(cnn, info.ParamReader))
            {
                DbDataReader reader = null;
                try
                {
                    if (needClose)
                    {
                        await cnn.TryOpenAsync(default(CancellationToken)).ConfigureAwait(false);
                    }
                    reader = await ExecuteReaderWithFlagsFallbackAsync(cmd, needClose, (row & RowEnum.Single) != 0
                                                                       ?CommandBehavior.SequentialAccess | CommandBehavior.SingleResult // need to allow multiple rows, to check fail condition
                                                                       : CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow, default(CancellationToken)).ConfigureAwait(false);

                    T result = default(T);
                    if (await reader.ReadAsync(default(CancellationToken)).ConfigureAwait(false) && reader.FieldCount != 0)
                    {
                        var tuple = info.Deserializer;
                        int hash  = GetColumnHash(reader);
                        if (tuple.Func == null || tuple.Hash != hash)
                        {
                            tuple = info.Deserializer = new DeserializerState(hash, GetDeserializer(effectiveType, reader, 0, -1, false));
                        }

                        var func = tuple.Func;

                        object val = func(reader);
                        if (val == null || val is T)
                        {
                            result = (T)val;
                        }
                        else
                        {
                            var convertToType = Nullable.GetUnderlyingType(effectiveType) ?? effectiveType;
                            result = (T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture);
                        }
                        if ((row & RowEnum.Single) != 0 && await reader.ReadAsync(default(CancellationToken)).ConfigureAwait(false))
                        {
                            ThrowMultipleRows(row);
                        }
                        while (await reader.ReadAsync(default(CancellationToken)).ConfigureAwait(false))
                        { /* ignore rows after the first */
                        }
                    }
                    else if ((row & RowEnum.FirstOrDefault) == 0) // demanding a row, and don't have one
                    {
                        ThrowZeroRows(row);
                    }
                    while (await reader.NextResultAsync(default(CancellationToken)).ConfigureAwait(false))
                    { /* ignore result sets after the first */
                    }
                    return(result);
                }
                finally
                {
                    using (reader)
                    { /* dispose if non-null */ }
                    if (needClose)
                    {
                        cnn.Close();
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// Constructor with no parameters.
 /// </summary>
 public KeyList()
 {
     Keys        = new List <string>();
     HeadersDict = new Dictionary <string, string>();
     Rows        = new RowEnum(this);
 }
示例#5
0
 /// <summary>
 /// Wipes the KeyList to a blank state.
 /// </summary>
 new public void Clear()
 {
     Keys.Clear();
     HeadersDict.Clear();
     Rows = new RowEnum(this);
 }