コード例 #1
1
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			if (reader == null) throw new ArgumentNullException("reader");
			if (transaction != null)
				throw new ArgumentException("OracleProvider does not support external transactions for bulk copy", "transaction");

			OracleBulkCopyOptions oracleOptions = OracleBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				oracleOptions |= OracleBulkCopyOptions.UseInternalTransaction;

			using (var bulk = new OracleBulkCopy((OracleConnection)connection, oracleOptions))
			using (var insightBulk = new OracleInsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;

				// map the columns by name, in case we skipped a readonly column
				foreach (DataRow row in reader.GetSchemaTable().Rows)
					bulk.ColumnMappings.Add((string)row["ColumnName"], (string)row["ColumnName"]);

				if (configure != null)
					configure(insightBulk);
				bulk.WriteToServer(reader);
			}
		}
コード例 #2
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public virtual void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			throw new NotImplementedException();
		}
コード例 #3
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public virtual void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			throw CreateNotRegisteredException(connection, String.Format(CultureInfo.InvariantCulture, "Cannot bulk copy into table {0}", tableName));
		}
コード例 #4
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			if (reader == null) throw new ArgumentNullException("reader");

			NpgsqlCopyIn bulk = new NpgsqlCopyIn(String.Format(CultureInfo.InvariantCulture, "COPY {0} FROM STDIN WITH CSV", tableName), (NpgsqlConnection)connection);
			PostgreSQLInsightBulkCopy insightBulkCopy = new PostgreSQLInsightBulkCopy(bulk);

			try
			{
				bulk.Start();

				var stream = bulk.CopyStream;
				StreamWriter writer = new StreamWriter(stream);

				int row = 0;
				while (reader.Read())
				{
					for (int i = 0; i < reader.FieldCount; i++)
					{
						if (i > 0)
							writer.Write(CsvDelimiter);

						object value = reader.GetValue(i);

						if (value != DBNull.Value)
						{
							writer.Write(CsvQuote);
							writer.Write(_csvRegex.Replace(value.ToString(), CsvReplacement));
							writer.Write(CsvQuote);
						}
					}

					writer.WriteLine();

					row++;
					if (insightBulkCopy.NotifyAfter != 0 && row % insightBulkCopy.NotifyAfter == 0)
					{
						InsightRowsCopiedEventArgs e = new InsightRowsCopiedEventArgs();
						e.RowsCopied = row;
						insightBulkCopy.OnRowsCopied(insightBulkCopy, e);
						if (e.Abort)
						{
							bulk.Cancel("Cancelled");
							return;
						}
					}
				}

				// must call flush before end
				// cannot call close on the stream before end
				writer.Flush();
				bulk.End();
			}
			catch (Exception e)
			{
				bulk.Cancel(e.Message);

				throw;
			}
		}
コード例 #5
0
 /// <summary>
 /// Bulk copies a set of objects to the server.
 /// </summary>
 /// <param name="connection">The connection to use.</param>
 /// <param name="tableName">The name of the table.</param>
 /// <param name="reader">The reader to read objects from.</param>
 /// <param name="configure">A callback method to configure the bulk copy object.</param>
 /// <param name="options">Options for initializing the bulk copy object.</param>
 /// <param name="transaction">An optional transaction to participate in.</param>
 /// <remarks>Number of rows copied.</remarks>
 public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
 {
     connection = GetInnerConnection(connection);
     InsightDbProvider.For(connection).BulkCopy(connection, tableName, reader, configure, options, transaction);
 }
コード例 #6
0
        /// <summary>
        /// Prepares the bulk copy operation.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        /// <returns>The configured bulk copy object.</returns>
        private static SqlInsightBulkCopy PrepareBulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            SqlBulkCopyOptions sqlOptions = SqlBulkCopyOptions.Default;

            if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
            {
                sqlOptions |= SqlBulkCopyOptions.KeepIdentity;
            }
            if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
            {
                sqlOptions |= SqlBulkCopyOptions.FireTriggers;
            }
            if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
            {
                sqlOptions |= SqlBulkCopyOptions.CheckConstraints;
            }
            if (options.HasFlag(InsightBulkCopyOptions.TableLock))
            {
                sqlOptions |= SqlBulkCopyOptions.TableLock;
            }
            if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
            {
                sqlOptions |= SqlBulkCopyOptions.KeepNulls;
            }
            if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
            {
                sqlOptions |= SqlBulkCopyOptions.UseInternalTransaction;
            }

            SqlBulkCopy        bulk        = null;
            SqlInsightBulkCopy insightBulk = null;

            try
            {
                bulk = new SqlBulkCopy((SqlConnection)connection, sqlOptions, (SqlTransaction)transaction);
                bulk.DestinationTableName = tableName;
                bulk.EnableStreaming      = true;

                // map the columns by name, in case we skipped a readonly column
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    string fieldName = reader.GetName(i);
                    bulk.ColumnMappings.Add(fieldName, fieldName);
                }

                insightBulk = new SqlInsightBulkCopy(bulk);
                bulk        = null;

                if (configure != null)
                {
                    configure(insightBulk);
                }

                return(insightBulk);
            }
            catch
            {
                if (insightBulk != null)
                {
                    insightBulk.Dispose();
                }
                if (bulk != null)
                {
                    ((IDisposable)bulk).Dispose();
                }

                throw;
            }
        }
