Sqlite Finalize statement failing - iphone

Error: sqlite3_finalize failed (database is locked). I have released memory also properly in each view. Has anyone faced this issue?

I think you're hitting some legacy cruft in the SQLite interface. To summarize, when you sqlite3_step and the result is an error, slite3_finalize will return the same error. Pay attention to the error from sqlite3_step and other SQLite calls, and ignore the error from slite3_finalize.
Per SQLite documentation for sqlite3_finalize:
If the most recent evaluation of the statement encountered no errors or or if the statement is never been evaluated, then sqlite3_finalize() returns SQLITE_OK. If the most recent evaluation of statement S failed, then sqlite3_finalize(S) returns the appropriate error code or extended error code.
It talks about the most recent evaluation of the statement rather than the finalize itself. This is nowhere near explicit enough, but there's another comment in the documentation that is:
Goofy Interface Alert: In the legacy interface, the sqlite3_step() API always returns a generic error code, SQLITE_ERROR, following any error other than SQLITE_BUSY and SQLITE_MISUSE. You must call sqlite3_reset() or sqlite3_finalize() in order to find one of the specific error codes that better describes the error.
It goes on to say this is fixed by the v2 APIs, but I think that's only partially correct. When using the v2 APIs, sqlite3_step returns an error code directly. However, there's no sqlite3_finalize_v2. And in my testing, sqlite3_finalize continues to return the error code from sqlite3_step.
In other words: Ignore the error from sqlite3_finalize. Pay attention to the error you're almost certainly getting but ignoring from sqlite3_step.

"Database is locked" means that (duh!) the database is locked. Some other sqlite operation against the database is still "pending", possibly because you failed to finalize an earlier query, or possibly because there's a query going on in an async thread.

Related

Lync 2013 Modality.ModalityStateChanged callback not always being called

So the issue I'm having only recently started after an update to the Lync client somewhere around version 15.0.4849.1000. The issue revolves around app sharing conferences, which I have working fine still in 2016 SFB and anything prior to 15.0.4849.1000.
The core issue as far as I can tell deals with Modality.BeginConnect, the passed in callback does not get called. Although, I have had it get called when I'm debugging, stepping through the code and hitting breakpoints, etc. So that leads me to think that normally maybe something's not getting initialized in time, or some sort of race condition, but I haven't been able to pin down exactly what makes it function correctly in that case.
EDIT: I just realized another exception occurs during the call to BeginConnect:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Lync.Model.dll
Additional information: Exception from HRESULT: 0x80F10083
And that HRESULT translates to: "The operation is disabled by capability". What in the world does that mean?
The odd thing is (or seems odd to me) that even though the callback is never called, I do receive a ModalityStateChanged event for ModalityState.Connected...
So if you have any ideas what would perhaps cause that, please share!
I don't think these this is related, but a call to this:
m_aeConversationWnd = AutomationElement.FromHandle(m_ConversationWindow.Handle);
shortly before calling BeginConnect, fails with the exception:
A first chance exception of type 'System.ArgumentException' occurred in UIAutomationClientsideProviders.dll
Additional information: Value does not fall within the expected range.

How to handle error with Realm during writing?

I'm used to working with SQL database, I'm new to Realm and, so far, I'm really impressed by the ease of use of this new mobile database.
But there is something that I really don't undestand: how to handle error throwing?
Take this simple example:
I want to store in a Realm DB some market stocks.
Each stock has a "symbol" as a unique identifier: APPL for Apple Inc, TSLA for Tesla Motors Inc, etc.
I believe it would make sense to declare these symbols as primary keys, since it's not possible to have multiple times the same symbol in the database
When user clicks on a symbol (among a list of symbols), this symbol is saved in db.
In this Raywenderlich tutorial, it is said: "To simplify the code required in this tutorial, you’ll be used try! when calling Realm methods that throw an error. In your own code, you should really be using try and do / catch to catch errors and handle them appropriately."
So according to the following pattern:
do {
try realm.write {
realm.add(symbol)
}
}
catch let error as NSError {
print("Something went wrong: \(error.localizedDescription)")
}
So far it makes sense.
And if a user clicks on a symbol that is already in the database, I get (very logically) an error:
*** Terminating app due to uncaught exception 'RLMException', reason: 'Can't set primary key property 'symbol' to existing value 'APPL'.'
The problem is that this error is not catched during run time: I've got a crash instead.
My question is not about how to avoid such a crash, I understand of course that it's easy to avoid it by doing a simple testing before writing anything in the database :)
My question is how do we do in Realm to catch potential writing errors?
Am I doing something wrong?
do/try/catch in Swift catch Swift Errors, which are an entirely distinct thing from Objective-C exceptions. Realm follows Foundation's pattern for error reporting: API misuse errors throw exceptions which are not intended to be caught (and can't be caught in Swift), and recoverable errors throw Swift errors (or use NSError out parameters in Objective-C).
Adding an object with a duplicate primary key is considered API misuse, so it's a fatal error as the route for "handling" it is to fix the bug in your code. An example of a recoverable error which would produce a Swift error that would be caught by catch is running out of disk space while trying to save the new data.
There are two distinct types of error: programmer error, and expected errors. Realm handles these two types of errors differently.
Programmer error covers cases such as accessing objects from incorrect threads, out-of-bounds collection access, attempting to insert an object with a duplicate primary key, and so forth. Realm responds to these programmer errors by throwing an Objective-C exception. These exceptions are not intended to be caught and handled as they're indicative of a bug in a Realm user's code.
Expected errors cover things like files not existing, permission errors, failures to write to disk. These are things that can happen even with correctly-written code due to factors outside of the programs control. These are exposed as NSErrors and can be caught from Swift using do / try / catch. Note that Realm's Objective-C API has some convenience methods that don't expose the NSError. In these cases an expected error will throw an exception as there's no other avenue for Realm to communicate the failure. Rather than attempting to catch and handle exceptions raised by these convenience methods, you should use the variant of the API that returns an NSError instead.
Hi, the error line said "to existing value", don't you try to write more than one time the same primary key with 'APPL' ?
you need to update it, not override.
if you try to "add" again the same value, it's gonna stop you.
(sorry for bad english x) )

