Make db.scalar able to handle SQL with params
Convert the remaining uses of scalar over to db.scalar
Small style fix