コード例 #7
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public virtual void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			throw new NotImplementedException("Cannot bulk copy into this database. Have you loaded the provider for your database?");
		}
コード例 #8
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			var bcp = PrepareBulkCopy(connection, tableName, reader, configure, options, transaction);

			using (bcp)
			{
				bcp.BulkCopy.WriteToServer(reader);
			}
		}
コード例 #9
0
		/// <summary>
		/// Asynchronously bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		/// <param name="ct">The cancellation token that can be used to cancel the operation.</param>
		/// <remarks>Number of rows copied if supported, -1 otherwise.</remarks>
		/// <returns>A task representing the completion of the operation.</returns>
		public override async Task BulkCopyAsync(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction, System.Threading.CancellationToken ct)
		{
			using (var bcp = PrepareBulkCopy(connection, tableName, reader, configure, options, transaction))
			{
				await bcp.BulkCopy.WriteToServerAsync(reader).ConfigureAwait(false);
			}
		}
コード例 #10
0
        /// <summary>
        /// Bulk copies a set of objects to the server.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var pgconnection = (NpgsqlConnection)connection;

            using (var writer = pgconnection.BeginTextImport(String.Format(CultureInfo.InvariantCulture, "COPY {0} FROM STDIN WITH CSV", tableName)))
            {
                PostgreSQLInsightBulkCopy insightBulkCopy = new PostgreSQLInsightBulkCopy();

                int row = 0;
                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        if (i > 0)
                        {
                            writer.Write(CsvDelimiter);
                        }

                        object value = reader.GetValue(i);

                        if (value != DBNull.Value)
                        {
                            writer.Write(CsvQuote);
                            writer.Write(_csvRegex.Replace(value.ToString(), CsvReplacement));
                            writer.Write(CsvQuote);
                        }
                    }

                    writer.WriteLine();

                    row++;
                    if (insightBulkCopy.NotifyAfter != 0 && row % insightBulkCopy.NotifyAfter == 0)
                    {
                        InsightRowsCopiedEventArgs e = new InsightRowsCopiedEventArgs();
                        e.RowsCopied = row;
                        insightBulkCopy.OnRowsCopied(insightBulkCopy, e);
                        if (e.Abort)
                        {
                            return;
                        }
                    }
                }

                // must call flush before end
                // cannot call close on the stream before end
                writer.Flush();
            }
        }
コード例 #11
0
        /// <inheritdoc/>
        public override Task BulkCopyAsync(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction, CancellationToken cancellationToken)
        {
            DbConnectionWrapper wrapped = (DbConnectionWrapper)connection;

            return(base.BulkCopyAsync(connection, tableName, reader, configure, options, transaction ?? wrapped.InnerTransaction, cancellationToken));
        }
コード例 #12
0
        /// <summary>
        /// Bulk copies a set of objects to the server.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            NpgsqlCopyIn bulk = new NpgsqlCopyIn(String.Format(CultureInfo.InvariantCulture, "COPY {0} FROM STDIN WITH CSV", tableName), (NpgsqlConnection)connection);
            PostgreSQLInsightBulkCopy insightBulkCopy = new PostgreSQLInsightBulkCopy(bulk);

            try
            {
                bulk.Start();

                var          stream = bulk.CopyStream;
                StreamWriter writer = new StreamWriter(stream);

                int row = 0;
                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        if (i > 0)
                        {
                            writer.Write(CsvDelimiter);
                        }

                        object value = reader.GetValue(i);

                        if (value != DBNull.Value)
                        {
                            writer.Write(CsvQuote);
                            writer.Write(_csvRegex.Replace(value.ToString(), CsvReplacement));
                            writer.Write(CsvQuote);
                        }
                    }

                    writer.WriteLine();

                    row++;
                    if (insightBulkCopy.NotifyAfter != 0 && row % insightBulkCopy.NotifyAfter == 0)
                    {
                        InsightRowsCopiedEventArgs e = new InsightRowsCopiedEventArgs();
                        e.RowsCopied = row;
                        insightBulkCopy.OnRowsCopied(insightBulkCopy, e);
                        if (e.Abort)
                        {
                            bulk.Cancel("Cancelled");
                            return;
                        }
                    }
                }

                // must call flush before end
                // cannot call close on the stream before end
                writer.Flush();
                bulk.End();
            }
            catch (Exception e)
            {
                bulk.Cancel(e.Message);

                throw;
            }
        }
