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
@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
@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
@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
@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
@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
@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
@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 This content has been proxied by September (3851b).Proxy Information
text/gemini