Ancestors

Toot

Written by Thomasorus on 2025-01-28 at 21:46

Each time I make progress in Go, I realize JavaScript rot my brain so much lol. I tried writing an SQL query containing a concatenation of a string + ? as a placeholder, all inside a datetime() SQLITE function and was like "why isn't this thing working" :popuko_doesnt_get_it:

Edit: it wasn't javascript or go, it was just my stupid brain, you can concat with || instead of +.

=> More informations about this toot | More toots from thomasorus@merveilles.town

Descendants

Written by s-ol on 2025-01-28 at 21:50

@thomasorus not sure I understood

what you were trying to do 100%, but if you're building SQL from strings and haven't read about "prepared statements" / "bind parameters" check this out:

https://go.dev/doc/database/prepared-statements

it's probably the best way to be sure to avoid SQL injection :)

=> More informations about this toot | More toots from s_ol@merveilles.town

Written by Thomasorus on 2025-01-28 at 21:54

@s_ol I know about them, that's what I'm doing. But this doesn't work:

stmt := INSERT INTO pages (title, content, created, expires) VALUES( ?, ?, datetime('now'), datetime('now', '+' + ? + ' days'))

Because I'm trying to mix string + placeholder inside the last datetime() and sqlite thinks the last ? is part of the string lol.

=> More informations about this toot | More toots from thomasorus@merveilles.town

Written by s-ol on 2025-01-28 at 21:59

@thomasorus

hmm I don't think the "?" is your problem, but rather that "+" doesn't work that way for strings. Try either

datetime('now, '+' || ? || ' days')

or

datetime('now', concat('+', ?, ' days'))

disclaimer: i had to look up what the concatenation operator (||) is, and i think it might differ from sqlite to other SQL databases

=> More informations about this toot | More toots from s_ol@merveilles.town

Written by Thomasorus on 2025-01-28 at 22:13

@s_ol Oh wow I tried the || before and it didn't work, but retrying again now it works????

The one with concat doesn't tho, it returns an "SQL logic error: incomplete input".

Thanks for helping, I learned something today!

=> More informations about this toot | More toots from thomasorus@merveilles.town

Written by s-ol on 2025-01-28 at 23:06

@thomasorus hm odd, i'm not sure what that error is supposed to mean. I tried it as

SELECT datetime('now', '+' || 3 || ' days');

in https://sqliteonline.com/ and that worked 🤷

=> More informations about this toot | More toots from s_ol@merveilles.town

Written by Thomasorus on 2025-01-28 at 23:07

@s_ol Yeah the one with || works, it's the one with the concat() function that returned the error!

=> More informations about this toot | More toots from thomasorus@merveilles.town

Written by s-ol on 2025-01-29 at 07:38

@thomasorus oops i pasted the wrong one, i meant that i tested both there before sending originally

=> More informations about this toot | More toots from s_ol@merveilles.town

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113908171731608197
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
282.151855 milliseconds
Gemini-to-HTML Time
1.398212 milliseconds

This content has been proxied by September (3851b).