diff options
Diffstat (limited to 'captain/db.f90')
-rw-r--r-- | captain/db.f90 | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/captain/db.f90 b/captain/db.f90 index 1efbb18..6624cc1 100644 --- a/captain/db.f90 +++ b/captain/db.f90 @@ -45,4 +45,43 @@ contains end subroutine add_player_db + function get_player_count() + implicit none + + type(sqlite3_stmt)::stmt + integer::get_player_count + + get_player_count = 0 + if(stmt%prepare(db, "SELECT COUNT(*) FROM players") == SQLITE_OK) then + if(stmt%step() == SQLITE_ROW) then + get_player_count = stmt%column_int(0) + end if + end if + call stmt%finalize() + + end function get_player_count + + function get_player_names() result(res) + implicit none + + type(sqlite3_stmt)::stmt + character(len=256), dimension(:), pointer::res + integer::i,n + + n = get_player_count() + if(n > 0) then + allocate(res(n)) + if(stmt%prepare(db, "SELECT name FROM players ORDER BY name") == SQLITE_OK) then + i = 1 + do while(stmt%step() == SQLITE_ROW .and. i <= n) + call stmt%column_text(0, res(i)) + i = i + 1 + end do + end if + call stmt%finalize() + + end if + + end function get_player_names + end module captain_db |