@@ -40,60 +40,23 @@ void NoteSubFolder::setParentId(int parentId) { _parentId = parentId; }
40
40
bool NoteSubFolder::isFetched () const { return (_id > 0 ); }
41
41
42
42
NoteSubFolder NoteSubFolder::fetch (int id, const QString &connectionName) {
43
- auto noteSubFolder = NoteSubFolder ();
44
- // bool closeDb = connectionName != QStringLiteral("memory");
45
- bool closeDb = false ;
46
-
47
- {
48
- // QSqlDatabase db = DatabaseService::getSharedMemoryDatabase(connectionName);
49
- qDebug () << __func__ << " - 'connectionName': " << connectionName;
50
- qDebug () << __func__ << " - 'id': " << id;
51
-
52
- // if (connectionName == QStringLiteral("memory")) {
53
- // void* array[50];
54
- // int size = backtrace(array, 50);
55
- // char** messages = backtrace_symbols(array, size);
56
- //
57
- // // Print the stack trace
58
- // for (int i = 0; i < size && messages != nullptr; ++i) {
59
- // qDebug() << "[" << i << "]" << messages[i];
60
- // }
61
- // free(messages);
62
- // }
63
-
64
- const QSqlDatabase db = QSqlDatabase::database (connectionName);
65
-
66
- // if (!db.open()) {
67
- // qWarning() << "Failed to open database in thread:" << db.lastError().text();
68
- // if (closeDb) {
69
- // QSqlDatabase::removeDatabase(connectionName);
70
- // }
71
- // return {};
72
- // }
73
-
74
- QSqlQuery query (db);
75
- query.prepare (QStringLiteral (" SELECT * FROM noteSubFolder WHERE id = :id" ));
76
- query.bindValue (QStringLiteral (" :id" ), id);
77
-
78
- if (!query.exec ()) {
79
- qWarning () << __func__ << " : " << query.lastError ();
80
- } else {
81
- if (query.first ()) {
82
- noteSubFolder = noteSubFolderFromQuery (query);
83
- }
84
- }
85
-
86
- query.finish ();
43
+ const QSqlDatabase db = QSqlDatabase::database (connectionName);
44
+ QSqlQuery query (db);
45
+ query.prepare (QStringLiteral (" SELECT * FROM noteSubFolder WHERE id = :id" ));
46
+ query.bindValue (QStringLiteral (" :id" ), id);
87
47
88
- // if (closeDb) {
89
- // db.close();
90
- // }
91
- } // db goes out of scope here
48
+ auto noteSubFolder = NoteSubFolder ();
92
49
93
- if (closeDb) {
94
- QSqlDatabase::removeDatabase (connectionName);
50
+ if (!query.exec ()) {
51
+ qWarning () << __func__ << " : " << query.lastError ();
52
+ } else {
53
+ if (query.first ()) {
54
+ noteSubFolder = noteSubFolderFromQuery (query);
55
+ }
95
56
}
96
57
58
+ query.finish ();
59
+
97
60
return noteSubFolder;
98
61
}
99
62
0 commit comments