I am having issues while decryption using RNCryptor Library

While decrypting I get the error : The operation couldnot be performed RNCryptorError 1
I dont understand what I am doing wrong. Here is my block of code
For anyone who might search here: this is a duplicate of RNCryptor#174, and you may want to read there as well.
Please just post code into the question rather than a screenshot. I can't compile a screenshot, and they're very hard to read.
Error 1 is an HMAC error. Either your data is corrupted or your password is incorrect.
Note that NSException never makes sense in Swift. Switch can't catch them. They only make sense in ObjC if you're going to crash the program shortly after. They're not memory-safe in ObjC. You meant to use Swift's throw and ErrorType, which are unrelated to raise or NSException.

Xcode Runtime Error log: What does the [#:#] mean in AppName[#:#]?

I got the following runtime error:
2014-12-10 19:26:39.695 Bliss2[21855:994070] Error: object not found for update (Code: 101, Version: 1.5.0)
I assume the [21855:994070] has a meaning.
How do I use it to track down the error in the code?
That is not a "runtime error". It is an NSLog message and has been executed and logged in perfectly good order (e.g. by some third-party code you are using?). Of course the code may then have thrown an exception / aborted, but if it did (and I don't know whether it did), that has nothing to do with the log message itself, except that you're being told first that there's a problem, apparently as a courtesy.
As for the numbers, they probably have nothing to say that will concern you here. The first number is your process number and won't be stable between invocations; it is rarely of interest. The second number is the thread number and is of interest when there are many log statements for discovering whether this log statement is executed in a background thread (or in the same thread as other log statements).

error handling vs exception handling in objective c

I am not able to understand the places where an error handling or where an exception handling should be used. I assume this, if it is an existing framework class there are delegate methods which will facilitate the programmer to send an error object reference and handle the error after that. Exception handling is for cases where an operation of a programmer using some framework classes throws an error and i cannot get an fix on the error object's reference.
Is this assumption valid ? or how should i understand them ?
You should use exceptions for errors that would never appear if the programmer would have checked the parameters to the method that throws the exception. E.g. divide by 0 or the well known "out of bounds"-exception you get from NSArrays.
NSErrors are for errors that the programmer could do nothing about. E.g. parsing a plist file. It would be a waste of resources if the program would check if the file is a valid plist before it tries to read its content. For the validity check the program must parse the whole file. And parsing a file to report that it is valid so you can parse it again would be a total waste. So the method returns a NSError (or just nil, which tells you that something went wrong) if the file can't be parsed.
The parsing for validity is the "programmer should have checked the parameters" part. It's not applicable for this type of errors, so you don't throw a exception.
In theory you could replace the out of bounds exception with a return nil. But this would lead to very bad programming.
Apple says:
Important: In many environments, use of exceptions is fairly commonplace. For example, you might throw an exception to signal that a routine could not execute normally—such as when a file is missing or data could not be parsed correctly. Exceptions are resource-intensive in Objective-C. You should not use exceptions for general flow-control, or simply to signify errors. Instead you should use the return value of a method or function to indicate that an error has occurred, and provide information about the problem in an error object.
I think you are absolutely right with your assumption for Errors and for it framework provide a set of methods (UIWebView error handling ), But your assumption for Exception partially right because the exception only occurred if we do something wrong which is not allowed by the framework and can be fixed. (for example accessing a member from an array beyond its limit).
and will result in application crash.