Field must have a value error

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
legende
Posts: 9
Joined: Wed 04 Mar 2009 09:19

Field must have a value error

Post by legende » Fri 06 Mar 2009 13:41

Hi

I have a field 'staatus' which is declared NOT NULL DEFAULT ''

Query.SQL.Text := 'SELECT * FROM dept WHERE deptno=10';
Query.Edit;
Query.FieldByName('staatus').AsString := '';
Query.Post;

and then I get Error "Field 'staatus' must have a value"

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 10 Mar 2009 10:37

You should set the RequiredFields property of TPgQuery to False.

legende
Posts: 9
Joined: Wed 04 Mar 2009 09:19

Post by legende » Thu 12 Mar 2009 09:05

Plash wrote:You should set the RequiredFields property of TPgQuery to False.
Nope, then I get same error from database.

PgDac automaticaly replace empty string with NULL even if default is empty string, but it should not

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 13 Mar 2009 08:34

When PgDAC generates an INSERT statement to add a record, only fields that have non-empty value are added to this statement. So if you don't assign a value to a field, it will get the default value.

Check that the SQLInsert property of TPgQuery is empty. In this case PgDAC generates INSERT statements at run-time.

legende
Posts: 9
Joined: Wed 04 Mar 2009 09:19

Post by legende » Fri 13 Mar 2009 15:04

There are no problem with inserting data, problem exists when i want to update data and set the new value to empty string.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 17 Mar 2009 13:01

We have fixed this problem. The fix will be included in the next build of PgDAC.

Post Reply