BookmarkList get_bookmarks(std::string query, std::string folder, int sort) { BookmarkList bookmarks; sqlite3 *db; sqlite3_stmt *stmt; std::string sql = "SELECT url, title, icon FROM bookmarks WHERE 1"; if (query != "") sql += " AND (url LIKE '%' || ? || '%' OR title LIKE '%' || ?1 || '%')"; if (folder != "") sql += " AND folderId = '" + folder + "'"; if (sort == 0) sql += " ORDER BY length(title) > 0 DESC, title ASC"; else sql += " ORDER BY created DESC"; if (!run_statement(sql, &db, &stmt)) goto exit; if (query != "") { if (sqlite3_bind_text(stmt, 1, query.data(), -1, SQLITE_STATIC)) { std::cerr << "Error binding text: " << sqlite3_errmsg(db) << std::endl; goto exit; } } { int res = sqlite3_step(stmt); while (res == SQLITE_ROW) { Bookmark b; b.url = sqlite3_column_string(stmt, 0, ""); b.title = sqlite3_column_string(stmt, 1, b.url); b.icon = sqlite3_column_string(stmt, 2, "file:///usr/share/icons/suru/actions/scalable/stock_website.svg"); bookmarks.emplace_back(b); res = sqlite3_step(stmt); } if (res != SQLITE_DONE) { std::cerr << "Error reading rows: " << sqlite3_errmsg(db) << std::endl; } } exit: sqlite3_close(db); return bookmarks; }