mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-16 05:55:50 +01:00
Add some comments to the code
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
4c795259fe
commit
3171a4f7f6
1 changed files with 20 additions and 13 deletions
|
@ -118,7 +118,7 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
|
||||||
{
|
{
|
||||||
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
|
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
|
||||||
|
|
||||||
/* create bookmarks database */
|
/* create bookmarks table */
|
||||||
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,"
|
"file TEXT,"
|
||||||
|
@ -128,6 +128,7 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
|
||||||
"vadj_ratio FLOAT,"
|
"vadj_ratio FLOAT,"
|
||||||
"PRIMARY KEY(file, id));";
|
"PRIMARY KEY(file, id));";
|
||||||
|
|
||||||
|
/* create fileinfo table */
|
||||||
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,"
|
||||||
|
@ -141,30 +142,35 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
|
||||||
"position_y FLOAT"
|
"position_y FLOAT"
|
||||||
");";
|
");";
|
||||||
|
|
||||||
static const char SQL_FILEINFO_ALTER[] =
|
/* create history table */
|
||||||
"ALTER TABLE fileinfo ADD COLUMN pages_per_row INTEGER;"
|
|
||||||
"ALTER TABLE fileinfo ADD COLUMN position_x FLOAT;"
|
|
||||||
"ALTER TABLE fileinfo ADD COLUMN position_y FLOAT;";
|
|
||||||
|
|
||||||
static const char SQL_FILEINFO_ALTER2[] =
|
|
||||||
"ALTER TABLE fileinfo ADD COLUMN first_page_column INTEGER;";
|
|
||||||
|
|
||||||
static const char SQL_BOOKMARK_ALTER[] =
|
|
||||||
"ALTER TABLE bookmarks ADD COLUMN hadj_ratio FLOAT;"
|
|
||||||
"ALTER TABLE bookmarks ADD COLUMN vadj_ratio FLOAT;";
|
|
||||||
|
|
||||||
static const char SQL_HISTORY_INIT[] =
|
static const char SQL_HISTORY_INIT[] =
|
||||||
"CREATE TABLE IF NOT EXISTS history ("
|
"CREATE TABLE IF NOT EXISTS history ("
|
||||||
"time TIMESTAMP,"
|
"time TIMESTAMP,"
|
||||||
"line TEXT,"
|
"line TEXT,"
|
||||||
"PRIMARY KEY(line));";
|
"PRIMARY KEY(line));";
|
||||||
|
|
||||||
|
/* update fileinfo table (part 1) */
|
||||||
|
static const char SQL_FILEINFO_ALTER[] =
|
||||||
|
"ALTER TABLE fileinfo ADD COLUMN pages_per_row INTEGER;"
|
||||||
|
"ALTER TABLE fileinfo ADD COLUMN position_x FLOAT;"
|
||||||
|
"ALTER TABLE fileinfo ADD COLUMN position_y FLOAT;";
|
||||||
|
|
||||||
|
/* update fileinfo table (part 2) */
|
||||||
|
static const char SQL_FILEINFO_ALTER2[] =
|
||||||
|
"ALTER TABLE fileinfo ADD COLUMN first_page_column INTEGER;";
|
||||||
|
|
||||||
|
/* update bookmark table */
|
||||||
|
static const char SQL_BOOKMARK_ALTER[] =
|
||||||
|
"ALTER TABLE bookmarks ADD COLUMN hadj_ratio FLOAT;"
|
||||||
|
"ALTER TABLE bookmarks ADD COLUMN vadj_ratio FLOAT;";
|
||||||
|
|
||||||
sqlite3* session = NULL;
|
sqlite3* session = NULL;
|
||||||
if (sqlite3_open(path, &session) != SQLITE_OK) {
|
if (sqlite3_open(path, &session) != SQLITE_OK) {
|
||||||
girara_error("Could not open database: %s\n", path);
|
girara_error("Could not open database: %s\n", path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* create tables if they don't exist */
|
||||||
if (sqlite3_exec(session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) {
|
if (sqlite3_exec(session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) {
|
||||||
girara_error("Failed to initialize database: %s\n", path);
|
girara_error("Failed to initialize database: %s\n", path);
|
||||||
sqlite3_close(session);
|
sqlite3_close(session);
|
||||||
|
@ -183,6 +189,7 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check existing tables for missing columns */
|
||||||
bool res1, res2, ret1, ret2;
|
bool res1, res2, ret1, ret2;
|
||||||
|
|
||||||
ret1 = check_column(session, "fileinfo", "pages_per_row", &res1);
|
ret1 = check_column(session, "fileinfo", "pages_per_row", &res1);
|
||||||
|
|
Loading…
Reference in a new issue