default value for timestamp popup an error !!

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

default value for timestamp popup an error !!

Post by inageib » Sat 01 Oct 2011 13:39

Hi,
I use Firebird 2.5 64bit edition and I set the default value for a timestamp field to 'NOW' but when I call Insert or append I get error "invalid value for field1"

when I removed the default value and used the afterinsert event in Delphi I was able to use the Delphi NOW() function normally

what cause that ?

Thanks

AndreyZ

Post by AndreyZ » Tue 04 Oct 2011 10:31

I cannot reproduce the problem. Please specify a script to create your table and the exact value that you put in the DefaultExpression property.

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Post by inageib » Tue 04 Oct 2011 13:30

I put 'NOW' in the default value inside the database itself

AndreyZ

Post by AndreyZ » Wed 05 Oct 2011 13:49

Please specify a script to create a table with a TIMESTAMP column that has the NOW default value. For example, the following code will raise the "Unknown token NOW" error:

Code: Select all

CREATE TABLE TEST (DT TIMESTAMP DEFAULT NOW)
The point is that NOW is not a valid default value for a TIMESTAMP column, you should use CURRENT_TIMESTAMP instead.

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Post by inageib » Wed 05 Oct 2011 19:48

Wow I used to use NOW with InterBase.
so When I can use NOW ?

Thanks

AndreyZ

Post by AndreyZ » Fri 07 Oct 2011 10:20

You cannot use NOW as a default value of any date type neither in InterBase nor in Firebird. But you can use NOW in your queries. Here is an example:

Code: Select all

Firebird:
IBCQuery.SQL.Text := 'update test set ts=''now'' where id=1'; //ts is TIMESTAMP
IBCQuery.Execute;

InterBase:
IBCQuery.SQL.Text := 'update test set dt=''now'' where id=1'; //dt is DATE
IBCQuery.Execute;
For more information, please read the following article: http://edn.embarcadero.com/article/25797 . Also you can set the DefaultExpression property of a TDateTimeField persistent field to NOW. In this case IBDAC uses the standard NOW function to fill the value for such field.

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Post by inageib » Fri 07 Oct 2011 14:03

Thanks alot AndreyZ. appreciate your help.

AndreyZ

Post by AndreyZ » Fri 07 Oct 2011 15:03

Feel free to contact us if you have any further questions about IBDAC.

Post Reply