How to store/retrieve Time values in SQLite

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
stevel
Posts: 125
Joined: Tue 02 Nov 2010 19:01

How to store/retrieve Time values in SQLite

Post by stevel » Wed 12 Dec 2012 15:32

Using: Delphi XE2, Unidac 4.5.10 Pro

URGENT!

I need you to tell me how to store and retrieve Time values in SQLite database.

The field is defined as REAL in the database.

Now when retrieving the value, how to convert this real value to TTime type properly?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to store/retrieve Time values in SQLite

Post by AlexP » Thu 13 Dec 2012 15:32

Hello,

If you use a REAL field to store date, then, to retrieve a readable date value, you should use data type mapping when both selecting and editing this field, e.g.:

ddl

Code: Select all

CREATE TABLE test (
  f_id INTEGER, 
  f_time REAL)

select

Code: Select all

select f_id, time(f_time) as f_time from test 
insert

Code: Select all

INSERT INTO test (f_id, f_time) VALUES  (:f_id, cast(:f_time as REAL))

Post Reply