Thread Rating:
  • 281 Vote(s) - 2.72 Average
  • 1
  • 2
  • 3
  • 4
  • 5
レコードに値を詰める際に、レコードフィールドに応じた値に変更したい
11-19-2013, 06:33 PM,
#1
レコードに値を詰める際に、レコードフィールドに応じた値に変更したい
レコードにある値を詰める際に、詰める先の型に応じてセットするにはどうすればいいですか?


11-19-2013, 07:15 PM,
#2
RE: レコードに値を詰める際に、レコードフィールドに応じた値に変更したい
Domain クラスで出来そうですね。

Code:
{let rs:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField
                "First", caption = "First Name", domain = String
            },
            {RecordField
                "Last", caption = "Last Name", domain = String
            },
            {RecordField
                "Age", domain = int
            },
            {RecordField
                "BD", domain = {BigDecimalDomain}
            }
        },
        {RecordData First = "John", Last = "Smith", Age = 25, BD = {BigDecimal.from-String "0"}},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Jones", Age = 28}
    }
}


{define-proc public {set-record-data
                        val:any,
                        record:Record,
                        rf:RecordField
                    }:void
    {if-non-null {rf.domain.validate val} then
        ||validate に成功したら、値をクリアする
        {if rf.nullable? then
            set record[rf.name] = null
         else
            set record[rf.name] = rf.default-value
        }

    else
        ||validate に成功したら、値をコンバートしてセット
        set record[rf.name] = {rf.domain.convert val}


    }
}
{def tf = {TextField}}
{def dl = {DropdownList }}
{for rf in rs.fields do
    {dl.append rf.name}
}
{VBox {RecordGrid record-source = rs, height = 2in}, tf, dl}

{CommandButton
    label = "指定フィールドに値をセット",
    {on Action do
        def val = tf.value
        def rf = {rs.fields.get dl.value}
        {for r in rs do
            {set-record-data val, r, rf}
        }
    }
}

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('1006')