aboutsummaryrefslogtreecommitdiff
path: root/captain/db.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-03-26 11:19:59 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-03-26 11:19:59 -0400
commit13f8f7e0e5b2361a5d3aa3f3a21519b03cd4c9c2 (patch)
tree62914777fe9fef2ade01be0361d65900bf73aacf /captain/db.f90
parent2a79043e4b33118437b3ade35a792b9e0d1323be (diff)
downloadlevitating-13f8f7e0e5b2361a5d3aa3f3a21519b03cd4c9c2.tar.gz
levitating-13f8f7e0e5b2361a5d3aa3f3a21519b03cd4c9c2.zip
Started work on a template engine complete with variables. Added a few database routines and some hopeful, untested changes to the sql creation script.
Diffstat (limited to 'captain/db.f90')
-rw-r--r--captain/db.f9039
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