LPS-36493 Ensure PortalInstances.getCompanyIdsBySQL inserts proper shard name in SQL query

The if clause must be around the ps.setString() because we must not change the value of currentShardName at that point see https://github.com/JorgeFerrer/liferay-portal/pull/188#issuecomment-19759267 for details