Added build query database insert functionality