Add support for named parameters in prepared statements
JasonPierce opened this issue · 2 comments
JasonPierce commented
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
- Valid chars for a named parameter include: letters, numbers, underscore
- Named parameters are case sensitive
- Named parameters within the sql must be prefixed with
:
writePreparedStatement
supports named parametersreadPreparedStatement
supports named parameterscreatePreparedStatementParam
accepts a string as it's first parameter (internally placing it in named parameter mode)- An error is not thrown when
createPreparedStatementParam
cannot find a matching named parameter within the statement - An error is thrown when the
params
array (ofwritePreparedStatement
andreadPreparedStatement
) contains named parameters with duplicate names - An error is thrown when the
params
array (ofwritePreparedStatement
andreadPreparedStatement
) contains both anonymous and named parameters - Documentation is updated with named parameter examples
JasonPierce commented
tyschroed commented
Bless your heart!
…On Sun, Oct 22, 2017 at 6:18 PM Jason Pierce ***@***.***> wrote:
@tyschroed <https://github.com/tyschroed> 🎁
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAweVjLGJP_7-VFxHj6A_T918j-CB4Zkks5su-lIgaJpZM4QBBCz>
.