ericsink / SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite
Apache License 2.0
525 stars 109 forks source link

Version 2.0 returning wrong byte array using raw.sqlite3_value_blob from function parameter #289

Closed sdejesusF closed 5 years ago

sdejesusF commented 5 years ago

Hello there,

I have a function created with a callback that previously was working fine but after the update to version 2.0 the function sqlite3_value_blob used to get the byte array from the parameters returns a wrong byte array.

Function declaration: raw.sqlite3_create_function(Database, "functionname", 1, null, handledelegate_function);

And this is the delegate function: void handledelegate_function(sqlite3_context ctx, object user_data, sqlite3_value[] args) { byte[] byteArrayParameter = raw.sqlite3_value_blob(args[0]).ToArray(); }

Also, tested it using a different kind of parameter like int and it worked, just getting a blob isn't working.

Am I doing something wrong here or might be an actual issue of the new version?

For now, I downgraded to 1.14 and it's working as expected.

Thanks, Cheers

ericsink commented 5 years ago

I probably need to investigate further.

When you say the byte array is "wrong", could you be more specific? Like, how is it wrong?

ericsink commented 5 years ago

Is the sqlite3_value passed to that function actually a BLOB?

If by chance you could send a small self-contained sample that reproduces the problem, that would be super-helpful.

sdejesusF commented 5 years ago

Yes, I confirmed that the values are actually a BLOBs. Also, to test I change the expected parameter to be a text and then use the hex function to pass the BLOB and got the expected data.

This is an example of what is expected: 30 20 00 00 7a 6f f8 00 2a 00 4b 84

And this is what I'm actually getting (in each call): 00 00 00 00 00 00 00 00 16 00 01 00

This is an example of how the function is called:

INSERT OR IGNORE INTO table_name ( value1 , value2 ) SELECT value1 , myFunction(value1) FROM temp_table

sdejesusF commented 5 years ago

BTW, this is a Xamarin app and happens in both platforms android and ios

ericsink commented 5 years ago

Yeah, it looks like you found a bug. Not fixed yet, but there is now a test case that reproduces it. I'm guessing the problem is something simple.

ericsink commented 5 years ago

Yep, dumb mistake on my part, easy fix.

This fix will be in 2.0.1, probably sometime in the next week or so. I'll close this issue when 2.0.1 is released.

sdejesusF commented 5 years ago

Great! will keep an eye when the update is ready to upgrade.

Thanks.

ericsink commented 5 years ago

This should be fixed in 2.0.1, which has been pushed up to nuget.org.