A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...