Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit a0eec38

Browse files
committed
[[ Bug ]] Fix ODBC parameter binding
This patch fixes ODBC parameter binding by correcting the use of the `StrLen_or_IndPtr` parameter which should point to a buffer containing the length of the parameter value and that is valid when `SQLExecute` is called.
1 parent 31840bd commit a0eec38

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

revdb/src/dbodbc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class DBConnection_ODBC: public CDBConnection
9898
int getConnectionType(void) { return -1; }
9999
protected:
100100
void SetError(SQLHSTMT tcursor);
101-
Bool BindVariables(SQLHSTMT tcursor, DBString *args, int numargs, int *paramsizes, PlaceholderMap *p_placeholder_map);
101+
Bool BindVariables(SQLHSTMT tcursor, DBString *args, int numargs, SQLLEN *paramsizes, PlaceholderMap *p_placeholder_map);
102102
bool ExecuteQuery(char *p_query, DBString *p_arguments, int p_argument_count, SQLHSTMT &p_statement, SQLRETURN &p_result);
103103
bool handleDataAtExecutionParameters(SQLHSTMT p_statement);
104104
bool useDataAtExecution(void);

revdb/src/odbc_connection.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ bool DBConnection_ODBC::ExecuteQuery(char *p_query, DBString *p_arguments, int p
399399
#endif
400400
if (t_result == SQL_SUCCESS || t_result == SQL_SUCCESS_WITH_INFO)
401401
{
402-
int *t_argument_sizes = NULL;
403-
t_argument_sizes = new (nothrow) int[t_placeholder_map . length];
402+
SQLLEN *t_argument_sizes = new (nothrow) SQLLEN[t_placeholder_map . length];
404403
if (BindVariables(t_statement, p_arguments, p_argument_count, t_argument_sizes, &t_placeholder_map))
405404
{
406405
t_result = SQLExecute(t_statement);
@@ -528,7 +527,7 @@ char *DBConnection_ODBC::getErrorMessage(Bool p_last)
528527

529528

530529
/*BindVariables-parses querystring and binds variables*/
531-
Bool DBConnection_ODBC::BindVariables(SQLHSTMT p_cursor, DBString *p_arguments, int p_argument_count, int *p_argument_sizes, PlaceholderMap *p_placeholder_map)
530+
Bool DBConnection_ODBC::BindVariables(SQLHSTMT p_cursor, DBString *p_arguments, int p_argument_count, SQLLEN *p_argument_sizes, PlaceholderMap *p_placeholder_map)
532531
{
533532
if (p_argument_count == 0)
534533
return True;
@@ -564,15 +563,14 @@ Bool DBConnection_ODBC::BindVariables(SQLHSTMT p_cursor, DBString *p_arguments,
564563

565564
// MW-2008-07-30: [[ Bug 6415 ]] Inserting data into SQL Server doesn't work.
566565
// This is because the bind parameter call was only being issued for binary columns!
567-
SQLLEN t_argument_size;
568-
t_result = SQLBindParameter(p_cursor, i + 1, SQL_PARAM_INPUT,
566+
567+
SQLLEN * t_argument_size = &p_argument_sizes[i];
568+
t_result = SQLBindParameter(p_cursor, i + 1, SQL_PARAM_INPUT,
569569
t_value -> isbinary ? SQL_C_BINARY : SQL_C_CHAR, t_data_type,
570-
t_value -> length, 0, (void *)t_value -> sptr, t_value -> length, &t_argument_size);
570+
t_value -> length, 0, (void *)t_value -> sptr, t_value -> length, t_argument_size);
571571

572572
if (!(t_result == SQL_SUCCESS || t_result == SQL_SUCCESS_WITH_INFO))
573573
return False;
574-
575-
p_argument_sizes[i] = t_argument_size;
576574
}
577575
else
578576
{

0 commit comments

Comments
 (0)