Although the latter value seems to smile at me, it’s obvious that this is not a good outcome and the var points to the wrong portion of memory.
At first I thought that this can be caused by memory being somehow freed, this seems not to be the case (judging by sqlite docs).
So I think this may have something to do with that cast, but I’m not sure what would be the correct one.
Also, this kind of code works for me, when I query a long value and change everything to work with ?u64 instead of ?[]const u8
This probably works because u64 is passed by value rather than reference.
If this is the case, you should allocate some memory and, in the callback, memcpy the string into your buffer.
Hmm, so it’s still due to the freeing you think? I tried to do allocPrint to copy, but outside of the callback and that didn’t help.
I wanted to try to copy inside of the callback, but I don’t have access to the allocator there (due to it’s being across the boundary), and I can’t seem to allocate beforehand, because I don’t know the size of the string. Although I expect it to be an iso date-time, perhaps I can deduce something based on that…
Can the ctx be anything you want? If so, maybe you can pass in a struct with an allocator and a field to hold the copy. I’m totally guessing here, but something like this: