I'm going to travel to Iran from Germany. Since I've booked connected flights (Germany- Turkey, Turkey- Iran), do I need a visa for Turkey as well as Iran?

This is my flights schedule: 

> - Basel-Mulhouse-Freiburg (check-in Swiss sector) to Istanbul - Sabiha
> Gökçen
> 
>  Dep 19 May 2012 22:30
> 
>  Arr 20 May 2012 02:25
> 
> - Istanbul - S.Gokcen(SAW)Tehran - IKA(IKA)
> 
>  Departure: IST (SAW) 20.05.2012  23:05
> 
>  Arrival:THR (IKA) 21.05.2012 03:25

So if I need a visa planning to leave the airport for a few hours to Istanbul till the next flight, I would stay at the airport. 

Note: I have German nationality.