bugifx sql code, thanks to @simoneloru