Page 1 of 1

How to store/retrieve Time values in SQLite

Posted: Wed 12 Dec 2012 15:32
by stevel
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?

Re: How to store/retrieve Time values in SQLite

Posted: Thu 13 Dec 2012 15:32
by AlexP
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))