protected override long InternalExecute() { var fields = "*"; var insertCommand = new RowInsertCommand(this.Connection, this.toTable); if (this.fieldDefinitions != null) { fields = this.fieldDefinitions.Select(definition => definition.Name).Join(","); } if (string.IsNullOrEmpty(fields)) { return(0); } if (this.TableDefinition != null) { string sql = string.Format("SELECT {1} FROM {0}", this.TableDefinition.Name.AsDbName(), fields ); // Log.DebugFormat( // "Copy Table:From:'{0}',To:'{1}',Query:'{2}'", // this.TableDefinition.Name.AsDbName(), // this.toTable, // sql // ); this.ExecuteQuery( sql, reader => { var row = TableRow.Read(this.TableDefinition, reader); insertCommand.AddRowForInserting(row); insertCommand.Execute(100); }); } return(0L); }
protected override long InternalExecute() { var fields = "*"; var insertCommand = new RowInsertCommand(this.Connection, this.toTable); if (this.fieldDefinitions != null) { fields = this.fieldDefinitions.Select(definition => definition.Name).Join(","); } if (string.IsNullOrEmpty(fields)) { return 0; } if (this.TableDefinition != null) { string sql = string.Format("SELECT {1} FROM {0}", this.TableDefinition.Name.AsDbName(), fields ); // Log.DebugFormat( // "Copy Table:From:'{0}',To:'{1}',Query:'{2}'", // this.TableDefinition.Name.AsDbName(), // this.toTable, // sql // ); this.ExecuteQuery( sql, reader => { var row = TableRow.Read(this.TableDefinition, reader); insertCommand.AddRowForInserting(row); insertCommand.Execute(100); }); } return 0L; }
/// <summary> /// Add rows to table /// </summary> /// <param name="rows">Row collection</param> /// <returns></returns> public Int64? AddRows(IEnumerable<ITableRow> rows) { Int64? lastRowIdentity = null; ITableRow lastTableRow = null; using (this.Connection.OpenWrapper()) { RowInsertCommand insertCommand = new RowInsertCommand(this.Connection, this.TableDefinition); foreach (ITableRow row in rows) { insertCommand.AddRowForInserting(row); lastTableRow = row; } insertCommand.Execute(100); if (lastTableRow != null) { lastRowIdentity = this.GetRow(lastTableRow); } return lastRowIdentity; } }