[DBMoto][スクリプト]条件付きレプリケーションを行うサンプルVBスクリプト


DBMotoでは下記のような条件付きレプリケーションが可能です。

・値が~を満たすときのみレプリケーション
・登録、更新、削除のうち一部のみレプリケーション

下記は登録・更新・削除時にフィールドの値が20140711未満の場合はレプリケーションしない(20140711以降のみレプリケーション)するためのサンプルスクリプトです。

登録時のみ・・・recSource.OperationType = enmOperationType.Insert
更新時のみ・・・recSource.OperationType = enmOperationType.Update
削除時のみ・・・recSource.OperationType = enmOperationType.Delete
レプリケーションを停止・・・AbortRecord = True
レプリケーションを稼働・・・AbortRecord = False

Imports System
Imports System.Data
Imports Microsoft.VisualBasic
Imports DBMotoPublic
Imports DBMotoScript
Imports DBRS.GlobalScript

Namespace DBRS
    Public Class ReplicationScript : Inherits IReplicationScript
    Public Overrides Sub Record_onBeforeMapping( recSource As DBMotoPublic.IRecord, ByRef AbortRecord As Boolean, ByRef DisableReplication As Boolean)
        ' カラム名の変数
        Dim strField As String
        ' 登録・更新・削除時
        If (recSource.OperationType = enmOperationType.Insert) Or (recSource.OperationType = enmOperationType.Update) Or (recSource.OperationType = enmOperationType.Delete) Then
        ' DBのカラム名を指定して値を取得
        strField = CType(recSource.GetValueAfter("Field").ToString(), Integer)
        ' 20140711 未満はレプリケーションをスキップ(Abort=True)する
        If (strField < "20140711") Then
            AbortRecord = True
        Else
            AbortRecord = False
        End If
        End If
    End Sub

    End Class
End Namespace

関連したトピックス

コメントを残す

メールアドレスが公開されることはありません。

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください