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