Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Binding parameters issues #157

Merged
merged 5 commits into from
Oct 27, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions src/db2ia/dbstmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2609,16 +2609,16 @@ int DbStmt::bindParams(Napi::Env env, Napi::Array *params, std::string &error)
size_t str_length = string.length();
const char *cString = string.c_str();
param[i].valueType = SQL_C_CHAR;

if (param[i].io == SQL_PARAM_INPUT || param[i].io == SQL_PARAM_INPUT_OUTPUT)
{
param[i].buf = strdup(cString);
param[i].ind = str_length;
}
else if (param[i].io == SQL_PARAM_OUTPUT)
{
param[i].buf = (char *)calloc(param[i].paramSize + 1, sizeof(char));
param[i].ind = param[i].paramSize;
// CLI does not honor the buffer size parameter or the output size in the indicator
// Make the buffer size is at least the size of parameter or the size of the string
abmusse marked this conversation as resolved.
Show resolved Hide resolved
param[i].buf = (char *)calloc(std::max(static_cast<size_t>(param[i].paramSize), str_length) + 1, sizeof(char));
// Set the indicator to be SQL_NTS
// this helps in edge cases like empty string where indicator is set 0 (which CLI doesn't like for some reason)
param[i].ind = SQL_NTS;
if (param[i].io != SQL_PARAM_OUTPUT) {
// for SQL_PARAM_INPUT and SQL_PARAM_INPUT_OUTPUT
// copy the string to the buffer
strcpy((char*)param[i].buf, cString);
}
}
else if (bindIndicator == 2)
Expand Down Expand Up @@ -2776,14 +2776,15 @@ int DbStmt::bindParams(Napi::Env env, Napi::Array *params, std::string &error)
std::string string = value.ToString().Utf8Value();
size_t str_length = string.length();
const char *cString = string.c_str();

if (cString[0] == '\0') // Check for JS empty-string.
{
param[i].ind = SQL_NTS;
} else {
param[i].ind = str_length;
}
param[i].buf = strdup(cString);
// CLI does not honor the buffer size parameter or the output size in the indicator
// Make the buffer size is at least the size of parameter or the size of the string
abmusse marked this conversation as resolved.
Show resolved Hide resolved
param[i].buf = (char *)calloc(std::max(static_cast<size_t>(param[i].paramSize), str_length) + 1, sizeof(char));
// set the indicator to be SQL_NTS
// this helps in edge cases like empty string where indicator is set 0 (which CLI doesn't like for some reason)
param[i].ind = SQL_NTS;
// SQL_PARAM_INPUT_OUTPUT is always set so
// copy the string to the buffer
strcpy((char*)param[i].buf, cString);
}
else
{
Expand Down