nolanlawson / cordova-plugin-sqlite-2

Native SQLite database API for Cordova/PhoneGap/Ionic, modeled after WebSQL (UNMAINTAINED)
https://nolanlawson.com/2016/04/10/introducing-the-cordova-sqlite-plugin-2/
Apache License 2.0
168 stars 28 forks source link

Blob crashes thread #32

Closed adamscybot closed 8 years ago

adamscybot commented 8 years ago

I have a situation where I want to retrieve a large blob (its an image) from an sql database. When I do this, the thread crashes:

2016-06-14 09:39:32.398 OptiExpert[3912:1058334] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]
: object cannot be nil'
*** First throw call stack:
5d0d 0x66e83 0x66517 0x661ef 0x25693cbf 0x2569f6a1 0x2569f07b 0x25832e0d 0x258329fc)
libc++abi.dylib: terminating with uncaught exception of type NSException
Process 3912 stopped
* thread #10: tid = 0x10261e, 0x2578fc5c libsystem_kernel.dylib`__pthread_kill + 8, queue = 'com.apple.root.default-qos', activity = 'starting resolver activity', stop reaso
n = signal SIGABRT
   frame #0: 0x2578fc5c libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x2578fc5c <+8>:  blo    0x2578fc74                ; <+32>
   0x2578fc60 <+12>: ldr    r12, [pc, #0x4]           ; <+24>
   0x2578fc64 <+16>: ldr    r12, [pc, r12]
   0x2578fc68 <+20>: b      0x2578fc70                ; <+28>
nolanlawson commented 8 years ago

This module serializes all blobs as strings due to limitations of the WebSQL API and the Cordova plugin API. In fact due to limitations of the WebView itself, there is no way around serialization, so blobs of a certain size will always cause crashes.

My recommendation is to break up large blobs into smaller ones and insert them as separate columns or separate rows. Sorry about that. It's definitely a pain, but it's unfixable AFAIK.

adamscybot commented 8 years ago

I actually have worked around this by dumping string conversion and instead using Base 64. So I guess it's not the size alone but the size + string conversion? Either that or certain characters in the output crash when they get serialised to JSON, which has been documented other older plugin and then fixer with url encoding. This still didn't work for me though.

nolanlawson commented 8 years ago

Yeah, it's hard to say. Everything has to be serialized, though. In general if you want to store big blobs, the best solution is storing blobs in IndexedDB on Android, and wait for Safari to implement blobs for IndexedDB on iOS.