How to Set Null for SetVariable

im2kul

Member²
Hi All,

This might be a stupid question for some of you, but I have been battling with this for a while. I have a Variant Array where I keep on adding the elements and then execute the Query by setting the values in the Query with the ones in the Variant Array: Below is the sample code:
# CODE #1

Code:
if (aCol->mDataType == ftInteger || aCol->mDataType == ftBoolean)
            {
                if (Text1.IsEmpty())
                {
                    vArrayElm[FieldIndex].PutElement(Text, ArrayCount);
                }
                else
                {
                    if (Text1 == "False")
                         Text1 = "0";
                    else if (Text1 == "True")
                         Text1 = "1";
                    vArrayElm[FieldIndex].PutElement(Text1.ToInt(), ArrayCount);
                }
            }
The logic is very simple. If the Text I got from UI is Empty/NULL I PutElement as NULL in the vArrayElm (Variant Array) else if True then putElem as int 1 else int 0. Please note that the Column that I am trying to write to is of type

Name Type
------------------------
MY_COLUMN1 CHAR(1)

Below is the code that actually assigns the values to the variables in the Query:

# CODE #2
for (int i = 0; i < DataSet->FieldCount; i++)
{
Query->SetVariable(vPList->Strings, vArrayElm);
}

When I try to Set The Variable for MY_COLUMN1 (in CODE #2) as NULL (set by the code #1 above) I get an error: "Variant conversion error for for variable xMY_COLUMN1"

Any help is highly appreciated. What am I doing wrong? How can I set a NULL value in the Variant Array so that I don't get this exception while assigning the NULL value to the params in the Query using Query->SetVariable?

Thanks
 
For Delphi:
See functions Unassigned and Null in unit Variants
Sample Code:

uses Variants;
...
var
Var1: Variant;
begin
Var1 := Variants.Unassigned;
if VarIsEmpty(Var1) //return True
then begin
ShowMessage('Var1 is Empty')
end;

Var1 := Variants.Null;
if VarIsNull(Var1) //return True
then begin
ShowMessage('Var1 is Null');
end;
end;

Good luck
 
Hi Devil,

Thanks for your quick reply. However, that does not really answer my question. I have tried assigning NULL directly (FYI: I am using Borland C++ 5.0 with Direct Oracle Access) while assigning Values to teh Variables => Query->SetVariable(MY_COLNAME1, NULL) and it still gives me an error saying the DML size should be same as paramaeters in the query at teh time of execution (Query->ExecuteArray(0, ArrayCount)).

Please help!

Thanks
 
Hi All,

Never mind...I figured out a better way to solve the problem rather then adding a NULL value.

The way I did it was never to add a value to the Variant Array if the Value is NULL or the Text value is NULL.

Thanks
 
How you declare variable xMY_COLUMN1, what set type for this?
Sample:
Query->DeclareVariable('xMY_COLUMN1',???);
 
Back
Top