Code the primary key ordering so it works with sqlite before version 3.7.16