views:

1379

answers:

3

Hi,

i have a delphi form with some DB Controls on it.

To represent a date I use the TJvDBDatePickerEdit (from JCL), which has a nice property

ShowCheckBox := True;

to allow the user to enter that no date is known (DBNull).

I verify, that nulling the DatePicker works as expected by:

procedure Tframe.adoQueryBeforePost(DataSet: TDataSet);
begin
  if (qryAuftraege.FieldByName('MyDateField').IsNull) then
  begin
    ShowMessage('IsNull!');
  end;
end;

The message box shows. So the field that the ADO Component should write is of type varNull.

Now there is this pipeline: TADOQuery -> TADOConnection -> MS OLE DB Provider for ODBC Drivers -> MySQL ODBC 5.1 Driver

And the MySQL ODBC driver now shows in it's log:

UPDATE `db`.`table` SET `MyDateField`=_latin1'0004-00-00' WHERE `ID`=5 AND `MyDateField`=_latin1'2009-06-17';

Well, the date is stored as '0004-00-00' (which MySQL seems to save like that). Now when querying the entry, it is recognized as Null by Delphi, but when it shall be updated the next time, calling:

UPDATE `bvl`.`auftraege` SET `MyDateField`=_latin1'2009-06-17' WHERE `ID`=5 AND `MyDateField` IS NULL;

of course fails, because MyDateField is NOT NULL (at least in the MySQL DB).

Where does this string '0004-00-00' come from? If it is a bug somewhere, where could I possibly intercept it?

I already know that there are components to buy that provide direct MySQL connections which (I assume) don't show this behaviour.

+6  A: 

To save a null date/time to the database record, just call

qryAuftraege.FieldByName('MyDateField').clear;
skamradt
Thanks, but as I stated the MyDateField value of the ADOQuery is already Null, the clear() method doesn't change this nor the wrong behaviour of the driver afterwards.
Tarnschaf
A: 

I don't know the implications of doing this, but I've always used

qryAuftraege.FieldByName('MyDateField').AsString:='';
José Romero
Totally wrong. Most RDBMSs differentiate between NULL (no value assigned) and '' (empty string assigned). Oracle is the only mainstream RDBMS that doesn't consider the NULL and '' as different.
Ken White
And Firebird too, I've used it for about 5 years and never have a problem doing this
José Romero
thanks for the hint, as the other two comments said this is not exactly what I wanted, though surprisingly it seems to have the same effect (it is actually NULL then).But the error is still AFTER that, when the driver assigns '0004-00-00' in the actual database field
Tarnschaf
+3  A: 

Be sure to check your MySQL options as discussed here...

Then, I would try with a different set of connection components as the stack (ADO + ODBC 5.1 driver) might the problem here.
Have you tried with another ODBC driver? Or with DBX...

François
Or ZEOSLIB (free), MyDAC (not free) for native MySQL access..
Ertugrul Tamer Kara
although I didn't try it, I guess you're right about the problem being in the stack. I will now switch to Postgres (which has a better fitting licensing model) because I am not bound to MySQL. Probably I will also try Zeoslib then. Thanks.
Tarnschaf
Since this questions seems to get attention: Switching to Postgres with Zeoslib solved the issue.
Tarnschaf