SQLitePCL.raw icon indicating copy to clipboard operation
SQLitePCL.raw copied to clipboard

Bindings for Formatted String Printing Functions

Open MKuckert opened this issue 8 years ago • 5 comments

I just found the sqlite3_*printf functions and was wondering if there's a reason those are missing from the bindings. They are pretty handy to escape special chars in strings for example (using sqlite3_mprintf("%q", str)).

Is there a way to use these printing functions using a custom binding or do I have to implement my own as a port of the original functions?

MKuckert avatar Apr 18 '17 09:04 MKuckert

I would like those functions too. I'll live this issue open for now, to remind me to explore possibilities.

But they are unusually difficult. They accept a varying number of args which are without a specified type. That doesn't map well onto the semantics of P/Invoke.

So yes, there is a reason they are missing from the bindings. But I agree that it would be nice to have them.

ericsink avatar Apr 18 '17 13:04 ericsink

I've had a request/need for them too. In this issue: https://github.com/praeclarum/sqlite-net/issues/382

Also pragma commands don't seem to like to be parameterized so it would be nice to have this to safely set the key for SQLCipher.

praeclarum avatar Aug 13 '17 02:08 praeclarum

If the binding is difficult, perhaps you can just expose the simplest overload that would let us execute sqlite3_mprintf("%u", unsafeString) - an overload that expects two strings. This is the trick Xamarin uses to bind to objc_msgSend - lots of overloads.

praeclarum avatar Aug 13 '17 02:08 praeclarum

Acknowledged. Good idea.

ericsink avatar Aug 17 '17 15:08 ericsink

I just committed the lamest possible implementation of this. In efb0a02.

Like I said, this is lame. I'll probably explore more angles.

Even with the overloads approach, the problems are:

  1. How do I know what the arg types should be?
  2. Do I have to worry about somebody passing %z?

I could resolve (1) by only supporting strings.

I could resolve (2) by ignoring the matter and just saying that if you pass %z and your app crashes, you got what you deserved. Or I could maybe scan the format string for %z and give an error.

ericsink avatar Aug 17 '17 17:08 ericsink