Apply sqlite query fix from master