Page 1 of 1
default value for timestamp popup an error !!
Posted: Sat 01 Oct 2011 13:39
by inageib
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
Posted: Tue 04 Oct 2011 10:31
by AndreyZ
I cannot reproduce the problem. Please specify a script to create your table and the exact value that you put in the DefaultExpression property.
Posted: Tue 04 Oct 2011 13:30
by inageib
I put 'NOW' in the default value inside the database itself
Posted: Wed 05 Oct 2011 13:49
by AndreyZ
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.
Posted: Wed 05 Oct 2011 19:48
by inageib
Wow I used to use NOW with InterBase.
so When I can use NOW ?
Thanks
Posted: Fri 07 Oct 2011 10:20
by AndreyZ
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.
Posted: Fri 07 Oct 2011 14:03
by inageib
Thanks alot AndreyZ. appreciate your help.
Posted: Fri 07 Oct 2011 15:03
by AndreyZ
Feel free to contact us if you have any further questions about IBDAC.