Beispiel #1
0
FolderList get_bookmark_folders() {
    FolderList folders;

    sqlite3 *db;
    sqlite3_stmt *stmt;
    std::string sql = "SELECT folderId, folder FROM folders ORDER BY folder";

    if (!run_statement(sql, &db, &stmt))
        goto exit;

    {
        int res = sqlite3_step(stmt);
        while (res == SQLITE_ROW) {
            Folder f;
            f.id = sqlite3_column_string(stmt, 0, "-1");
            f.name = sqlite3_column_string(stmt, 1, "");
            folders.emplace_back(f);
            res = sqlite3_step(stmt);
        }
        if (res != SQLITE_DONE) {
            std::cerr << "Error reading rows: " << sqlite3_errmsg(db) << std::endl;
        }
    }

    exit:
    sqlite3_close(db);
    return folders;
}
Beispiel #2
0
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;
}
Beispiel #3
0
string
PibDb::getOwnerName() const
{
  sqlite3_stmt* statement;
  sqlite3_prepare_v2(m_database, "SELECT owner FROM mgmt", -1, &statement, nullptr);

  if (sqlite3_step(statement) == SQLITE_ROW) {
    m_owner = sqlite3_column_string(statement, 0);
  }

  sqlite3_finalize(statement);
  return m_owner;
}
Beispiel #4
0
std::string
PibDb::getTpmLocator() const
{
  sqlite3_stmt* statement;
  sqlite3_prepare_v2(m_database, "SELECT tpm_locator FROM mgmt", -1, &statement, nullptr);

  string tpmLocator;
  if (sqlite3_step(statement) == SQLITE_ROW) {
    tpmLocator = sqlite3_column_string(statement, 0);
  }

  sqlite3_finalize(statement);
  return tpmLocator;
}