查找 SSIS 脚本组件中的最后一行

发布于 2024-10-20 19:11:12 字数 153 浏览 4 评论 0原文

我有一个 SSIS 2008 脚本组件,它使用以下方法

Input0_ProcessInputRow(Input0Buffer 行)

来处理行。有没有办法确定我正在读取的行是否是数据集中的最后一行。

I have an SSIS 2008 script component and it uses the method

Input0_ProcessInputRow(Input0Buffer
Row)

to process the Rows. Is there a way to find if the Row I'm reading is the Last Row in the Dataset.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

你与清晨阳光 2024-10-27 19:11:12
if (Row.EndOfRowset()) { // this is the last row }
if (Row.EndOfRowset()) { // this is the last row }
绮筵 2024-10-27 19:11:12

重写 InputRows_ProcessInput 的解决方案对我有用。但是,不要随意使用该代码。方法的名称取决于您的输入的名称。在我的例子中,方法签名是:

public override void Input0_ProcessInput(Input0Buffer Buffer)

找出正确方法的一个简单方法是进入脚本并输入“base.Input”intellisense 应该为您提供正确的重写方法。

public override void **Input0_ProcessInput**(**Input0Buffer** Buffer)
    {
        while (Buffer.NextRow())
        {
            Input0_ProcessInputRow(Buffer);
        }

        if (Buffer.EndOfRowset()) 
        {
            //do something 
        }
    }

仅仅检查“Buffer.EndOfRowset()”是不够的,并且它在“while (Buffer.NextRow())”循环中不起作用。所以我猜“EndOfRowset”发生在最后一行之后。

The solution of overriding InputRows_ProcessInput worked for me. However, don't use the code litterally. The name of the method depends on the name of your Input. In my case the method signature was:

public override void Input0_ProcessInput(Input0Buffer Buffer)

An easy way to find out the correct method is to go in the script and type "base.Input" intellisense should provide you the correct method to override.

public override void **Input0_ProcessInput**(**Input0Buffer** Buffer)
    {
        while (Buffer.NextRow())
        {
            Input0_ProcessInputRow(Buffer);
        }

        if (Buffer.EndOfRowset()) 
        {
            //do something 
        }
    }

Simply checking for "Buffer.EndOfRowset()" is not sufficient and it doesn't work inside the "while (Buffer.NextRow())" loop. So I guess the "EndOfRowset" occurs after the last row.

拍不死你 2024-10-27 19:11:12

我以前没有尝试过,但在您的脚本组件之前,添加一个 RowCount 任务并在此任务中设置一个变量的值(称为 RowCnt,此处初始化为 0)。然后在您的脚本中,有类似这样的内容(确保变量声明的范围在类中)...

Public Class ScriptMain
Inherits UserComponent

Dim iRows As Integer

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    iRows = iRows + 1
    If iRows = Variables.RowCnt Then
        'Do something here
    End If
End Sub

End Class

这应该允许您处理最后一行。

I've not tried this before, but before your Script Component, add a RowCount Task and set the value of a variable (called RowCnt, initialised to 0 here) in this task. Then in your script, have something like this (ensure the variable declaration is scoped in the Class)...

Public Class ScriptMain
Inherits UserComponent

Dim iRows As Integer

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    iRows = iRows + 1
    If iRows = Variables.RowCnt Then
        'Do something here
    End If
End Sub

End Class

That should allow you to process the final row.

猥琐帝 2024-10-27 19:11:12

重写 InputRows_ProcessInput 方法,如下所示:

public override void InputRows_ProcessInput(InputRowsBuffer Buffer)
    {

        while (Buffer.NextRow())
        {
            InputRows_ProcessInputRow(Buffer);
        }

        if (Buffer.EndOfRowset()) 
        {
            //do something 
        }

    }

Override the InputRows_ProcessInput method as follows:

public override void InputRows_ProcessInput(InputRowsBuffer Buffer)
    {

        while (Buffer.NextRow())
        {
            InputRows_ProcessInputRow(Buffer);
        }

        if (Buffer.EndOfRowset()) 
        {
            //do something 
        }

    }
征棹 2024-10-27 19:11:12

自定义脚本代码写在 ScriptMain 类中。该类继承自 UserComponent,其中包含一个虚拟方法 FinishOutputs()。您可以在 ScriptMain 中覆盖它以执行最后一行之后需要运行的代码。

UserComponent 中的相关代码。

public override void ProcessInput(int InputID, string InputName, PipelineBuffer Buffer, OutputNameMap OutputMap)
{

    if (InputName.Equals(@"Input 0", StringComparison.Ordinal))
    {
        Input0_ProcessInput(new Input0Buffer(Buffer, GetColumnIndexes(InputID), OutputMap));
    }

    if (Buffer.EndOfRowset)
    {
        InputsFinished = InputsFinished + 1;
        if (InputsFinished == 1)
        {
            FinishOutputs();
            MarkOutputsFinished();
        }
    }

}

public virtual void FinishOutputs()
{
}

请注意,此代码是自动生成的,无法更改。然而,它确实有效地为您提供了放置代码的位置,因为您可以在 ScriptMain 中的代码中重写 FinishOutputs(),如下所示:

public override void FinishOutputs()
{
   //do stuff
}

The custom script code is written inside the ScriptMain class. This class inherits from UserComponent which contains a virtual method FinishOutputs(). You can override this in ScriptMain to execute the code you need to run after the last row.

Relevant code in UserComponent.

public override void ProcessInput(int InputID, string InputName, PipelineBuffer Buffer, OutputNameMap OutputMap)
{

    if (InputName.Equals(@"Input 0", StringComparison.Ordinal))
    {
        Input0_ProcessInput(new Input0Buffer(Buffer, GetColumnIndexes(InputID), OutputMap));
    }

    if (Buffer.EndOfRowset)
    {
        InputsFinished = InputsFinished + 1;
        if (InputsFinished == 1)
        {
            FinishOutputs();
            MarkOutputsFinished();
        }
    }

}

public virtual void FinishOutputs()
{
}

Notice that this code is auto-generated and cannot be changed. It does however effectively give you place to put your code as you can override FinishOutputs() in your code within ScriptMain like this:

public override void FinishOutputs()
{
   //do stuff
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文