コード例 #13
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		/// <remarks>Number of rows copied if supported, -1 otherwise.</remarks>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			SqlBulkCopyOptions sqlOptions = SqlBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
				sqlOptions |= SqlBulkCopyOptions.KeepIdentity;
			if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
				sqlOptions |= SqlBulkCopyOptions.FireTriggers;
			if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
				sqlOptions |= SqlBulkCopyOptions.CheckConstraints;
			if (options.HasFlag(InsightBulkCopyOptions.TableLock))
				sqlOptions |= SqlBulkCopyOptions.TableLock;
			if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
				sqlOptions |= SqlBulkCopyOptions.KeepNulls;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				sqlOptions |= SqlBulkCopyOptions.UseInternalTransaction;

			using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)connection, sqlOptions, (SqlTransaction)transaction))
			using (var insightBulk = new SqlInsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;
#if !NODBASYNC
				bulk.EnableStreaming = true;
#endif
				if (configure != null)
					configure(insightBulk);
				bulk.WriteToServer(reader);
			}
		}
コード例 #14
0
 /// <inheritdoc/>
 public override Task BulkCopyAsync(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction, CancellationToken cancellationToken)
 {
     connection = GetInnerConnection(connection);
     return InsightDbProvider.For(connection).BulkCopyAsync(connection, tableName, reader, configure, options, transaction, cancellationToken);
 }
コード例 #15
0
        /// <summary>
        /// Bulk copies a set of objects to the server.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            var bcp = PrepareBulkCopy(connection, tableName, reader, configure, options, transaction);

            using (bcp)
            {
#if NETSTANDARD1_5
                bcp.BulkCopy.WriteToServer((DbDataReader)reader);
#else
                bcp.BulkCopy.WriteToServer(reader);
#endif
            }
        }
コード例 #16
0
 /// <summary>
 /// Bulk copies a set of objects to the server.
 /// </summary>
 /// <param name="connection">The connection to use.</param>
 /// <param name="tableName">The name of the table.</param>
 /// <param name="reader">The reader to read objects from.</param>
 /// <param name="configure">A callback method to configure the bulk copy object.</param>
 /// <param name="options">Options for initializing the bulk copy object.</param>
 /// <param name="transaction">An optional transaction to participate in.</param>
 public virtual void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
 {
     throw CreateNotRegisteredException(connection, String.Format(CultureInfo.InvariantCulture, "Cannot bulk copy into table {0}", tableName));
 }
コード例 #17
0
        /// <summary>
        /// Asynchronously bulk copies a set of objects to the server.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        /// <param name="cancellationToken">The cancellation token that can be used to cancel the operation.</param>
        /// <remarks>Number of rows copied if supported, -1 otherwise.</remarks>
        /// <returns>A task representing the completion of the operation.</returns>
        public override async Task BulkCopyAsync(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction, System.Threading.CancellationToken cancellationToken)
        {
            using (var bcp = PrepareBulkCopy(connection, tableName, reader, configure, options, transaction))
            {
#if NETSTANDARD1_5
                await bcp.BulkCopy.WriteToServerAsync((DbDataReader)reader).ConfigureAwait(false);
#else
                await bcp.BulkCopy.WriteToServerAsync(reader).ConfigureAwait(false);
#endif
            }
        }
コード例 #18
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			if (transaction != null)
				throw new ArgumentException("OracleProvider does not support external transactions for bulk copy", "transaction");

			DB2BulkCopyOptions db2Options = DB2BulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
				db2Options |= DB2BulkCopyOptions.KeepIdentity;
			if (options.HasFlag(InsightBulkCopyOptions.TableLock))
				db2Options |= DB2BulkCopyOptions.TableLock;
			if (options.HasFlag(InsightBulkCopyOptions.Truncate))
				db2Options |= DB2BulkCopyOptions.Truncate;

			using (var bulk = new DB2BulkCopy((DB2Connection)connection, db2Options))
			using (var insightBulk = new DB2InsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;
				if (configure != null)
					configure(insightBulk);
				bulk.WriteToServer(reader);
			}
		}
