You have successfully reverse-engineered a lot. To pick up on one other point:
The mdl_resources.displayoptions column is storing PHP serialised data. http://php.net/manual/en/function.serialize.php.
The other general approach you could take, rather than writing data directly to the database, would be to write a Moodle backup file. A Moodle backup is basically a .zip file (renamed to .mbz) containing a bunch of XML files. Once again, the format is not very well documented, but it very closely matches the database structure, and is easy to reverse engineer. There are ways to automate restoring a backup too. (http://docs.moodle.org/dev/Restore_2.0_for_developers#Automatically_triggering_restore_in_code).
Of course, since you have something that works already, I am not expecting you to re-write things now. I am just pointing it out as an alternative approach that might be worth considering in future.