2Toad/node-teradata

Add support for named parameters in prepared statements

JasonPierce opened this issue · 2 comments

Currently prepared statements use the Teradata syntax of anonymous parameters referenced by index:

var id = 7;
var username = 'Foo';
var sql = 'UPDATE MyDatabase.MyTable SET Username = ? WHERE Id = ?';

return teradata.writePreparedStatement(sql, [
    teradata.createPreparedStatementParam(1, 'String', username),
    teradata.createPreparedStatementParam(2, 'Int', Number(id))
  ]);

This proposed enhancement adds the ability to name parameters (similar to Sequelize's named replacements):

var id = 7;
var username = 'Foo';
var sql = 'UPDATE MyDatabase.MyTable SET Username = :username WHERE Id = :id';

return teradata.writePreparedStatement(sql, [
    teradata.createPreparedStatementParam('username', 'String', username),
    teradata.createPreparedStatementParam('id', 'Int', Number(id))
  ]);

Acceptance Criteria

  1. Valid chars for a named parameter include: letters, numbers, underscore
  2. Named parameters are case sensitive
  3. Named parameters within the sql must be prefixed with :
  4. writePreparedStatement supports named parameters
  5. readPreparedStatement supports named parameters
  6. createPreparedStatementParam accepts a string as it's first parameter (internally placing it in named parameter mode)
  7. An error is not thrown when createPreparedStatementParam cannot find a matching named parameter within the statement
  8. An error is thrown when the params array (of writePreparedStatement and readPreparedStatement) contains named parameters with duplicate names
  9. An error is thrown when the params array (of writePreparedStatement and readPreparedStatement) contains both anonymous and named parameters
  10. Documentation is updated with named parameter examples