sqlite compatibility

Add the functions used here that sqlite lacks, so this also works for the sqlite3 engine. It works quite quickly for me.