better-sqlite3 icon indicating copy to clipboard operation
better-sqlite3 copied to clipboard

Add support for numbered placeholders

Open alex3d opened this issue 4 years ago • 3 comments

This PR should add support for numbered placeholders (?1, ?2, ?3).

PS What lzz is assumed to be used with this project? https://github.com/mjspncr/lzz3? https://github.com/driedfruit/lzz? Probably this info could be added to the readme.

alex3d avatar Nov 15 '21 08:11 alex3d

Related to https://github.com/JoshuaWise/better-sqlite3/issues/576

Could you add some more tests? What if there are gaps, e.g. SELECT ?3, ?15? How do you bind that? With an array or object? Or do both work?

See my comment here https://github.com/JoshuaWise/better-sqlite3/issues/576#issuecomment-804976406

Prinzhorn avatar Nov 25 '21 08:11 Prinzhorn

@Prinzhorn I've added a couple of new testcases.

How do you bind that? With an array or object? Or do both work?

Semantically you should treat numbered placeholders the same as unnamed placeholders (?). It is just a shortcut to reuse the same bind values. For example, INSERT INTO payments(payment_type, amount) VALUES (?1, ?), (?1, ?) + bind values ['cash', 100, 200]. ? === increment current_index and insert anonymous bind value with index current_index ?n === insert anonymous bind value with index n and set current_index = max(current_index, n)

alex3d avatar Nov 25 '21 16:11 alex3d

wow, it is still open

I need to use the parameter multiple times, and it is a single parameter: WHERE instr(lower(card.name), ?1) OR instr(lower(card.description), ?1)

It's stupid to wrap it into an object or pass it twice. But currently, I have no choice.

7nik avatar Apr 15 '23 23:04 7nik