Skip to content

Commit 9a1a432

Browse files
committed
tests: get server major from rdb$get_context, not SQL_DBMS_VER
`GetServerMajorVersion` was atoi-ing `SQLGetInfo(SQL_DBMS_VER)`, but the driver does not put the Firebird product version in that field — it constructs it from the implementation / protocol version bytes of `isc_info_version` (`IscDbc/Attachment.cpp:480`) and currently returns e.g. `"06.03.1683 WI-V Firebird 5.0"` on Firebird 5.0.3. `atoi("06...")` is 6 on every supported server, so `SKIP_ON_FIREBIRD6()` fires on FB 3 / 4 / 5 too and every guarded test silently `[ SKIPPED ]`s across the whole matrix. Ask the server directly via `SELECT RDB$GET_CONTEXT('SYSTEM', 'ENGINE_VERSION') FROM RDB$DATABASE`, which returns a straight "5.0.3" / "6.0.0.xxxx" / "3.0.12" string. Local FB 5.0.3 run: 224 passing tests (was 200) — 24 tests that had been silently skipped (the pre-existing `Char*` parameter-conversion cases plus the Issue #161 coverage added in this branch) are now actually exercised. Local FB 6.0 master still skips them all (correct).
1 parent 220eb3c commit 9a1a432

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

tests/test_helpers.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,34 @@ class TempTable {
223223
std::string name_;
224224
};
225225

226-
// Returns the Firebird server major version number (e.g. 5 for Firebird 5.x, 6 for 6.x)
227-
// via SQL_DBMS_VER which returns strings like "05.00.0001683" or "06.00.0001884".
226+
// Returns the Firebird server major version number (e.g. 5 for Firebird 5.x, 6 for 6.x).
227+
//
228+
// The Firebird ODBC driver's SQL_DBMS_VER string is NOT the Firebird product
229+
// version — it is constructed from the implementation / protocol version
230+
// fields of `isc_info_version` (see IscDbc/Attachment.cpp:480) and currently
231+
// reads e.g. "06.03.1683 WI-V Firebird 5.0" on Firebird 5.0.3. atoi-ing that
232+
// to get the major returns 6 for every supported server, so anything gated on
233+
// `>= 6` (notably SKIP_ON_FIREBIRD6) silently fires on FB 3 / 4 / 5 too and
234+
// the test is effectively disabled.
235+
//
236+
// Ask the server directly instead — `rdb$get_context('SYSTEM', 'ENGINE_VERSION')`
237+
// returns a straight "5.0.3" / "6.0.0.xxxx" / "3.0.12" string, trivial to parse.
228238
inline int GetServerMajorVersion(SQLHDBC hDbc) {
229-
SQLCHAR version[32] = {};
230-
SQLSMALLINT len = 0;
231-
SQLGetInfo(hDbc, SQL_DBMS_VER, version, sizeof(version), &len);
239+
SQLHSTMT hStmt = SQL_NULL_HSTMT;
240+
if (!SQL_SUCCEEDED(SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt))) return 0;
241+
242+
SQLRETURN ret = SQLExecDirect(hStmt,
243+
(SQLCHAR*)"SELECT RDB$GET_CONTEXT('SYSTEM', 'ENGINE_VERSION') FROM RDB$DATABASE",
244+
SQL_NTS);
245+
if (!SQL_SUCCEEDED(ret) || !SQL_SUCCEEDED(SQLFetch(hStmt))) {
246+
SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
247+
return 0;
248+
}
249+
250+
SQLCHAR version[64] = {};
251+
SQLLEN ind = 0;
252+
SQLGetData(hStmt, 1, SQL_C_CHAR, version, sizeof(version), &ind);
253+
SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
232254
return std::atoi((char*)version);
233255
}
234256

0 commit comments

Comments
 (0)