Page 1 of 1

ODAC -

Posted: Tue 31 Mar 2015 09:28
by andrefm
Table in Oracle 11g R2 with a field called STARTTIME type TIMESTAMP(6).
I'm preparing an insert statement like:

Code: Select all

  ...
  QR_TABLE_INSERT.ParamByName('STARTTIME').DataType := ftOraTimeStamp;
  QR_TABLE_INSERT.Prepare; 
I have a variable dtStartTime from type TDateTime which contain a date and time with milliseconds.
When I execute:

Code: Select all

  QR_TABLE_INSERT.ParamByName('STARTTIME').AsDateTime := dtStartTime;
  QR_TABLE_INSERT.Execute;
The SQL statement is something like:

Code: Select all

INSERT INTO MY_TABLE
  (ID, FIELD1, STARTTIME)
VALUES
  (:ID, :FIELD1, :STARTTIME)
After I insert, the field STARTTIME contain the date and time, but no milliseconds (000).
Could you please let me know is this is a bug or how can I avoid loosing the milliseconds?

I guess the ".AsDateTime" might be the problem because if I just use the .Value and copy from another table, then I don't loose the milliseconds.
Example:

Code: Select all

QR_TABLE_INSERT.ParamByName('STARTTIME').Value  := QR_OTHER_TABLE.ParamByName('DATE_TIME').Value;
Using ODAC 9.4.14 with XE7 Enterprise.

Re: ODAC -

Posted: Tue 31 Mar 2015 11:27
by AlexP
Hello,

If you are using the AsDateTime property, then, independently on the set parameter type, it will be changed to ftDateTime in the TParam.SetAsDateTime standard method. To work with TimeStamp parameters, you can use the AsSQLTimeStamp property and map your data to this type:

Code: Select all

dt := now;
OraQuery1.ParamByName('p2').AsSQLTimeStamp := DateTimeToSQLTimeStamp(dt);

Re: ODAC -

Posted: Tue 31 Mar 2015 11:30
by andrefm
Thank you very much for the very quick response. It worked well.

Re: ODAC -

Posted: Tue 31 Mar 2015 12:40
by AlexP
Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.