sqlite_modern_cpp icon indicating copy to clipboard operation
sqlite_modern_cpp copied to clipboard

Not clearing all bindings

Open zauguin opened this issue 6 years ago • 2 comments

Often we need a statement where only some bound parameters change with every use. Currently we clear bindings every time we reset the bindings so we have to bind all parameters again after every usage. This gets complicated if you want to pass the prepared statement to another function without all the parameters you want to use every time.

Maybe we could make clearing the bindings optional? Or does anyone has an idea for a nice interface which allows reusing the bindings?

I thought about adding a method .fix_parameters(n) which indicates to no longer modify/clear the first n parameters. There is no sqlite3 function for clearing a subset of all bound parameters, but we could probably emulate this.

zauguin avatar Jun 21 '18 12:06 zauguin

@zauguin according to documentation sqlite3_reset does not rest the bindings. The reason we are calling sqlite3_clear_bindings here.

I wonder what happens if we don't clear the previous bindings and just bind again to an already bound parameter?

Is is ok to use sqlite3_bind_* on the same parameter index without clearing the existing bindings?

aminroosta avatar Jun 21 '18 14:06 aminroosta

It is OK to rebind without clearing first. The only problem with it is that it can be confusing for your old bindings to still have an effect after calling reset.

zauguin avatar Jun 21 '18 14:06 zauguin