diff --git a/include/stmt.h b/include/stmt.h index c644421..fb52300 100644 --- a/include/stmt.h +++ b/include/stmt.h @@ -26,3 +26,12 @@ static const char set_repo_stmt_template[] = static const char dump_stmt[] = "SELECT * FROM project;" ; + +static sqlite3_stmt* get_nth_id_stmt; +static const char get_nth_id_stmt_template[] = + "SELECT rowid " + "FROM projects " + "WHERE" + "LIMIT 1 " + "OFFSET ?;" +; diff --git a/src/api.c b/src/api.c index 1e19f42..3f4098c 100644 --- a/src/api.c +++ b/src/api.c @@ -35,6 +35,7 @@ api_init(void) DBERR(sqlite3_open(DBFILE, &connection)); DBERR(stmt_prepare(remind_stmt)); DBERR(stmt_prepare(set_repo_stmt)); + DBERR(stmt_prepare(get_nth_id_stmt)); return 0; } @@ -42,6 +43,8 @@ DECL void api_rope(void) { DBERR(sqlite3_finalize(remind_stmt)); + DBERR(sqlite3_finalize(set_repo_stmt)); + DBERR(sqlite3_finalize(get_nth_id_stmt)); sqlite3_close(connection); } @@ -152,3 +155,12 @@ get_project_count(){ return r; } + +DECL int +get_nth_id(const int i){ + int r; + DBERR(sqlite3_bind_int(get_nth_id_stmt, 1, i)); + DBERR(sqlite3_step(get_nth_id_stmt)); + r = sqlite3_column_int(get_nth_id_stmt, 0); + return r; +}