pbek / QOwnNotes

QOwnNotes is a plain-text file notepad and todo-list manager with Markdown support and Nextcloud / ownCloud integration.
https://www.qownnotes.org/
GNU General Public License v2.0
4.65k stars 411 forks source link

[BUG] notes.sqlite: "Unable to establish a database connection with file" after first launch #2901

Closed tesfabpel closed 9 months ago

tesfabpel commented 11 months ago

Using the flatpak version (QOwnNotes - version 23.11.1 - GitHub - build 1062), trying to open the app, it greets me with the message: "Unable to establish a database connection with file '/run/user/1000/doc/ff2a565b/Notes/notes.sqlite'. Are the folder and the file writeable?"

After searching through the code, it seems it's displayed here: https://github.com/pbek/QOwnNotes/blob/cceb3370c333dc0d70f4dd1dcefc426107b9deb1/src/services/databaseservice.cpp#L142

Entering the flatpak environment with flatpak enter org.qownnotes.QOwnNotes bash, and issuing the command ls -al /run/user/1000/doc/ff2a565b/Notes/ it reports:

total 24
drwxr-xr-x  1 tesx tesx  190 Nov 11 09:41  .
dr-x------. 2 tesx tesx    0 Jan  1  1970  ..
-rw-r--r--  1 tesx tesx   30 Nov 11 09:26  Foo.md
-rw-r--r--  1 tesx tesx   29 Nov 11 09:27  Hi.md
-rw-------  1 tesx tesx 6345 Nov  4 10:11 'Markdown Cheatsheet.md'
-rw-r--r--  1 tesx tesx   51 Nov  4 10:15 'Note 2023-11-04T10.15.12.md'
-rw-------  1 tesx tesx 1505 Nov  4 10:11 'Welcome to QOwnNotes.md'
-rw-r--r--  1 tesx tesx    0 Nov 11 09:41  notes.sqlite

So the file is indeed writable.

Issuing the command file /run/user/1000/doc/ff2a565b/Notes/notes.sqlite it says:

/run/user/1000/doc/ff2a565b/Notes/notes.sqlite: empty

So I tried to delete the file and run the app again and no message were shown this time and the file was recreated (but still empty).
Closing the app, and restarting it, the message reappeared...

Does Qt SQL gets mad that the .sqlite is empty, expecting at least a schema inside (while with the file missing it just creates a new one)?

Expected behaviour

No message appears when starting the app.

Actual behaviour

