How to set a NULL column value through an ADO query connected to a MySQL ODBC source in C++?

  ado, borland-c, c++, mysql

Given a given MySQL table

DESC tabl_foo;
--------------------------------
Field            Type         Null    Key    Default    Extra
-----------------------------------------------------------------
fooId            varchar(15)  NO      PRI    NULL
FooDate          date         YES     MUL    NULL

I need to update FooDate for a given row. So I tried this code :

query->SQL->Add("UPDATE tbl_foo SET FooDate = :FooDate WHERE fooId = :id"):

// both arguments are AnsiString
query->Parameters->FindParam("id")->Value = FoodId;
query->Parameters->FindParam("FooDate")->Value = FooDate; 

query->ExecSQL();

However, this fails

Incorrect date value: "" for folumn FooDate at row 1

It turns out that FooDate may be an empty string (or { data:NULL }), and MySQL does not like that. So, I tried setting Null() :

if (FooDate.IsEmpty())
   query->Parameters->FindParam("FooDate")->Value = Null();
else
   query->Parameters->FindParam("FooDate")->Value = FooDate;

But then I get this error :

Parameter object is improperly defined. Inconsistent or incomplete information was provided.

What should be the value to set for MySQL NULL?

Source: Windows Questions C++

LEAVE A COMMENT