Consolidate SQL function sanity checking code