How to set a bind variable to NULL?

TDateTime dt = /* ... */;
Query->DeclareVaraiable("DT", otDate);
if(/*dt is a valid date*/
Query->SetVariable("DT", dt);
else
Query->SetVariable("DT", "NULL"); //
 
My success message was too early. NULL ist a typedef to 0 only:

#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif

Thus, 'Query->SetVariable("DT", NULL);' will set the value to number 0. What I want to do is to set a real NULL-field. That doesn't work this way:

try {
Os->LogOn();
Oq->SQL->Text =
L"CREATE TABLE TestTab ("
L" Test_id INTEGER CONSTRAINT CK_TestTab_Test_id CHECK(Test_id > 0)"
L")";
Oq->Execute();
Oq->DeclareVariable(L"ID", otInteger);
Oq->SetVariable(L"ID", NULL);
Oq->SQL->Text = L"INSERT INTO TestTab VALUES(:ID)";
try {
Oq->Execute();
}
catch(EOracleError& e) {
Application->ShowException(&e);
}
Oq->DeleteVariable(L"ID");
Oq->SQL->Text = L"DROP TABLE TestTab";
Oq->Execute();
Os->LogOff();
}
catch(Exception& e) {
Application->ShowException(&e);
}

will cause an Oracle error '(ORA-02290: check constraint CK_TESTTAB_TEST_ID) violated'

I have tried the following:

void* nl = NULL;
Oq->SetVariable(L"ID", nl);

But the Oracle error is the same.
 
Back
Top