←back to thread

620 points tambourine_man | 1 comments | | HN request time: 0.257s | source
Show context
mont_tag ◴[] No.43753538[source]
How does this Python docs example work with t-strings?

    cur.executemany("INSERT INTO movie VALUES(?, ?, ?)", data)
Can SQLite3 cache the query as it does now?
replies(1): >>43754460 #
roywiggins ◴[] No.43754460[source]
It seems to me that it would be straightforward to parse a Template's parameters back into ? placeholders?
replies(1): >>43755606 #
mont_tag ◴[] No.43755606[source]
No, it would fail upstream before the template post-processing even begin.

The template object itself could not be formed because the each name must be a visible variable name.

This is the same error that you would get with an f-string that contained an undefined variable name.

replies(1): >>43756844 #
1. sanderjd ◴[] No.43756844[source]
I'm intrigued but confused by your comment. I think it could be done like this:

    cur.executemany(t"INSERT INTO movie VALUES({data})")
Then the Template object would have a parameter that is a list, and it could turn that into the right number of "?"s to pass into the database driver along with the data.

What am I missing?