switch_mprintf -> sqlite3_mprintf; add missing memory alloc checks; use correct *free() calls, don't be shit