Fix SQL out of range error for frequent API attempts