/// <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);
			}
		}
		/// <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();
		}
		/// <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));
		}
		/// <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;
			}
		}
 /// <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?");
		}
		/// <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);
			}
		}
		/// <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);
			}
		}
        /// <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();
            }
        }
        /// <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));
        }
        /// <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;
            }
        }
		/// <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);
			}
		}
 /// <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
            }
        }
 /// <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
            }
        }
		/// <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);
			}
		}
		/// <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);
                }
        }
 /// <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);
		}
		/// <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);
			}
		}
		/// <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);
			}
		}
		/// <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);
		}
		/// <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;
			}
		}