Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion bindings/odbc/openads_odbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ SQLRETURN SQL_API SQLGetConnectAttr(SQLHDBC, SQLINTEGER, SQLPOINTER, SQLINTEGER,
if (out) *out = 0;
return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT, SQLINTEGER a, SQLPOINTER, SQLINTEGER) {
SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT, SQLINTEGER, SQLPOINTER, SQLINTEGER) {
return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLGetStmtAttr(SQLHSTMT hstmt, SQLINTEGER a, SQLPOINTER val,
Expand Down Expand Up @@ -601,10 +601,23 @@ SQLRETURN SQL_API SQLDescribeCol(SQLHSTMT hstmt, SQLUSMALLINT col, SQLCHAR* name
return SQL_SUCCESS;
}

// The ODBC header switches the final parameter's type by bitness: SQLLEN* on
// 64-bit, SQLPOINTER on 32-bit (Windows SDK sqlext.h guards this with
// `defined(_WIN64) || defined(SQLCOLATTRIBUTE_SQLLEN)`). The definition must
// match the declaration exactly or MSVC rejects it as an extern "C" overload
// (C2733) on x86. Mirror the SDK guard and alias back to SQLLEN* internally.
#if defined(_WIN64) || defined(SQLCOLATTRIBUTE_SQLLEN)
SQLRETURN SQL_API SQLColAttribute(SQLHSTMT hstmt, SQLUSMALLINT col,
SQLUSMALLINT field, SQLPOINTER charattr,
SQLSMALLINT bufmax, SQLSMALLINT* strlen,
SQLLEN* numattr) {
#else
SQLRETURN SQL_API SQLColAttribute(SQLHSTMT hstmt, SQLUSMALLINT col,
SQLUSMALLINT field, SQLPOINTER charattr,
SQLSMALLINT bufmax, SQLSMALLINT* strlen,
SQLPOINTER numattr_) {
SQLLEN* numattr = reinterpret_cast<SQLLEN*>(numattr_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since SQLPOINTER is defined as void* in the Windows SDK, it is more idiomatic and safer in C++ to use static_cast instead of reinterpret_cast when casting from void* to a typed pointer.

    SQLLEN* numattr = static_cast<SQLLEN*>(numattr_);

#endif
if (!hstmt) return SQL_ERROR;
switch (field) {
case SQL_DESC_NAME:
Expand Down
2 changes: 1 addition & 1 deletion src/abi/ace_exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13613,7 +13613,7 @@ UNSIGNED32 AdsExecuteSQLDirect(ADSHANDLE hStatement, UNSIGNED8* pucSQL,
// Enforce that table name is a simple identifier/filename.
const auto& tname = ci.value().table;
if (tname.empty() || tname[0] == '(' || tname.find("SELECT") != std::string::npos) {
return fail(openads::AE_SYNTAX_ERROR,
return fail(openads::AE_PARSE_ERROR,
"INDEX ON requires a table name, not a SELECT result; "
"use SELECT ... ORDER BY/DISTINCT/LIMIT to materialize first");
}
Expand Down
Loading