|
楼主 |
发表于 2003-4-7 10:22:47
|
显示全部楼层
Cache系统数据类型剖析
再看一下%Date:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%Date</b> data type class represents a date.
/// The logical value of the <b>%Date</b> data type is in <i>Cach&eacute</i> <code>$H</code> format.
Class %Library.Date [ ClassType = datatype, ClientDataType = DATE, OdbcType = DATE, SqlCategory = DATE ]
{
/// The format specification for the data type\'s display value.
/// The value of the <var>FORMAT</var> parameter corresponds to the
/// available parameters of the <code>$ZDATE</code> and <code>$ZDATEH</code> functions,
/// which are used to perform the formatting.
Parameter FORMAT"
/// The maximum allowed logical value for the data type.
Parameter MAXVAL"
/// The minimum allowed logical value for the data type.
Parameter MINVAL"
/// Used for enumerated (multiple-choice) attributes.
/// <var>VALUELIST</var> is either a null string ("") or a delimiter
/// separated list (where the delimiter is the first character) of logical values.
/// If a non-null value is present, then the attribute is restricted to values
/// in the list, and the validation code simply checks to see if the value is in the list.
Parameter VALUELIST"
/// Used for enumerated (multiple-choice) attributes.
/// Used in conjunction with the <a href="#VALUELIST">VALUELIST</a> parameter for enumerated
/// (multiple-choice) attributes. <var>DISPLAYLIST</var>, if not null,
/// represents the display values for the attribute corresponding with
/// the logical values listed in <var>VALUELIST</var>.
///
The display values are returned by the <a href="#LogicalToDisplay">LogicalToDisplay</a> method.
Parameter DISPLAYLIST"
/// Declares the XSD type used when projecting XML Schemas.
Parameter XSDTYPE = "date""
/// Converts the SOAP encoded input date value into a Cache %Date value.
ClassMethod XSDToLogical(%val As %String) As %Date [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
$$$GENERATE(" New len")
$$$GENERATE(" Set len=$length(%val)")
$$$GENERATE(" If len\'=10 {")
$$$GENERATE(" If $extract(%val,len)=""Z"" {")
$$$GENERATE(" Set %val=$extract(%val,1,len-1)")
$$$GENERATE(" } ElseIf $case($extract(%val,len-5),""+"":1,""-"":1,:0) {")
$$$GENERATE(" Set %val=$extract(%val,1,len-6)")
$$$GENERATE(" }")
$$$GENERATE(" }")
$$$GENERATE(" Quit $select(%val="""":"""",1 zdateh(%val,3,,,,,,,""""))")
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the Cache %Date value to the canonical SOAP encoded value.
ClassMethod LogicalToXSD(%val As %Date) As %String [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$select(%val="""":"""",1 zdate(%val,3))"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which represents a date, into <code>$H</code> format.
///
Returns the logical (<code>$H</code>) value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String) As %Date [ CodeMode = generator ]
{
n i,len,sep
s %code=0
i %parameter("VALUELIST")\'="",%parameter("DISPLAYLIST")\'="" d QUIT $$$OK
. s sep=$e(%parameter("DISPLAYLIST"))
. s len=$l(%parameter("DISPLAYLIST"),sep)
. f i=2:1 l(%parameter("DISPLAYLIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("DISPLAYLIST"),sep,i))_" "_$$quote($p(%parameter("VALUELIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("FORMAT")="" s %code="$s(%val="""":"""",1:$zdh(%val,,,5,80,20,,,""""))" QUIT $$$OK
s %code="$s(%val="""":"""",1:$zdh(%val,"_%parameter("FORMAT")_",,5,80,20,,,""""))"
QUIT $$$OK
}
/// Converts <var>%val</var> to a normalized value.
ClassMethod Normalize(%val As %String) As %Date [ CodeMode = expression ]
{
%val\\1
}
/// Tests if the logical value <var>%val</var>, which represents a date in <code>$H</code> format,
/// is valid. The validation is based on the class parameter settings used
/// for the class attribute this data type is associated with.
/// In this case, <a href="#MAXVAL">MAXVAL</a> and <a href="#MINVAL">MINVAL</a>.
///
Returns true (1) if the value <var>%val</var> is valid, otherwise false (0).
ClassMethod IsValidDT(%val As %Date) As %Integer [ CodeMode = generator ]
{
n sep,str
s %code=0
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("VALUELIST")\'="" d QUIT $$$OK
. s sep=$e(%parameter("VALUELIST")) "for now
. s %code="(%val\'["""_sep_""")&("_$$quote(%parameter("VALUELIST")_sep)_"[("""_sep_"""_%val_"""_sep_"""))"
s str="$isvalidnum(%val,0,"_%parameter("MINVAL")_","_%parameter("MAXVAL")_")"
s %code=str
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is in logical <code>$H</code> format, into a display string.
/// The formatting is based on the value of the <a href="#FORMAT">FORMAT</a> parameter.
///
Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Date) As %String [ CodeMode = generator ]
{
n i,len,sep
k %code s %code=0
i %parameter("VALUELIST")\'="",%parameter("DISPLAYLIST")\'="" d QUIT $$$OK
. s sep=$e(%parameter("VALUELIST"))
. s len=$l(%parameter("VALUELIST"),sep)
. f i=2:1:$l(%parameter("VALUELIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("VALUELIST"),sep,i))_" "_$$quote($p(%parameter("DISPLAYLIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("FORMAT")="" s %code="$s(%val="""":"""",1:$zd(%val,,,4))" QUIT $$$OK
s %code="$s(%val="""":"""",1:$zd(%val,"_%parameter("FORMAT")_",,4))"
QUIT $$$OK
}
/// Converts <var>%val</var>, which represents a date in logical <code>$H</code> format, into ODBC date format.
///
Returns the ODBC date string for the logical (<code>$H</code>) value <var>%val</var>.
ClassMethod LogicalToOdbc(%val As %Date = "") As %String [ CodeMode = expression ]
{
$s(%val="":"",1:$zd(%val,3))
}
/// Converts <var>%val</var>, which represents a date in ODBC format, into <code>$H</code> format.
///
Returns the <code>$H</code> value of the ODBC date string <var>%val</var>.
ClassMethod OdbcToLogical(%val As %String = "") As %Date [ CodeMode = expression ]
{
$s(%val="":"",1:$zdh(%val,3,,,,,,,"error: \'"_%val_"\' is an invalid date value"))
}
}
|
|