The code in https://code.launchpad.net/~james-w/udd/db-resources/+merge/114511 is a good place to pillage for this.
The code in https:/ /code.launchpad .net/~james- w/udd/db- resources/ +merge/ 114511 is a good place to pillage for this.