Partial SQL implementation of placeorder(). Check TODO.txt for details
Solved merge conflicts.