Merge branch 'girara'

This commit is contained in:
Moritz Lipp 2011-09-29 11:43:01 +02:00
commit 8a1f1816fd
2 changed files with 82 additions and 3 deletions

View File

@ -19,17 +19,17 @@ zathura_db_init(const char* path)
/* create bookmarks database */ /* create bookmarks database */
static const char SQL_BOOKMARK_INIT[] = static const char SQL_BOOKMARK_INIT[] =
"CREATE TABLE IF NOT EXISTS bookmarks (" "CREATE TABLE IF NOT EXISTS bookmarks ("
"file TEXT PRIMARY KEY," "file TEXT,"
"id TEXT," "id TEXT,"
"page INTEGER," "page INTEGER,"
"UNIQUE(file, id));"; "PRIMARY KEY(file, id));";
static const char SQL_FILEINFO_INIT[] = static const char SQL_FILEINFO_INIT[] =
"CREATE TABLE IF NOT EXISTS fileinfo (" "CREATE TABLE IF NOT EXISTS fileinfo ("
"file TEXT PRIMARY KEY," "file TEXT PRIMARY KEY,"
"page INTEGER," "page INTEGER,"
"offset INTEGER," "offset INTEGER,"
"scale INTEGER);"; "scale FLOAT);";
if (sqlite3_open(path, &(db->session)) != SQLITE_OK) { if (sqlite3_open(path, &(db->session)) != SQLITE_OK) {
girara_error("Could not open database: %s\n", path); girara_error("Could not open database: %s\n", path);
@ -174,3 +174,61 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
return result; 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;
}
bool
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* page, int* offset, float* scale)
{
g_return_val_if_fail(db && file && page && ofset && scale, false);
static const char SQL_FILEINFO_GET[] =
"SELECT page, offset, scale FROM fileinfo WHERE file = ?;";
sqlite3_stmt* stmt = prepare_statement(db->session, SQL_FILEINFO_GET);
if (stmt == NULL) {
return false;
}
if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK)
sqlite3_finalize(stmt);
girara_error("Failed to bind arguments.");
return false;
}
if (sqlite3_step(stmt) != SQLITE_ROW) {
sqlite3_finalize(stmt);
girara_info("No info for file %s available.", file);
return false;
}
*page = sqlite3_column_int(stmt, 0);
*offset = sqlite3_column_int(stmt, 1);
*scale = sqlite3_column_double(stmt, 2);
sqlite3_finalize(stmt);
return true;
}

View File

@ -48,4 +48,25 @@ 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); 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);
/* Get file info (last site, ...) from 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_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* page, int* offset, float* scale);
#endif // DATABASE_H #endif // DATABASE_H