A ciritical message "Unable to establish a database connection with file '/run/user/1000/doc/ff2a565b/Notes/notes.sqlite'. Are the folder and the file writeable?" appears when starting the app but then it continues seemingly fine (didn't test all the features) but I can edit and create new notes...

Steps to reproduce

Output from the debug section in the settings dialog

Expand QOwnNotes Debug Information =========================== ## General Info **Current Date**: `sab nov 11 09:51:35 2023` **Version**: `23.11.1` **Build date**: `Nov 10 2023` **Build number**: `1062` **Platform**: `linux` **Operating System**: `KDE Flatpak runtime` **Build architecture**: `x86_64` **Current architecture**: `x86_64` **Release**: `GitHub` **Qt Version (build)**: `5.15.10` **Qt Version (runtime)**: `5.15.10` **Portable mode**: `no` **Settings path / key**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/config/PBE/QOwnNotes.conf` **Application database path**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/data/PBE/QOwnNotes/QOwnNotes.sqlite` **Application arguments**: `QOwnNotes` **Qt Debug**: `0` **Locale (system)**: `it_IT` **Locale (interface)**: *empty* **Primary screen resolution**: `1920x1080` **Icon theme**: `breeze` **Notes in current note folder**: `5` **Calendar items**: `0` **Enabled scripts**: `0` ## Server Info **serverUrl**: *empty* **appIsValid**: `yes` **notesPathExists**: *empty* **serverVersion**: *empty* **appVersion**: *empty* ## Spellchecking **Enabled**: `true` **Selected language**: `auto` **Language codes**: `en_AU, en_BS, en_BZ, en_CA, en_GB, en_GH, en_IE, en_IN, en_JM, en_MW, en_NA, en_NZ, en_PH, en_TT, en_US, en_ZA, en_ZW, it_IT` **Language names**: `Australian English (Australia), English (Bahamas), English (Belize), Canadian English (Canada), British English (United Kingdom), English (Ghana), English (Ireland), English (India), English (Jamaica), English (Malawi), English (Namibia), English (New Zealand), English (Philippines), English (Trinidad & Tobago), American English (United States), English (South Africa), English (Zimbabwe), italiano (Italia)` **Application dictionaries path**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/data/PBE/QOwnNotes/dicts` ## Note folders **currentNoteFolderId**: `1` ### Note folder `default` **id**: `1` **isCurrent**: `yes` **activeTagId**: `0` **localPath**: `/run/user/1000/doc/ff2a565b/Notes` **remotePath**: `Notes` **cloudConnectionId**: `1` **isShowSubfolders**: `no` **isUseGit**: `no` **allowDifferentNoteFileName**: `no` **activeNoteSubFolder name**: *empty* **database file**: `/run/user/1000/doc/ff2a565b/Notes/notes.sqlite` ## Cloud connections ### Cloud connection `Predefinito` **id**: `1` **isCurrent**: `yes` **serverUrl**: *empty* **username**: *empty* **accountId**: *empty* ## Enabled scripts ## Settings **AboutDialog/geometry** (QByteArray): `` **ActiveNoteHistoryItem** (NoteHistoryItem): `` **Debug/fakeOldVersionNumber** (QString): `false` **Debug/fileLogging** (QString): `false` **Editor/CurrentSchemaKey** (QString): `EditorColorSchema-6033d61b-cb96-46d5-a3a8-20d5172017eb` **Editor/autoBracketClosing** (QString): `true` **Editor/autoBracketRemoval** (QString): `true` **Editor/disableCursorBlinking** (QString): `false` **Editor/editorWidthInDFMOnly** (QString): `true` **Editor/highlightCurrentLine** (QString): `true` **Editor/indentSize** (QString): `4` **Editor/removeTrailingSpaces** (QString): `false` **Editor/showLineNumbers** (QString): `false` **Editor/useTabIndent** (QString): `false` **Editor/vimMode** (QString): `false` **IssueAssistantDialog/geometry** (QByteArray): `` **LastUpdateCheck** (QDateTime): `2023-11-11T09:43:07.117` **MainWindow/geometry** (QByteArray): `` **MainWindow/mainToolBar.iconSize** (QString): `24` **MainWindow/menuBarGeometry** (QByteArray): `` **MainWindow/noteTextEdit.code.font** (QString): `Fira Mono,11,-1,5,50,0,0,0,0,0` **MainWindow/noteTextEdit.font** (QString): `Fira Mono,11,-1,5,50,0,0,0,0,0` **MainWindow/noteTextView.code.font** (QString): `Fira Mono,11,-1,5,50,0,0,0,0,0` **MainWindow/noteTextView.font** (QString): `Noto Sans,10,-1,5,50,0,0,0,0,0` **MainWindow/noteTextView.ignoreCodeFontSize** (QString): `true` **MainWindow/noteTextView.refreshDebounceTime** (QString): `600` **MainWindow/noteTextView.rtl** (QString): `false` **MainWindow/noteTextView.underline** (QString): `true` **MainWindow/noteTextView.useEditorStyles** (QString): `true` **MainWindow/noteTextView.useInternalExportStyling** (QString): `true` **NoteFolder-1/NoteTabNameList** (QString): `Hi` **NoteFolder-1/NoteTabStickinessList**: *empty* **NoteFolder-1/NoteTabSubFolderPathDataList** (QString): *empty* **NoteHistory-1** (QVariantList): `` **NoteHistoryCurrentIndex-1** (QString): `6` **PiwikClientId** (QString): `` **ScriptRepositoryDialog/mainSplitterState** (QByteArray): `` **SearchEngineId** (QString): `2` **SettingsDialog/geometry** (QByteArray): `` **SettingsDialog/mainSplitterState** (QByteArray): `` **ShowSystemTray** (QString): `false` **StartHidden** (QString): `false` **WelcomeDialog/geometry** (QByteArray): `` **acceptAllExternalModifications** (QString): `false` **allowNoteEditing** (bool): `true` **allowOnlyOneAppInstance** (QString): `true` **appMetrics/disableAppHeartbeat** (QString): `false` **appMetrics/disableTracking** (QString): `true` **appMetrics/notificationShown** (QString): `true` **autoReadOnlyMode** (QString): `false` **autoReadOnlyModeTimeout** (QString): `30` **automaticNoteFolderDatabaseClosing** (QString): `false` **checkSpelling** (bool): `true` **closeTodoListAfterSave** (QString): `false` **cryptoKey** (QString): `` **currentNoteFolderId** (QString): `1` **currentWorkspace** (QString): `initial` **cursorWidth** (QString): `1` **darkMode** (bool): `false` **darkModeColors** (QString): `false` **darkModeIconTheme** (QString): `false` **darkModeTrayIcon** (QString): `false` **defaultNoteFileExtension** (QString): `md` **demoNotesCreated** (QString): `true` **disableAutomaticUpdateDialog** (QString): `true` **disableSavedSearchesAutoCompletion** (QString): `false` **dockWasInitializedOnce** (QString): `true` **enableNoteTree** (QString): `false` **enableSocketServer** (QString): `true` **enableWebAppSupport** (QString): `false` **externalEditorPath** (QString): *empty* **fullyHighlightedBlockquotes** (QString): `false` **gitCommitInterval** (QString): `30` **gitExecutablePath** (QString): *empty* **gitLogCommand** (QString): *empty* **guiFirstRunInit** (bool): `true` **ignoreAllExternalModifications** (QString): `false` **ignoreAllExternalNoteFolderChanges** (QString): `false` **ignoreNoteSubFolders** (QString): `^\.` **ignoredNoteFiles** (QString): *empty* **imageScaleDown** (QString): `false` **imageScaleDownMaximumHeight** (QString): `1024` **imageScaleDownMaximumWidth** (QString): `1024` **initialLayoutIdentifier** (QString): `full` **insertTimeFormat** (QString): *empty* **interfaceFontSize** (QString): `11` **interfaceLanguage** (QString): *empty* **internalIconTheme** (QString): `false` **itemHeight** (QString): `24` **legacyLinking** (QString): `false` **localTrash/autoCleanupDays** (QString): `30` **localTrash/autoCleanupEnabled** (QString): `true` **localTrash/supportEnabled** (QString): `true` **markdownHighlightingEnabled** (QString): `true` **navigationPanelAutoSelect** (QString): `true` **navigationPanelHideSearch** (QString): `false` **networking/ignoreSSLErrors** (QString): `false` **networking/proxyType** (QString): `2` **newNoteAskHeadline** (QString): `false` **noteEditIsCentralWidget** (QString): `true` **noteFileExtensionList** (QStringList): `md, txt` **noteListPreview** (QString): `false` **noteSaveIntervalTime** (QString): `10` **noteSubfoldersPanelDisplayAsFullTree** (QString): `true` **noteSubfoldersPanelHideSearch** (QString): `false` **noteSubfoldersPanelOrder** (QString): `0` **noteSubfoldersPanelShowFullPath** (QString): `false` **noteSubfoldersPanelShowNotesRecursively** (QString): `false` **noteSubfoldersPanelShowRootFolderName** (QString): `true` **noteSubfoldersPanelSort** (QString): `0` **noteSubfoldersPanelTabsUnsetAllNotesSelection** (QString): `false` **notesPanelOrder** (QString): `0` **notesPanelSort** (QString): `1` **notesPath** (QString): `/run/user/1000/doc/ff2a565b/Notes` **notifyAllExternalModifications** (QString): `false` **overrideInterfaceFontSize** (QString): `false` **ownCloud/supportEnabled** (QString): `false` **ownCloud/todoCalendarBackend** (QString): `3` **ownCloud/todoCalendarCalDAVPassword** (QString): `` **ownCloud/todoCalendarCalDAVServerUrl** (QString): *empty* **ownCloud/todoCalendarCalDAVUsername** (QString): *empty* **ownCloud/todoCalendarCloudConnectionId** (QString): `1` **ownCloud/todoCalendarDisplayNameList**: *empty* **ownCloud/todoCalendarEnabledList**: *empty* **ownCloud/todoCalendarEnabledUrlList**: *empty* **ownCloud/todoCalendarUrlList**: *empty* **ownCloudInfo/appIsValid** (bool): `true` **ownCloudInfo/connectionErrorMessage** (QString): *empty* **ownCloudInfo/notesPathExistsText** (QString): *empty* **ownCloudInfo/serverVersion** (QString): *empty* **restoreCursorPosition** (QString): `true` **restoreLastNoteAtStartup** (QString): `true` **restoreNoteTabs** (QString): `true` **savedSearches/noteFolder-1** (QStringList): `Note 2023-11-11T09.26.54, Note 2023-11-04T10.15.12` **showMatches** (QString): `true` **showMenuBar** (bool): `true` **showStatusBar** (bool): `true` **spellCheckLanguage** (QString): `auto` **startInReadOnlyMode** (QString): `false` **systemIconTheme** (QString): `false` **taggingShowNotesRecursively** (QString): `false` **tagsPanelHideNoteCount** (QString): `false` **tagsPanelHideSearch** (QString): `false` **tagsPanelOrder** (QString): `0` **tagsPanelSort** (QString): `0` **todoCalendarSupport** (QString): `true` **toolbar/1/items** (QStringList): `action_New_note, action_Find_note, action_Remove_note, action_Open_note_in_external_editor, actionShow_local_trash, actionAllow_note_editing, , action_Back_in_note_history, action_Forward_in_note_history, , action_Find_text_in_note, actionReplace_in_current_note, , actionShow_versions, actionShow_trash, actionShare_note, , actionShow_Todo_List` **toolbar/1/name** (QString): `mainToolBar` **toolbar/1/title** (QString): `Barra degli strumenti principale` **toolbar/2/items** (QStringList): `actionFormat_text_bold, actionFormat_text_italic, actionStrike_out_text, actionInsert_code_block, actionInsert_block_quote` **toolbar/2/name** (QString): `formattingToolbar` **toolbar/2/title** (QString): `barra degli strumenti formattazione` **toolbar/3/items** (QStringList): `actionInsert_text_link, actionInsert_image, actionInsert_current_time` **toolbar/3/name** (QString): `insertingToolbar` **toolbar/3/title** (QString): `barra degli strumenti "inserisci"` **toolbar/4/items** (QStringList): `action_Encrypt_note, actionEdit_encrypted_note, actionDecrypt_note` **toolbar/4/name** (QString): `encryptionToolbar` **toolbar/4/title** (QString): `barra degli strumenti di crittografia` **toolbar/5/items** (QStringList): `actionWorkspaceComboBox, actionStore_as_new_workspace, actionRemove_current_workspace, actionRename_current_workspace, actionSwitch_to_previous_workspace, actionUnlock_panels, , actionToggle_distraction_free_mode, action_Increase_note_text_size, action_Decrease_note_text_size, action_Reset_note_text_size` **toolbar/5/name** (QString): `windowToolbar` **toolbar/5/title** (QString): `barra degli strumenti della finestra` **toolbar/6/items** (QString): `action_Quit` **toolbar/6/name** (QString): `quitToolbar` **toolbar/6/title** (QString): `esci dalla barra degli strumenti` **toolbar/size** (QString): `6` **useNoteFolderButtons** (QString): `false` **useUNIXNewline** (QString): `false` **webAppClientService/serverUrl** (QString): `wss://app.qownnotes.org` **webAppClientService/token** (QString): `` **webSocketServerService/bookmarksNoteName** (QString): `Bookmarks` **webSocketServerService/bookmarksTag** (QString): `bookmarks` **webSocketServerService/commandSnippetsNoteName** (QString): `Commands` **webSocketServerService/commandSnippetsTag** (QString): `commands` **webSocketServerService/port** (QString): `22222` **workspace-initial/name** (QString): `Completo` **workspace-initial/noteSubFolderDockWidgetVisible** (QString): `true` **workspace-initial/windowState** (QByteArray): `` **workspaces** (QString): `initial` ## System environment **XDG_RUNTIME_DIR**: `/run/user/1000` **container**: `flatpak` **AT_SPI_BUS_ADDRESS**: `unix:path=/run/flatpak/at-spi-bus` **DBUS_SESSION_BUS_ADDRESS**: `unix:path=/run/flatpak/bus` **DESKTOP_SESSION**: `plasmawayland` **FLATPAK_ID**: `org.qownnotes.QOwnNotes` **FLATPAK_SANDBOX_DIR**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/sandbox` **GDMSESSION**: `plasmawayland` **GDM_LANG**: `it_IT.UTF-8` **GI_TYPELIB_PATH**: `/app/lib/girepository-1.0` **GST_PLUGIN_PATH**: `/app/lib/gstreamer-1.0:/usr/lib/extensions/gstreamer-1.0:/usr/lib/x86_64-linux-gnu/gstreamer-1.0` **GTK2_RC_FILES**: `/etc/gtk-2.0/gtkrc:/home/tesx/.gtkrc-2.0:/home/tesx/.config/gtkrc-2.0` **GTK_RC_FILES**: `/etc/gtk/gtkrc:/home/tesx/.gtkrc:/home/tesx/.config/gtkrc` **HOME**: `/home/tesx` **INVOCATION_ID**: `b9a4c9ff2bb14c759b2db52897cda0a5` **JOURNAL_STREAM**: `8:16813` **KDE_APPLICATIONS_AS_SCOPE**: `1` **KDE_FORK_SLAVES**: `1` **KDE_FULL_SESSION**: `true` **KDE_SESSION_UID**: `1000` **KDE_SESSION_VERSION**: `5` **LANG**: `it_IT.UTF-8` **LANGUAGE**: *empty* **LD_LIBRARY_PATH**: *empty* **LOGNAME**: `tesx` **MAIL**: `/var/spool/mail/tesx` **MANAGERPID**: `1740` **MEMORY_PRESSURE_WATCH**: `/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/plasma-plasmashell.service/memory.pressure` **MEMORY_PRESSURE_WRITE**: `c29tZSAyMDAwMDAgMjAwMDAwMAA=` **MOTD_SHOWN**: `pam` **PATH**: `/app/bin:/usr/bin` **PLASMA_USE_QT_SCALING**: `1` **PS1**: `[📦 $FLATPAK_ID \W]\$ ` **PWD**: `/home/tesx` **QML2_IMPORT_PATH**: `/app/lib64/qml:/app/lib/qml` **QT_AUTO_SCREEN_SCALE_FACTOR**: `0` **QT_PLUGIN_PATH**: `/app/lib64/plugins:/app/lib/plugins:/usr/share/runtime/lib/plugins` **QT_WAYLAND_FORCE_DPI**: `96` **SESSION_MANAGER**: `local/tesx-pc:@/tmp/.ICE-unix/2024,unix/tesx-pc:/tmp/.ICE-unix/2024` **SHELL**: `/bin/sh` **SYSTEMD_EXEC_PID**: `2058` **USER**: `tesx` **USERNAME**: `tesx` **WAYLAND_DISPLAY**: `wayland-0` **XAUTHORITY**: `/run/user/1000/xauth_ixYJWH` **XCURSOR_SIZE**: `24` **XCURSOR_THEME**: `breeze_cursors` **XDG_ACTIVATION_TOKEN**: `kwin-17` **XDG_CACHE_HOME**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/cache` **XDG_CONFIG_DIRS**: `/app/etc/xdg:/etc/xdg` **XDG_CONFIG_HOME**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/config` **XDG_CURRENT_DESKTOP**: `KDE` **XDG_DATA_DIRS**: `/app/share:/usr/share:/usr/share/runtime/share:/run/host/user-share:/run/host/share` **XDG_DATA_HOME**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/data` **XDG_SEAT**: `seat0` **XDG_SESSION_CLASS**: `user` **XDG_SESSION_DESKTOP**: `plasmawayland` **XDG_SESSION_ID**: `3` **XDG_SESSION_TYPE**: `wayland` **XDG_STATE_HOME**: `/home/tesx/.var/app/org.qownnotes.QOwnNotes/.local/state` **XDG_VTNR**: `2` **ZZ_MOZ_ENABLE_WAYLAND**: `1` **__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS**: `/etc/egl/egl_external_platform.d:/usr/lib/x86_64-linux-gnu/GL/egl/egl_external_platform.d:/usr/share/egl/egl_external_platform.d`

Relevant log output in the Log panel

Expand ``` [09:52:59] [warning] QSqlDatabasePrivate::database: unable to open database: "unable to open database file Errore di apertura del database" [09:52:59] [warning] QSqlQuery::prepare: database not open [09:52:59] [warning] fetch : QSqlError("", "Impossibile ottenere la riga", "Nessuna query") ``` Translated by me: ``` [09:52:59] [warning] QSqlDatabasePrivate::database: unable to open database: "unable to open database file Error opening database" [09:52:59] [warning] QSqlQuery::prepare: database not open [09:52:59] [warning] fetch : QSqlError("", "Can't fetch the row", "No query") ```
pbek commented 11 months ago

I don't have a lot of experience with flatpak or the flatpak community repository of QOwnNotes. Does the flatpak even have permissions to write to /run/user/1000/doc/ff2a565b/Notes? What happens if you set your note folder to somewhere in your home directory?

Otherwise, best open an issue directly on https://github.com/flathub/org.qownnotes.QOwnNotes/issues.

tesfabpel commented 11 months ago

Oh, yes it does have permission to write there as the notes you see in the output of ls were created inside the app (and the notes.sqlite file is recreated by the app.

The weird path is because the app doesn't have permissions to write everywhere (it can be set via the app's manifest) and when you click the Select Folder on QOwnNotes to choose the notes directory, a portal gets used to ask the user to pick a directory, giving the app permission to use it. The real path is instead /mnt/CommonExtraLinuxFiles/DATASTORE/Documents/Notes/.

This is similar to mobile OSes like Android: the app asks the user to select a directory (or file) via OS' APIs and then the app is given access to it when the user agrees...

Anyway, I can try to give explicit access to the directory via flatpak (or FlatSeal, an app to manage permissions) to check if the issue is still present when using the real path (without having to go through the flatpak's documents portal) or to change the path to a different one.

I will report my findings and in case the issue isn't directly attributable to QOwnNotes I will open the bug issue to the flatpak repo's GitHub...


BTW, this is the output of flatpak documents:

$ flatpak documents --columns=all org.qownnotes.QOwnNotes     
ID       Path                              Origin                                               Application             Permissions
ff2a565b /run/user/1000/doc/ff2a565b/Notes /mnt/CommonExtraLinuxFiles/DATASTORE/Documents/Notes org.qownnotes.QOwnNotes read write grant-permissions
pbek commented 11 months ago

Yes, best open an issue on https://github.com/flathub/org.qownnotes.QOwnNotes/issues.

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 9 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.