Johan, why not simply executing your query without the LIMIT keyword? You could step through the whole result set to count the total lines while fetching the actual column values only for the first 1000 lines. This would be faster than executing your query twice.
Greetings, Christian

