Thread Rating:
  • 385 Vote(s) - 2.82 Average
  • 1
  • 2
  • 3
  • 4
  • 5
修正したレコードだけを抽出したい
11-20-2013, 01:41 PM,
#6
RE: 修正したレコードだけを抽出したい
「TRUEの値をFALSEに修正したけど、またTRUEに修正した」場合に、
元に戻っているのだから、「変更されたレコード」としては扱いたくない、
というケースでは、スナップショットを取っておいて、比較するほうが簡単な気がしてきました。

Libライブラリの、RecordSetUtil.clone を使って、レコードセットのクローンを作成しています。
(厳密には、レコードフィールドの増減なども判別する必要がありそうですが・・・)


Code:
{import * from COM.CURL.LIB.DATA-ACCESS}
{let snapshot-rs:#RecordSet = null}

{def RECORD-INDEX = "RECORD-INDEX"}

{def rs =
    {RecordSet
        {RecordFields
            {RecordField "select", domain = bool, caption = "選択"},
            {RecordField RECORD-INDEX, domain = int, caption = "番号"},
            {RecordField "First", domain = String, caption = "名前"},
            {RecordField "Last", domain = String, caption = "苗字"},
            {RecordField "Age", domain = int, caption = "年齢"},
            {RecordField "updated?", domain = bool, caption = "修正?"}
        }
    }
}

{def grid = {RecordGrid record-source = rs, height= 2in}}

{do
    {with rs.batch-events? = true do
        {for i:int = 0 to 3 do
            def new-r = {rs.new-record}
            set new-r[RECORD-INDEX] = i
            {rs.append new-r}
        }
        {rs.commit}
    }
}

{value grid}

{CommandButton
    label = "スナップショット",
    {on Action do
        {if-non-null rs = grid.record-source then
            set snapshot-rs = {RecordSetUtil.clone rs}
        }
    }
}


{CommandButton
    label = "比較",
    {on Action do
        {if-non-null snapshot-rs then
            {if-non-null rs = grid.record-source then
                def vb = {VBox}
                {for r key idx:int in grid.records do
                    {if-non-null cmp-r =
                        {snapshot-rs.select-one
                            filter = {RecordFilter
                                         {proc {tg-r:Record}:bool
                                             {if r[RECORD-INDEX] == tg-r[RECORD-INDEX] then
                                                 {return true}
                                              else
                                                 {return false}
                                             }
                                         }
                                     }
                        }
                     then
                        let equal?:bool = true
                        {for rf in rs.fields do
                            {if r[rf.name]  != cmp-r[rf.name] then
                                set equal? = false
                                {break}
                            }
                        }

                        {if not equal? then
                            {vb.add idx + 1 & "行目" & r["First"]}
                        }

                    }
                }
                {if vb.child-array.size > 0 then
                    {vb.add index = 0 , "以下のレコードは修正されています"}
                    {popup-message vb}
                 else
                    {popup-message "編集中のレコードはありません"}
                }
            }
        }
    }
}


Messages In This Thread
RE: 修正したレコードだけを抽出したい - by umemura - 11-20-2013, 01:41 PM
Forum Jump:


Users browsing this thread:
2 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('1005')