Skip to content

Commit f55aee2

Browse files
committed
Merge branch 'master' of github.com:markdirish/node-odbc
2 parents a147b48 + ea58bba commit f55aee2

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

src/odbc_connection.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,16 +1271,30 @@ class CallProcedureAsyncWorker : public ODBCAsyncWorker {
12711271

12721272
SQLRETURN return_code;
12731273

1274-
char *combinedProcedureName = new char[255]();
1275-
if (data->catalog != NULL) {
1276-
strcat(combinedProcedureName, (const char*)data->catalog);
1277-
strcat(combinedProcedureName, ".");
1278-
}
1279-
if (data->schema != NULL) {
1280-
strcat(combinedProcedureName, (const char*)data->schema);
1281-
strcat(combinedProcedureName, ".");
1282-
}
1283-
strcat(combinedProcedureName, (const char*)data->procedure);
1274+
#ifndef UNICODE
1275+
char *combinedProcedureName = new char[1024]();
1276+
sprintf (
1277+
combinedProcedureName,
1278+
"%s%s%s%s%s",
1279+
data->catalog ? (const char*)data->catalog : "",
1280+
data->catalog ? "." : "",
1281+
data->schema ? (const char*)data->schema : "",
1282+
data->schema ? "." : "",
1283+
data->procedure
1284+
);
1285+
#else
1286+
wchar_t *combinedProcedureName = new wchar_t[1024]();
1287+
swprintf (
1288+
combinedProcedureName,
1289+
1024,
1290+
L"%s%s%s%s%s",
1291+
data->catalog ? data->catalog : L"",
1292+
data->catalog ? L"." : L"",
1293+
data->schema ? data->schema : L"",
1294+
data->schema ? L"." : L"",
1295+
data->procedure
1296+
);
1297+
#endif
12841298

12851299
// allocate a new statement handle
12861300
uv_mutex_lock(&ODBC::g_odbcMutex);
@@ -1345,7 +1359,11 @@ class CallProcedureAsyncWorker : public ODBCAsyncWorker {
13451359

13461360
if (data->storedRows.size() == 0) {
13471361
char errorString[255];
1362+
#ifndef UNICODE
13481363
sprintf(errorString, "[odbc] CallProcedureAsyncWorker::Execute: Stored procedure '%s' doesn't exist", combinedProcedureName);
1364+
#else
1365+
sprintf(errorString, "[odbc] CallProcedureAsyncWorker::Execute: Stored procedure '%S' doesn't exist", combinedProcedureName);
1366+
#endif
13491367
SetError(errorString);
13501368
return;
13511369
}
@@ -1826,7 +1844,8 @@ class CallProcedureAsyncWorker : public ODBCAsyncWorker {
18261844

18271845
// create the statement to call the stored procedure using the ODBC Call escape sequence:
18281846
// need to create the string "?,?,?,?" where the number of '?' is the number of parameters;
1829-
char *parameterString = new char[255];
1847+
size_t parameterStringSize = (data->parameterCount * 2);
1848+
char *parameterString = new char[parameterStringSize];
18301849
parameterString[0] = '\0';
18311850

18321851
for (int i = 0; i < data->parameterCount; i++) {
@@ -1839,14 +1858,16 @@ class CallProcedureAsyncWorker : public ODBCAsyncWorker {
18391858

18401859
data->deleteColumns(); // delete data in columns for next result set
18411860

1842-
data->sql = new SQLTCHAR[255];
1861+
// 13 non-template characters in { CALL %s (%s) }\0
1862+
size_t sqlStringSize = 1024 + parameterStringSize + sizeof("{ CALL () }");
1863+
data->sql = new SQLTCHAR[sqlStringSize];
18431864
#ifndef UNICODE
18441865
sprintf((char *)data->sql, "{ CALL %s (%s) }", combinedProcedureName, parameterString);
18451866
#else
18461867
// Note: On Windows, %s and %S change their behavior depending on whether
18471868
// it's passed to a printf function or a wprintf function. Since we're passing
1848-
// narrow strings to a wide function, we need to use %S.
1849-
swprintf(data->sql, 255, L"{ CALL %S (%S) }", combinedProcedureName, parameterString);
1869+
// narrow strings to a wide function in the case of parameters, we need to use %S.
1870+
swprintf(data->sql, sqlStringSize, L"{ CALL %s (%S) }", combinedProcedureName, parameterString);
18501871
#endif
18511872

18521873
delete[] combinedProcedureName;

0 commit comments

Comments
 (0)