Skip to content

Commit

Permalink
fix: init all record fields (#111)
Browse files Browse the repository at this point in the history
Some of the string record fields have been left 0-ed, which is
problematic when their value is asked for. This commit inits them all to
the empty string, so that the transfer can take place.

(Their value would normally be provided by the data source, but this is
now not available with the current ES/SQL API.)
  • Loading branch information
bpintea authored Feb 11, 2019
1 parent f58ceb3 commit f50959b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions driver/odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,12 @@ SQLRETURN SQL_API SQLFetchScroll(SQLHSTMT StatementHandle,
SQLSMALLINT FetchOrientation, SQLLEN FetchOffset)
{
SQLRETURN ret;
TRACE(_IN, StatementHandle, "phz", StatementHandle,
TRACE3(_IN, StatementHandle, "phz", StatementHandle,
FetchOrientation, FetchOffset);
HND_LOCK(StatementHandle);
ret = EsSQLFetchScroll(StatementHandle, FetchOrientation, FetchOffset);
HND_UNLOCK(StatementHandle);
TRACE(_OUT, StatementHandle, "dphz", ret, StatementHandle,
TRACE4(_OUT, StatementHandle, "dphz", ret, StatementHandle,
FetchOrientation, FetchOffset);
return ret;
}
Expand Down
13 changes: 11 additions & 2 deletions driver/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static SQLRETURN attach_columns(esodbc_stmt_st *stmt, UJObject columns)
MK_WPTR(JSON_ANSWER_COL_NAME),
MK_WPTR(JSON_ANSWER_COL_TYPE)
};
static const wstr_st EMPTY_WSTR = WSTR_INIT("");

ird = stmt->ird;
dbc = stmt->hdr.dbc;
Expand Down Expand Up @@ -180,15 +181,23 @@ static SQLRETURN attach_columns(esodbc_stmt_st *stmt, UJObject columns)
/* "If a base column name does not exist (as in the case of columns
* that are expressions), then this variable contains an empty
* string." */
rec->base_column_name = MK_WSTR("");
rec->base_column_name = EMPTY_WSTR;
/* "If a column does not have a label, the column name is returned. If
* the column is unlabeled and unnamed, an empty string is ret" */
rec->label = rec->name.cnt ? rec->name : MK_WSTR("");
rec->label = rec->name.cnt ? rec->name : EMPTY_WSTR;

assert(rec->name.str && rec->label.str);
rec->unnamed = (rec->name.cnt || rec->label.cnt) ?
SQL_NAMED : SQL_UNNAMED;

/* All rec fields must be init'ed to a valid string in case their value
* is requested (and written with write_wstr()). The values would
* normally be provided by the data source, this is not the case here
* (yet), though. */
rec->base_table_name = EMPTY_WSTR;
rec->catalog_name = EMPTY_WSTR;
rec->schema_name = EMPTY_WSTR;
rec->table_name = EMPTY_WSTR;
#ifndef NDEBUG
//dump_record(rec);
#endif /* NDEBUG */
Expand Down
1 change: 1 addition & 0 deletions driver/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ SQLRETURN write_wstr(SQLHANDLE hnd, SQLWCHAR *dest, wstr_st *src,
LWSTR(src), src->cnt, wide_avail);
RET_HDIAGS(hnd, SQL_STATE_01004);
} else {
assert(src->str);
wcsncpy(dest, src->str, src->cnt + /* 0-term */1);
}
} else {
Expand Down

0 comments on commit f50959b

Please sign in to comment.