sql: improve single-row detection (fix #47)