Calculating indices of named parameters, creating sql for prepared statement