Commit 320063f6 authored by Sebastian Ramacher's avatar Sebastian Ramacher
Browse files

fix PRIMARY KEY in bookmarks and some work on fileinfo

parent e47ff9ad
......@@ -19,17 +19,17 @@ zathura_db_init(const char* path)
/* create bookmarks database */
static const char SQL_BOOKMARK_INIT[] =
"CREATE TABLE IF NOT EXISTS bookmarks ("
"file TEXT PRIMARY KEY,"
"file TEXT,"
"id TEXT,"
"page INTEGER,"
"UNIQUE(file, id));";
"PRIMARY KEY(file, id));";
static const char SQL_FILEINFO_INIT[] =
"CREATE TABLE IF NOT EXISTS fileinfo ("
"file TEXT PRIMARY KEY,"
"page INTEGER,"
"offset INTEGER,"
"scale INTEGER);";
"scale FLOAT);";
if (sqlite3_open(path, &(db->session)) != SQLITE_OK) {
girara_error("Could not open database: %s\n", path);
......@@ -174,3 +174,29 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
return result;
}
bool
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int page, int offset, float scale)
{
g_return_val_if_fail(db && file, false);
static const char SQL_FILEINFO_SET[] =
"REPLACE INTO fileinfo (file, page, offset, scale) VALUES (?, ?, ?);";
sqlite3_stmt* stmt = prepare_statement(db->session, SQL_FILEINFO_SET);
if (stmt == NULL) {
return false;
}
if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK ||
sqlite3_bind_int(stmt, 2, page) != SQLITE_OK ||
sqlite3_bind_int(stmt, 3, offset) != SQLITE_OK ||
sqlite3_bind_double(stmt, 4, scale) != SQLITE_OK) {
sqlite3_finalize(stmt);
girara_error("Failed to bind arguments.");
return false;
}
int res = sqlite3_step(stmt);
sqlite3_finalize(stmt);
return res == SQLITE_OK;
}
......@@ -48,4 +48,15 @@ bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const
*/
girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char* file);
/**
* Set file info (last site, ...) in the database.
* @param db The database instance
* @param file The file to which the file info belongs to.
* @param page The last page.
* @param offset The last offset.
* @param scale The last scale.
* @return true on success, false otherwise.
*/
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int page, int offset, float scale);
#endif // DATABASE_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment