MDL-35155 database: better sql_substr() impl. for mssql/sqlsrv + unit tests