I need to know if given package exists or not.
Currently found two solution - one doesn't work, another works but I don't like it.
**Solution 1.**
I started, of course, with %Dictionary package - it has PackageDefinition class after all.
However, %ExistsId returned on packages that clearly do exist, so I went to %LoadData, it uses this macro to determine if the package exist:
#define PACKAGE(%package) ^oddPKG($zcvt(%package,"u"))
And zw ^oddPKG showed the root cause - ^oddPKG global only contains data for packages with tables (or something along these lines).
**Solution 2.**
Using sql to find first class that starts with package name. Seems like an overhead to me.
Query PackageExists(package) As %SQLQuery
{
SELECT TOP 1 1 As "Exists"
FROM %Dictionary.ClassDefinition
WHERE ID %STARTSWITH :package
}
/// write ##class().GetPackageExists("isc")
ClassMethod GetPackageExists(class)
{
#dim exists As %Boolean
if class = "" {
set exists = $$$YES
} else {
set package = $case($l(class, "."), 1: class, : $p(class, ".", 1, *-1))
set rs = ..PackageExistsFunc(package)
do rs.%Next()
set exists = (rs.Exists = $$$YES)
}
quit exists
}
Ideas?