aboutsummaryrefslogtreecommitdiff
path: root/captain/db.f90
diff options
context:
space:
mode:
Diffstat (limited to 'captain/db.f90')
-rw-r--r--captain/db.f9056
1 files changed, 56 insertions, 0 deletions
diff --git a/captain/db.f90 b/captain/db.f90
index 2dc1cff..b607c39 100644
--- a/captain/db.f90
+++ b/captain/db.f90
@@ -3,6 +3,7 @@ use sqlite
implicit none
integer, parameter::PLAYER_NAME_LENGTH = 128
+ integer, parameter::FILENAME_NAME_LENGTH = 1024
character(1024)::database_file
type(c_ptr)::db
@@ -135,4 +136,59 @@ contains
end function get_player_names
+ function get_instuctions_count()
+ implicit none
+
+ type(sqlite3_stmt)::stmt
+ integer::get_instuctions_count
+
+ get_instuctions_count = 0
+ if(stmt%prepare(db, "SELECT COUNT(*) FROM instructions") == SQLITE_OK) then
+ if(stmt%step() == SQLITE_ROW) then
+ get_instuctions_count = stmt%column_int(0)
+ end if
+ end if
+ call stmt%finalize()
+
+ end function get_instuctions_count
+
+ function get_instruction_names() result(res)
+ implicit none
+
+ type(sqlite3_stmt)::stmt
+ character(len=PLAYER_NAME_LENGTH), dimension(:), pointer::res
+ integer::i,n
+
+ n = get_instuctions_count()
+ if(n > 0) then
+ allocate(res(n))
+ if(stmt%prepare(db, "SELECT name FROM instructions 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_instruction_names
+
+ subroutine scan_instructions_for_db()
+ use config
+ use utilities
+ use logging
+ implicit none
+
+ character(len=2048)::cmdline
+
+ call combine_paths(script_dir, "scan_instructions.sh", cmdline)
+ cmdline = trim(cmdline)//" "//trim(database_file)//" "//trim(instructions_dir)//" 1>/dev/null 2>/dev/null"
+
+ call write_log("Scan Command: "//trim(cmdline))
+ call execute_command_line(trim(cmdline), wait=.true.)
+
+ end subroutine scan_instructions_for_db
+
end module captain_db