comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: GNATCOLL SQLite3 vs Ada.Calendar.Time
Date: Fri, 19 Aug 2016 19:43:17 +0200
Date: 2016-08-19T19:43:17+02:00	[thread overview]
Message-ID: <np7gfm$lh4$1@dont-email.me> (raw)
In-Reply-To: <3c38b5cc-736b-40ed-bfdd-7df36d0b5c59@googlegroups.com>

On 19.08.16 17:30, Stephen Leake wrote:
> On Thursday, August 18, 2016 at 1:13:40 PM UTC-5, Stephen Leake wrote:
>> On Thursday, August 18, 2016 at 12:45:11 PM UTC-5, Stephen Leake wrote:
>>> On Thursday, August 18, 2016 at 6:19:45 AM UTC-5, G.B. wrote:
>>>> On 17.08.16 23:05, Stephen Leake wrote:
>>>>> One solution would be to replace the "DATETIME" field type in the .sql file with "TEXT", always pass strings for times, and rely on lexicographic sorting for time comparison. But that seems extreme.
>>>>
>>>> It seems advisable to use SQLite's Date And Time Functions
>>>> when using SQLite for SQL. Thus,
>>>>
>>>>     " ... WHERE Modified >= datetime(?) ... "
>>>>
>>>
>>> Yes, that works.
>>
>> I take it back; it fixed most of the problems in the full program, but not all.
>>
>> So I'm switching to CHAR[19] for date/time fields.
>
> Which _also_ did not fix the problem. Which makes sense, given that SQL apparently uses TEXT for DATETIME.
>
> So I wrote code to substitute the time string for the ?, and pass a single string to SQLite3 with no bound parameters; that fixed the problem.
>
> There is apparently a problem with bound string parameters and >= in queries. Bound parameters with = INTEGER or LIKE %STRING work (so far, anyway).

TTBOMK, DATETIME, as opposed to TIMESTAMP, is not really present
in standard SQL (1999). DATE and TIME are. However, DATETIME and its
variations are offered by many DBMS products. There are hints at
varying ranges, though. Also, literals of DATETIME may differ.
Found these, for example, for two rather popular ones:

from: 1753-01-01 00:00:00.000	to: 31.12.9999 23:59:59.997
from: 1000-01-01 00:00:00	to: 9999-12-31 23:59:59

And for some version of Oracle, the docs say:
   "Dates between January 1, 4712 B.C. and December 31, 9999 A.D.,
    and times in hours, minutes and seconds."
DATE literals will depend on NLS settings.

For TIMESTAMP and TIME, timezones may enter the picture, as in
TIMESTAMP [WITH TIME ZONE]. Handling zones may depend on the DBMS
or even on SQL session settings, and is therefore not easy to
predict from just looking at SQL queries.

So, if portability or QoI are an issue, Randy Brukardt's suggestion
to use standard Ada conversions, to and from text, looks simple and
safe to me.

In the past, I had successfully used a combination of
DATE and TIME fields, not needing the fractions of TIMESTAMP.
The programs would be using UTC when storing points in time.
This worked reasonably well, since it didn't need complicated
comparisons of points in time. (In fact, when some results need
grouping by day, the split was a logical advantage.)


  reply	other threads:[~2016-08-19 17:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 21:05 GNATCOLL SQLite3 vs Ada.Calendar.Time Stephen Leake
2016-08-18  8:09 ` Dmitry A. Kazakov
2016-08-18 11:19 ` G.B.
2016-08-18 17:45   ` Stephen Leake
2016-08-18 18:13     ` Stephen Leake
2016-08-19 15:30       ` Stephen Leake
2016-08-19 17:43         ` G.B. [this message]
2016-08-18 18:28     ` Jeffrey R. Carter
2016-08-18 19:48       ` Dmitry A. Kazakov
2016-08-18 20:50         ` Jeffrey R. Carter
2016-08-18 22:05         ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox