Forum > Database

[SOLVED] SQLite query not providing data

<< < (2/2)

Slyde:

--- Quote from: dsiders ---    SELECT (strftime('%s', 'now', 'localtime') - strftime('%s', skip_date)) / 3600 AS elapsed FROM MC_Skipped;
--- End quote ---

That doesn't work for me.  I'd tried it before, and I just tried it again with your query.  The compiler shuts this down when I try to run it with this message:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---main_unit.pas(1649,40) Error: Syntax error, ";" expected but "ordinal const" found
I appreciate you trying.  Thanks.

rvk:

--- Quote from: Slyde on February 02, 2024, 10:29:27 pm ---This is what I get from Showmessage(SQL.Text).

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SELECT (strftime('%s', 'now', 'localtime') - strftime('%s', 'skip_date')) / 3600 AS elapsed FROM MC_Skipped WHERE nid = :nid
In DB Browser, I use the same:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---'SELECT (strftime("%s", "now", "localtime") - strftime("%s", "skip_date")) / 3600 FROM MC_Skipped WHERE nid = 103;'
--- End quote ---
How are those the same??.
The second uses double quotes. The first single quote.
And although sqlite tries to enable both methods, sometimes this goes horribly wrong.

Try the double quotes in your program and it should work.
In some fiddle website I see it makes a difference.

Slyde:
Thanks, rvk.  I feel kind of stupid in doing that.  I used single quotes instead of double quotes because that's always what Lazarus always wants.  But you're 100% right.  In this instance, it's all about double quotes.  It works.

Really appreciate you.

Zvoni:
Seeing such queries always gives me cramps.
Yes, you're using strftime to return the seconds, but why in blazes don't you use the unixepoch-function?
That said: Depending on your use-case: have you thought about storing your DateTime's as a Unixepoch from the get go?
Then you wouldn't have to jump through hoops to recalculate the seconds, just to get hours between two datetimes

Next: you use 'now' with modifier 'localtime'. Is your skip_date localtime, too?

Beware: SQLite stores Date/Times as UTC IF NO Modifier is passed

Navigation

[0] Message Index

[*] Previous page

Go to full version