コード例 #19
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			if (transaction != null)
				throw new ArgumentException("OracleProvider does not support external transactions for bulk copy", "transaction");

			OracleBulkCopyOptions oracleOptions = OracleBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				oracleOptions |= OracleBulkCopyOptions.UseInternalTransaction;

			using (var bulk = new OracleBulkCopy((OracleConnection)connection, oracleOptions))
			using (var oracleBulk = new OracleInsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;
				if (configure != null)
					configure(oracleBulk);
				bulk.WriteToServer(reader);
			}
		}
コード例 #20
0
        /// <summary>
        /// Prepares the bulk copy operation.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        /// <returns>The configured bulk copy object.</returns>
        private SqlInsightBulkCopy PrepareBulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            SqlBulkCopyOptions sqlOptions = SqlBulkCopyOptions.Default;

            if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
            {
                sqlOptions |= SqlBulkCopyOptions.KeepIdentity;
            }
            if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
            {
                sqlOptions |= SqlBulkCopyOptions.FireTriggers;
            }
            if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
            {
                sqlOptions |= SqlBulkCopyOptions.CheckConstraints;
            }
            if (options.HasFlag(InsightBulkCopyOptions.TableLock))
            {
                sqlOptions |= SqlBulkCopyOptions.TableLock;
            }
            if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
            {
                sqlOptions |= SqlBulkCopyOptions.KeepNulls;
            }
            if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
            {
                sqlOptions |= SqlBulkCopyOptions.UseInternalTransaction;
            }

            SqlBulkCopy        bulk        = null;
            SqlInsightBulkCopy insightBulk = null;

            try
            {
                bulk        = new SqlBulkCopy((SqlConnection)connection, sqlOptions, (SqlTransaction)transaction);
                insightBulk = new SqlInsightBulkCopy(bulk);

                bulk.DestinationTableName = tableName;
#if !NODBASYNC
                bulk.EnableStreaming = true;
#endif

                // map the columns by name, in case we skipped a readonly column
                foreach (DataRow row in reader.GetSchemaTable().Rows)
                {
                    bulk.ColumnMappings.Add((string)row["ColumnName"], (string)row["ColumnName"]);
                }

                if (configure != null)
                {
                    configure(insightBulk);
                }

                return(insightBulk);
            }
            catch
            {
                if (insightBulk != null)
                {
                    insightBulk.Dispose();
                }

                throw;
            }
        }
コード例 #21
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		/// <param name="cancellationToken">A token that can be used to cancel the operation.</param>
		/// <returns>A task representing the completion of the bulk copy.</returns>
		public virtual Task BulkCopyAsync(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction, CancellationToken cancellationToken)
		{
			// default - punt to the sync version
			return Task.Factory.StartNew(() => BulkCopy(connection, tableName, reader, configure, options, transaction));
		}
コード例 #22
0
        /// <summary>
        /// Bulk copies a set of objects to the server.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            AseBulkCopyOptions aseOptions = AseBulkCopyOptions.Default;

            if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
            {
                aseOptions |= AseBulkCopyOptions.CheckConstraints;
            }
            if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
            {
                aseOptions |= AseBulkCopyOptions.FireTriggers;
            }
            if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
            {
                aseOptions |= AseBulkCopyOptions.KeepIdentity;
            }
            if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
            {
                aseOptions |= AseBulkCopyOptions.KeepNulls;
            }
            if (options.HasFlag(InsightBulkCopyOptions.TableLock))
            {
                aseOptions |= AseBulkCopyOptions.TableLock;
            }
            if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
            {
                aseOptions |= AseBulkCopyOptions.UseInternalTransaction;
            }

            using (var bulk = new AseBulkCopy((AseConnection)connection, aseOptions, (AseTransaction)transaction))
                using (var insightBulk = new SybaseAseInsightBulkCopy(bulk))
                {
                    bulk.DestinationTableName = tableName;

                    // map the columns by name, in case we skipped a readonly column
                    foreach (DataRow row in reader.GetSchemaTable().Rows)
                    {
                        bulk.ColumnMappings.Add(new AseBulkCopyColumnMapping((string)row["ColumnName"], (string)row["ColumnName"]));
                    }

                    if (configure != null)
                    {
                        configure(insightBulk);
                    }
                    bulk.WriteToServer(reader);
                }
        }
