DataStoreError: The operation couldn’t be completed. (SQLite.Result error 0.)

1.1k Views Asked by At

I am using AWS Appsync, AWS datastore, Aws Cognito, Aws API. When I am trying to save data on AWS Datastore it gives me this error

DataStoreError: The operation couldn’t be completed. (SQLite.Result error 0.).

let msg = Message.init(....)
//where Message is genrated from amplify codegen models
print(msg) // Output Message()
Amplify.DataStore.save(msg) { result in
    print(msg)// Output Message()
    switch result {
    case .success:
        print("Post saved successfully!")
    case .failure(let error):
        print("Error saving post \(error)")
    }
}

I also get this response in my console.

[SQLiteStorageEngineAdapter] insert into Message (.....) values (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

I have created another sample project using the same model and it works fine there.

3

There are 3 best solutions below

2
On BEST ANSWER

After spending 8 - 9 days found this. Target < Project Name < Build Settings < Reflection Metadata level. Make sure you select "All" in this.enter image description here

This setting controls the level of reflection metadata the Swift compiler emits.

All: Type information about stored properties of Swift structs and classes, Swift enum cases, and their names, are emitted into the binary for reflection and analysis in the Memory Graph Debugger.

Without Names: Only type information about stored properties and cases are emitted into the binary, with their names omitted. -disable-reflection-names

None: No reflection metadata is emitted into the binary. Accuracy of detecting memory issues involving Swift types in the Memory Graph Debugger will be degraded and reflection in Swift code may not be able to discover children of types, such as properties and enum cases. -disable-reflection-metadata.

In my case that was in None. Please make sure you select "All".

0
On

@Mandhata Singh solution did not work for me.

I deleted the app and installed it again and it worked fine.

Note: deleting the app will delete the database with it. so the data will be lost.

0
On

This error was returned under similar circumstances in my case: saving an item. It was only throwing errors when I tried saving a model that I had recently created in Amplify. I was able to solve it by quitting the emulator (ios) and rerunning the application. It seems that resetting the environment is a solution to 50% of the problems with Amplify