empty DBEdit in VARCHAR column

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Frega
Posts: 8
Joined: Thu 23 Apr 2009 18:44

empty DBEdit in VARCHAR column

Post by Frega » Thu 23 Apr 2009 23:09

hello, im starting with devart mysql component for delphi and im having a problem with empty dbedits, here it goes:


in the Client Inserting form i have a DBEdit linked to column email by a MyQuery -> DataSource -> DBEdit


I need that MyQuery pass the value null to the database and not a blank value, because this field (email) is set 'not null' , and the blank value sent by MyQuery bypasses the blockage of 'not null' of the database..



(In my form i have a button register, when i click it, and a required field is not supplied, MySQL return a error and the button have a error handler, that block user to finish the register, but the database only return a error when i sent a NULL value, but MyQuery is sending as Blank value ' ')



how to send a null value to the database when the dbedit is not supplied?




Sorry bad english
thanks...

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 24 Apr 2009 07:08

To solve this problem you may handle the TMyQuery.BeforeUpdateExecute event and check the set value of the 'email' field, like this:

Code: Select all

  if Params.FindParam('email')  nil then
    if Params.ParamByName('email').AsString = '' then
      Params.ParamByName('email').Clear;

jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

Post by jkuiper » Fri 24 Apr 2009 07:41

Set your default value in your table to ''. When the field is NULL, MySQL wil use the default value.

Post Reply