コード例 #23
0
 /// <inheritdoc/>
 public override Task BulkCopyAsync(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction, CancellationToken cancellationToken)
 {
     connection = GetInnerConnection(connection);
     return(InsightDbProvider.For(connection).BulkCopyAsync(connection, tableName, reader, configure, options, transaction, cancellationToken));
 }
		/// <inheritdoc/>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			DbConnectionWrapper wrapped = (DbConnectionWrapper)connection;

			base.BulkCopy(connection, tableName, reader, configure, options, transaction ?? wrapped.InnerTransaction);
		}
コード例 #25
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			AseBulkCopyOptions aseOptions = AseBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
				aseOptions |= AseBulkCopyOptions.CheckConstraints;
			if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
				aseOptions |= AseBulkCopyOptions.FireTriggers;
			if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
				aseOptions |= AseBulkCopyOptions.KeepIdentity;
			if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
				aseOptions |= AseBulkCopyOptions.KeepNulls;
			if (options.HasFlag(InsightBulkCopyOptions.TableLock))
				aseOptions |= AseBulkCopyOptions.TableLock;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				aseOptions |= AseBulkCopyOptions.UseInternalTransaction;

			using (var bulk = new AseBulkCopy((AseConnection)connection, aseOptions, (AseTransaction)transaction))
			using (var insightBulk = new SybaseAseInsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;
				if (configure != null)
					configure(insightBulk);
				bulk.WriteToServer(reader);
			}
		}
コード例 #26
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		/// <remarks>Number of rows copied if supported, -1 otherwise.</remarks>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			if (reader == null) throw new ArgumentNullException("reader");

			SqlBulkCopyOptions sqlOptions = SqlBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
				sqlOptions |= SqlBulkCopyOptions.KeepIdentity;
			if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
				sqlOptions |= SqlBulkCopyOptions.FireTriggers;
			if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
				sqlOptions |= SqlBulkCopyOptions.CheckConstraints;
			if (options.HasFlag(InsightBulkCopyOptions.TableLock))
				sqlOptions |= SqlBulkCopyOptions.TableLock;
			if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
				sqlOptions |= SqlBulkCopyOptions.KeepNulls;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				sqlOptions |= SqlBulkCopyOptions.UseInternalTransaction;

			using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)connection, sqlOptions, (SqlTransaction)transaction))
			using (var insightBulk = new SqlInsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;
#if !NODBASYNC
				bulk.EnableStreaming = true;
#endif

				// map the columns by name, in case we skipped a readonly column
				foreach (DataRow row in reader.GetSchemaTable().Rows)
					bulk.ColumnMappings.Add((string)row["ColumnName"], (string)row["ColumnName"]);

				if (configure != null)
					configure(insightBulk);
				bulk.WriteToServer(reader);
			}
		}
コード例 #27
0
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		/// <remarks>Number of rows copied.</remarks>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			connection = GetInnerConnection(connection);
			InsightDbProvider.For(connection).BulkCopy(connection, tableName, reader, configure, options, transaction);
		}
コード例 #28
0
		/// <summary>
		/// Prepares the bulk copy operation.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		/// <returns>The configured bulk copy object.</returns>
		private static SqlInsightBulkCopy PrepareBulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			if (reader == null) throw new ArgumentNullException("reader");

			SqlBulkCopyOptions sqlOptions = SqlBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
				sqlOptions |= SqlBulkCopyOptions.KeepIdentity;
			if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
				sqlOptions |= SqlBulkCopyOptions.FireTriggers;
			if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
				sqlOptions |= SqlBulkCopyOptions.CheckConstraints;
			if (options.HasFlag(InsightBulkCopyOptions.TableLock))
				sqlOptions |= SqlBulkCopyOptions.TableLock;
			if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
				sqlOptions |= SqlBulkCopyOptions.KeepNulls;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				sqlOptions |= SqlBulkCopyOptions.UseInternalTransaction;

			SqlBulkCopy bulk = null;
			SqlInsightBulkCopy insightBulk = null;

			try
			{
				bulk = new SqlBulkCopy((SqlConnection)connection, sqlOptions, (SqlTransaction)transaction);
				bulk.DestinationTableName = tableName;
#if !NODBASYNC
				bulk.EnableStreaming = true;
#endif

				// map the columns by name, in case we skipped a readonly column
				foreach (DataRow row in reader.GetSchemaTable().Rows)
					bulk.ColumnMappings.Add((string)row["ColumnName"], (string)row["ColumnName"]);

				insightBulk = new SqlInsightBulkCopy(bulk);
				bulk = null;

				if (configure != null)
					configure(insightBulk);

				return insightBulk;
			}
			catch
			{
				if (insightBulk != null)
					insightBulk.Dispose();
				if (bulk != null)
					((IDisposable)bulk).Dispose();

				throw;
			}
		}