Skip to content

Commit 59ed053

Browse files
committed
trialing IndexHasData method
1 parent 93a4182 commit 59ed053

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/cls/bdb/sql/StorageUtils.cls

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,4 +1200,40 @@ ClassMethod PopulateFromStats(tableName As %String, rowCount As %Integer = 1000,
12001200
quit sc
12011201
}
12021202

1203+
/// <p>This experimental method tries to verify whether the index <var>indexname</var> in class <var>classname</var>
1204+
/// is empty, meaning it has just been added to the class and still needs building.</p>
1205+
/// <p>This method does not verify whether the index is fully populated and entries are correct.
1206+
/// You can use <method>%ValidateIndices</method> for that purpose.</p>
1207+
ClassMethod IndexHasData(classname As %String, indexname As %String, Output status As %Status) As %Boolean [ Internal, SqlName = IndexHasData, SqlProc ]
1208+
{
1209+
set status = $$$OK, hasData = 0
1210+
try {
1211+
1212+
set cls = ##class(%Dictionary.CompiledClass).%OpenId(classname,, .status)
1213+
quit:'$isobject(cls)
1214+
set ss = ##class(%Dictionary.StorageDefinition).%OpenId(classname_"||"_cls.StorageStrategy,, .status)
1215+
quit:'$isobject(ss)
1216+
if (ss.Type = "%Storage.Persistent") {
1217+
1218+
// use SQL lookup to address case sensitivity
1219+
set location = "", parent = classname_"||"_ss.Name
1220+
&SQL(SELECT Location INTO :location FROM %Dictionary.CompiledStorageIndex WHERE parent = :parent AND UPPER(Name) = UPPER(:indexname))
1221+
if (SQLCODE'= 0) || (location = "") {
1222+
set status = $$$ERROR($$$GeneralError, "Unable to find index '"_indexname_"' in class '"_classname_"' - "_SQLCODE)
1223+
quit
1224+
}
1225+
1226+
set hasData = $d(@location)>0
1227+
1228+
} else {
1229+
set status = $$$ERROR($$$GeneralError, "Unsupported storage type: '"_ss.Type_"'")
1230+
quit
1231+
}
1232+
1233+
} catch (e) {
1234+
set status = e.AsStatus()
1235+
}
1236+
return hasData
1237+
}
1238+
12031239
}

0 commit comments

Comments
 (0)