Last active
March 31, 2016 18:04
-
-
Save eduard93/3a4b180ac23c482250c6 to your computer and use it in GitHub Desktop.
Custom class Query examples for InterSystems Caché
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Export generator="Cache" version="25"> | |
<Class name="Utils.CustomQuery"> | |
<Super>%Persistent,%Populate</Super> | |
<TimeCreated>63869,45310.24869</TimeCreated> | |
<Property name="Prop1"> | |
<Type>%String</Type> | |
</Property> | |
<Property name="Prop2"> | |
<Type>%Integer</Type> | |
</Property> | |
<Query name="AllRecords"> | |
<Type>%Query</Type> | |
<SqlName>AllRecords</SqlName> | |
<SqlProc>1</SqlProc> | |
<Parameter name="CONTAINID" value="1"/> | |
<Parameter name="ROWSPEC" value="Id:%String,Prop1:%String,Prop2:%Integer"/> | |
</Query> | |
<Method name="AllRecordsExecute"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary]]></FormalSpec> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
Set qHandle = "" | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Method name="AllRecordsFetch"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary,&Row:%List,&AtEnd:%Integer=0]]></FormalSpec> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
#; Iterating through ^Utils.CustomQueryD | |
#; Writing the next id to qHandle and writing the global's value with the new id into val | |
Set qHandle = $Order(^Utils.CustomQueryD(qHandle),1,val) | |
#; Checking whether there is any more data left | |
If qHandle = "" { | |
Set AtEnd = 1 | |
Set Row = "" | |
Quit $$$OK | |
} | |
#; If not, create %List | |
#; val = $Lb("", Prop1, Prop2) see Storage definition | |
#; Row =$lb(Id,Prop1, Prop2) see ROWSPEC for the AllRecords request | |
Set Row = $Lb(qHandle, $Lg(val,2), $Lg(val,3)) | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Method name="AllRecordsClose"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary]]></FormalSpec> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
Kill qHandle | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Query name="AllStatic"> | |
<Type>%Query</Type> | |
<SqlName>AllStatic</SqlName> | |
<SqlProc>1</SqlProc> | |
<Parameter name="CONTAINID" value="1"/> | |
<Parameter name="ROWSPEC" value="Id:%String,Prop1:%String,Prop2:%Integer"/> | |
</Query> | |
<Method name="AllStaticExecute"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary]]></FormalSpec> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
&sql( DECLARE C CURSOR FOR | |
SELECT Id, Prop1, Prop2 | |
FROM Utils.CustomQuery) | |
&sql(OPEN C) | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Method name="AllStaticFetch"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary,&Row:%List,&AtEnd:%Integer=0]]></FormalSpec> | |
<PlaceAfter>AllStaticExecute</PlaceAfter> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
&sql(FETCH C INTO :Id, :Prop1, :Prop2) | |
#; Checking whether there is any more data left | |
If (SQLCODE'=0) { | |
Set AtEnd = 1 | |
Set Row = "" | |
Quit $$$OK | |
} | |
Set Row = $Lb(Id, Prop1, Prop2) | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Method name="AllStaticClose"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary]]></FormalSpec> | |
<PlaceAfter>AllStaticFetch</PlaceAfter> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
&sql(CLOSE C) | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Query name="AllDynamic"> | |
<Type>%Query</Type> | |
<SqlName>AllDynamic</SqlName> | |
<SqlProc>1</SqlProc> | |
<Parameter name="CONTAINID" value="1"/> | |
<Parameter name="ROWSPEC" value="Id:%String,Prop1:%String,Prop2:%Integer"/> | |
</Query> | |
<Method name="AllDynamicExecute"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary]]></FormalSpec> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
Set qHandle = ##class(%SQL.Statement).%ExecDirect(,"SELECT * FROM Utils.CustomQuery") | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Method name="AllDynamicFetch"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary,&Row:%List,&AtEnd:%Integer=0]]></FormalSpec> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
If qHandle.%Next()=0 { | |
Set AtEnd = 1 | |
Set Row = "" | |
Quit $$$OK | |
} | |
Set Row = $Lb(qHandle.%Get("Id"), qHandle.%Get("Prop1"), qHandle.%Get("Prop2")) | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Method name="AllDynamicClose"> | |
<ClassMethod>1</ClassMethod> | |
<FormalSpec><![CDATA[&qHandle:%Binary]]></FormalSpec> | |
<ReturnType>%Status</ReturnType> | |
<Implementation><![CDATA[ | |
Kill qHandle | |
Quit $$$OK | |
]]></Implementation> | |
</Method> | |
<Storage name="Default"> | |
<Type>%Library.CacheStorage</Type> | |
<DataLocation>^Utils.CustomQueryD</DataLocation> | |
<DefaultData>CustomQueryDefaultData</DefaultData> | |
<IdLocation>^Utils.CustomQueryD</IdLocation> | |
<IndexLocation>^Utils.CustomQueryI</IndexLocation> | |
<StreamLocation>^Utils.CustomQueryS</StreamLocation> | |
<ExtentSize>1000</ExtentSize> | |
<Data name="CustomQueryDefaultData"> | |
<Value name="1"> | |
<Value>%%CLASSNAME</Value> | |
</Value> | |
<Value name="2"> | |
<Value>Prop1</Value> | |
</Value> | |
<Value name="3"> | |
<Value>Prop2</Value> | |
</Value> | |
</Data> | |
<Property name="%%CLASSNAME"> | |
<Selectivity>0.1000%</Selectivity> | |
<OutlierSelectivity>.992632:</OutlierSelectivity> | |
</Property> | |
<Property name="Prop1"> | |
<Selectivity>0.1000%</Selectivity> | |
</Property> | |
<Property name="Prop2"> | |
<Selectivity>0.1000%</Selectivity> | |
</Property> | |
<SQLMap name="IDKEY"> | |
<BlockCount>-12</BlockCount> | |
</SQLMap> | |
</Storage> | |
</Class> | |
</Export> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment