Fix null deref in sdb_querys