Don't use a temporary table for block positions

This also moves database functions and data structures to db.h