I have some code in my application that looks something like this:
char *hash = (char*) sqlite3_column_text(get_bookmark, 0);
NSString* postHash = [NSString stringWithUTF8String:hash];
This works for me every time; I've never seen it not work. Most of my users do not experience problems (as far as I know). However I find that postHash
is an empty string (@""
) for some users some of the time.
Can anyone explain why?
Some more context/speculation:
This only seems to happen on jailbroken handsets. Is there anything different about them? I gather that there's usually less memory available. Anything else that could contribute here?
postHash
is used in a table cell and is occasionally seen to be populated correctly so I'm reasonably confident that the database call should work. In fact, if the database also has an empty string it's because of a very similar piece of code so the question remains.
hash
is certainly returning with a non-NULL value. If I force a NULL here, the app crashes. Similarly, postHash
is not nil
as that would also crash the app (for the same reason).
I am thinking that this is possibly memory related. If the method tries to allocate too much memory before -didReceiveMemoryWarning
can get called what happens? I know that, at some point, the Springboard ejects the app. But is it possible that Cocoa returns a null string here rather than the expected value? I've heard of a few reports that, as far as I can tell, can only have been caused by an empty string being present where something longer should have been present.
Any other speculation, theories or ideas welcome.
However I find that
postHash
is an empty string (@""
) for some users some of the time.Can anyone explain why?
Because hash
is an empty string (hash[0] == '\0'
).
I finally found the solution to this. I'm going to give Peter the accepted answer as he is right but the reason that I was getting an empty string is... interesting.
The database is populated correctly. The query is also correct. The difference between my phone and my users is that they have jail broken handsets. And apparently jail broken iPhones sometimes use a different version of SQLite than found in shipping versions of iPhone OS.
The change in version exposed a bug in my code that caused one of the parameters to be set incorrectly and sqlite3_column_text
to return an empty string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With