Question
· Dec 30, 2024

Unique Index Open on Empty String

I have a unique index on two properties in a class, and I want to open the instance by index key with one of the two properties is set to the empty string. Is this possible to perform?

Take the example class here

Class TestIndex
{

Property Mandatory as TestClass [Required];
Property Alternate as TestClass;
Property AltOrEmpty As %String [ Calculated, Required, SqlComputeCode = {Set {*} = $Case({Alternate},"":$c(0),:{Alternate})}, SqlComputed ];
Index AlternateMandatory on (Mandatory, AltOrEmpty) [ Unique ];
}

And example data as

Mandatory Alternate AltOrNUL
2    
2 3 3

I can open the second line in the table as 

>set testInstance = ##class(TestIndex).AlternateMandatoryOpen(2,3,.st)
>w st
1

And I want to be able to use the same functionality to open the first line. This would be as open on one valid Id and on empty string, which results in an attempt to open NULL and fails. 

>set testInstance = ##class(TestIndex).AlternateMandatoryOpen(2,"",.st)
>zw st
ERROR #5770: Object open failed because 'AlternateMandatory' key value of '2:NULL' was not found

I am wondering if there is a syntax that would work to find and open this instance based on the unique index containing the empty string, or not based on the inherent design to have a unique index on an empty string.

Product version: IRIS 2022.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2022.1.3
Discussion (2)2
Log in or sign up to continue