Minor: fixed small bugs on SQL engine