added flag to query database with sql