switch_mprintf -> sqlite3_mprintf

Also check null before dereferencing and make it readable.