General solution of scalar field cosmology with a (piecewise) exponential potential