Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the NHybridDataReader class.
        /// </summary>
        /// <param name="reader">The underlying DbDataReader to use.</param>
        /// <param name="inMemory"><see langword="true" /> if the contents of the DbDataReader should be read into memory right away.</param>
        public static NHybridDataReader Create(DbDataReader reader, bool inMemory)
        {
            var dataReader = new NHybridDataReader();

            if (inMemory)
            {
                dataReader._reader = NDataReader.Create(reader, false);
            }
            else
            {
                dataReader._reader = reader;
            }
            return(dataReader);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the NHybridDataReader class.
        /// </summary>
        /// <param name="reader">The underlying DbDataReader to use.</param>
        /// <param name="inMemory"><see langword="true" /> if the contents of the DbDataReader should be read into memory right away.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        public static async Task <NHybridDataReader> CreateAsync(DbDataReader reader, bool inMemory, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var dataReader = new NHybridDataReader();

            if (inMemory)
            {
                dataReader._reader = await(NDataReader.CreateAsync(reader, false, cancellationToken)).ConfigureAwait(false);
            }
            else
            {
                dataReader._reader = reader;
            }
            return(dataReader);
        }
Beispiel #3
0
		public IDataReader ExecuteReader(IDbCommand cmd)
		{
			CheckReaders();
			Prepare(cmd);

			IDataReader reader = cmd.ExecuteReader();

			if (!factory.ConnectionProvider.Driver.SupportsMultipleOpenReaders)
			{
				reader = new NHybridDataReader(reader);
			}

			readersToClose.Add(reader);
			LogOpenReader();
			return reader;
		}
		public IDataReader ExecuteReader(IDbCommand cmd)
		{
			CheckReaders();
            LogCommand(cmd);
            Prepare(cmd);
			Stopwatch duration = null;
			if (log.IsDebugEnabled)
				duration = Stopwatch.StartNew();
			IDataReader reader = null;
		    try
		    {
		        reader = cmd.ExecuteReader();
		    }
		    catch (Exception e)
		    {
		        e.Data["actual-sql-query"] = cmd.CommandText;
		    	log.Error("Could not execute query: " + cmd.CommandText, e);
		        throw;
		    }
			finally
		    {
		    	if(log.IsDebugEnabled && duration != null && reader != null)
		    	{
		    		log.DebugFormat("ExecuteReader took {0} ms", duration.ElapsedMilliseconds);
					readersDuration[reader] = duration;
		    	}
		    }

		    if (!factory.ConnectionProvider.Driver.SupportsMultipleOpenReaders)
			{
				reader = new NHybridDataReader(reader);
			}

			readersToClose.Add(reader);
			LogOpenReader();
			return reader;
		}