How to read values from db in provision script

I need to trigger firmware upgrade to CPE based on the software version that the CPE reports. Download URL is present in db and would like to read the name, url, filesize, version etc from db in provision script, compare the version and trigger the firmware update to CPE accordingly .

Please let me know how to do this.