new attempt, SQL integration the hard, manual way

Poor code i know, but nessacary