Periodicity is not the cause of this trouble. If you integrate cos x, then you get sin x which is periodic. However, the substitution still works as usual.
The cause of this trouble is a different constant of integration at different intervals.
Instead of +c for all real numbers, you actually...