, everything is working well i can see datas in my sqlite database. However, when i kill my app, the database is empty.
I've tried to save context on applicationWillTerminate but it doesn't change anything,
do {
try dataStack.unsafeContext().save()
} catch {
}
Any idea of what's happens ?
Thanks you in advance for your answer.
Originally created by @odilebellerose on GitHub (Mar 30, 2022).
Hi,
when i create some objects by using
```
dataStack.perform( asynchronous: { (transaction) -> StoredDocument? in) })
```
, everything is working well i can see datas in my sqlite database. However, when i kill my app, the database is empty.
I've tried to save context on applicationWillTerminate but it doesn't change anything,
```
do {
try dataStack.unsafeContext().save()
} catch {
}
```
Any idea of what's happens ?
Thanks you in advance for your answer.
I'm not sure I understand what you mean. You are sure that the SQLite database is created and populated correctly, but the file disappears after you terminate the app?
If so then something in your code is deleting the database manually, as CoreStore doesn't have any mechanism that automatically deletes the store.
@JohnEstropia commented on GitHub (Mar 30, 2022):
I'm not sure I understand what you mean. You are sure that the SQLite database is created and populated correctly, but the file disappears after you terminate the app?
If so then something in your code is deleting the database manually, as CoreStore doesn't have any mechanism that automatically deletes the store.
@odilebellerose commented on GitHub (Mar 30, 2022):
I'm not sure I understand what you mean. You are sure that the SQLite database is created and populated correctly, but the file disappears after you terminate the app?
If so then something in your code is deleting the database manually, as CoreStore doesn't have any mechanism that automatically deletes the store.
The database still exists but records are deleted. Do you know if there is a way that CoreStore re-create sqlite database or erase the content ?
@odilebellerose commented on GitHub (Mar 30, 2022):
> I'm not sure I understand what you mean. You are sure that the SQLite database is created and populated correctly, but the file disappears after you terminate the app?
>
> If so then something in your code is deleting the database manually, as CoreStore doesn't have any mechanism that automatically deletes the store.
The database still exists but records are deleted. Do you know if there is a way that CoreStore re-create sqlite database or erase the content ?
Is the SQLite file URL constant or is it generated and somehow changes every launch?
The only reason CoreStore would reset a database is if the schema was updated AND the .recreateStoreOnModelMismatch option is set on the SQLiteStore
@JohnEstropia commented on GitHub (Mar 30, 2022):
Is the SQLite file URL constant or is it generated and somehow changes every launch?
The only reason CoreStore would reset a database is if the schema was updated AND the `.recreateStoreOnModelMismatch` option is set on the `SQLiteStore`
@odilebellerose commented on GitHub (Mar 30, 2022):
I have a Singleton, with a start() func :
```
open func start() {
let store = SQLiteStore(fileName: "documents_storage.sqlite")
do {
try self.dataStack.addStorageAndWait(store)
} catch {
}
}
```
and i'm calling this function in the AppDelegate :
```
open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DocumentStorageManager.shared.start()
return true
}
```
Are you using storyboards? If so you are likely accessing the DataStack before addStorageAndWait() returns. Storyboard initial ViewControllers get initialized before the UIAppDelegate's didFinishLaunching is called. At least if I recall correctly.
Put a breakpoint on the dataStack getter and the addStorageAndWait() call and see if it's getting accessed somewhere else before the store is added.
@JohnEstropia commented on GitHub (Mar 30, 2022):
Are you using storyboards? If so you are likely accessing the `DataStack` before `addStorageAndWait()` returns. Storyboard initial ViewControllers get initialized before the `UIAppDelegate`'s `didFinishLaunching` is called. At least if I recall correctly.
Put a breakpoint on the `dataStack` getter and the `addStorageAndWait()` call and see if it's getting accessed somewhere else before the store is added.
@odilebellerose commented on GitHub (Mar 30, 2022):
Are you using storyboards? If so you are likely accessing the DataStack before addStorageAndWait() returns. Storyboard initial ViewControllers get initialized before the UIAppDelegate's didFinishLaunching is called. At least if I recall correctly.
Put a breakpoint on the dataStack getter and the addStorageAndWait() call and see if it's getting accessed somewhere else before the store is added.
I'm not using Storyboards and i tried to put breakpoints on functions using the dataStack it's seems ok. The addStorageAndWait() func seems to be called first.
@odilebellerose commented on GitHub (Mar 30, 2022):
> Are you using storyboards? If so you are likely accessing the `DataStack` before `addStorageAndWait()` returns. Storyboard initial ViewControllers get initialized before the `UIAppDelegate`'s `didFinishLaunching` is called. At least if I recall correctly.
>
> Put a breakpoint on the `dataStack` getter and the `addStorageAndWait()` call and see if it's getting accessed somewhere else before the store is added.
I'm not using Storyboards and i tried to put breakpoints on functions using the dataStack it's seems ok. The `addStorageAndWait() `func seems to be called first.
How are you confirming the SQLite file contents? Are you sure the perform() methods are completing successfully?
@JohnEstropia commented on GitHub (Mar 30, 2022):
How are you confirming the SQLite file contents? Are you sure the `perform()` methods are completing successfully?
@odilebellerose commented on GitHub (Mar 30, 2022):
If i open the SQLite file in a browser i can see my records. In fact, i'm using CoreStore to store documents that i'm going to upload by using operation queue and background task. If i keep the app open or put it in the background, everything is working well. That's why i can confirm SQLite file contents. If i kill the app and re-open it, my app should fetch documents in database and try to re-upload documents but they have been deleted.
@odilebellerose commented on GitHub (Mar 30, 2022):
If i open the SQLite file in a browser i can see my records. In fact, i'm using CoreStore to store documents that i'm going to upload by using operation queue and background task. If i keep the app open or put it in the background, everything is working well. That's why i can confirm SQLite file contents. If i kill the app and re-open it, my app should fetch documents in database and try to re-upload documents but they have been deleted.
There's definitely something deleting your file (or a parent folder) somewhere. If you can isolate the issue in a shareable project I'll try to take a look.
@JohnEstropia commented on GitHub (Mar 30, 2022):
There's definitely something deleting your file (or a parent folder) somewhere. If you can isolate the issue in a shareable project I'll try to take a look.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @odilebellerose on GitHub (Mar 30, 2022).
Hi,
when i create some objects by using
, everything is working well i can see datas in my sqlite database. However, when i kill my app, the database is empty.
I've tried to save context on applicationWillTerminate but it doesn't change anything,
Any idea of what's happens ?
Thanks you in advance for your answer.
@JohnEstropia commented on GitHub (Mar 30, 2022):
I'm not sure I understand what you mean. You are sure that the SQLite database is created and populated correctly, but the file disappears after you terminate the app?
If so then something in your code is deleting the database manually, as CoreStore doesn't have any mechanism that automatically deletes the store.
@odilebellerose commented on GitHub (Mar 30, 2022):
The database still exists but records are deleted. Do you know if there is a way that CoreStore re-create sqlite database or erase the content ?
@JohnEstropia commented on GitHub (Mar 30, 2022):
Is the SQLite file URL constant or is it generated and somehow changes every launch?
The only reason CoreStore would reset a database is if the schema was updated AND the
.recreateStoreOnModelMismatchoption is set on theSQLiteStore@odilebellerose commented on GitHub (Mar 30, 2022):
I have a Singleton, with a start() func :
and i'm calling this function in the AppDelegate :
@JohnEstropia commented on GitHub (Mar 30, 2022):
Are you using storyboards? If so you are likely accessing the
DataStackbeforeaddStorageAndWait()returns. Storyboard initial ViewControllers get initialized before theUIAppDelegate'sdidFinishLaunchingis called. At least if I recall correctly.Put a breakpoint on the
dataStackgetter and theaddStorageAndWait()call and see if it's getting accessed somewhere else before the store is added.@odilebellerose commented on GitHub (Mar 30, 2022):
I'm not using Storyboards and i tried to put breakpoints on functions using the dataStack it's seems ok. The
addStorageAndWait()func seems to be called first.@JohnEstropia commented on GitHub (Mar 30, 2022):
How are you confirming the SQLite file contents? Are you sure the
perform()methods are completing successfully?@odilebellerose commented on GitHub (Mar 30, 2022):
If i open the SQLite file in a browser i can see my records. In fact, i'm using CoreStore to store documents that i'm going to upload by using operation queue and background task. If i keep the app open or put it in the background, everything is working well. That's why i can confirm SQLite file contents. If i kill the app and re-open it, my app should fetch documents in database and try to re-upload documents but they have been deleted.
@JohnEstropia commented on GitHub (Mar 30, 2022):
After restarting the app, do you still see the records in the SQLite browser?
@odilebellerose commented on GitHub (Mar 30, 2022):
No, i can't.
@JohnEstropia commented on GitHub (Mar 30, 2022):
There's definitely something deleting your file (or a parent folder) somewhere. If you can isolate the issue in a shareable project I'll try to take a look.
@odilebellerose commented on GitHub (Mar 30, 2022):
Unfortunately i can't :/
Thanks you for your help, i'm going to try to figure it out.