diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-25 16:50:32 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-25 16:50:32 -0400 |
commit | 2a79043e4b33118437b3ade35a792b9e0d1323be (patch) | |
tree | ea2e50b8a624543b59ab8a0da7b3a630dd9143f0 /captain/db.f90 | |
parent | 1545914afff13e37bfcfee1b04828942e430a819 (diff) | |
download | levitating-2a79043e4b33118437b3ade35a792b9e0d1323be.tar.gz levitating-2a79043e4b33118437b3ade35a792b9e0d1323be.zip |
Started on server components. Implemented thin, only-necessary sqlite wrapping in Fortran.
Diffstat (limited to 'captain/db.f90')
-rw-r--r-- | captain/db.f90 | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/captain/db.f90 b/captain/db.f90 new file mode 100644 index 0000000..1efbb18 --- /dev/null +++ b/captain/db.f90 @@ -0,0 +1,48 @@ +module captain_db +use sqlite +implicit none + + character(1024)::database_file + type(c_ptr)::db + +contains + + subroutine initialize_db(filename) + implicit none + + character(*), intent(in)::filename + + if(sqlite3_open(filename, db) == SQLITE_OK) then + database_file = filename + else + Print *, "ERROR: Could not open db" + stop + end if + + end subroutine initialize_db + + subroutine shutdown_db() + implicit none + + integer::i + + i = sqlite3_close(db) + + end subroutine shutdown_db + + subroutine add_player_db(name, token) + implicit none + + character(*), intent(in)::name, token + type(sqlite3_stmt)::stmt + + if(stmt%prepare(db, "INSERT INTO players(name, token) VALUES(?, ?)") == SQLITE_OK) then + if(stmt%bind_text(1, "name!") == SQLITE_OK .and. stmt%bind_text(2, "token!") == SQLITE_OK) then + call stmt%step_now() + end if + end if + call stmt%finalize() + + end subroutine add_player_db + +end module captain_db |