Skip to content

Commit af58ece

Browse files
committed
Add SQLBrowseConnectW and refactor SQLBrowseConnect logic
Minor type casting and consistency updates.
1 parent abc637f commit af58ece

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

src/empty_stubs.cpp

+47-20
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ WHERE 1 < 0
3333
return ret;
3434
}
3535

36-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
36+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
37+
static_cast<SQLINTEGER>(query.size()));
3738
}
3839

3940
SQLRETURN SQL_API SQLPrimaryKeys(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
@@ -87,7 +88,8 @@ WHERE 1 < 0
8788
return ret;
8889
}
8990

90-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
91+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
92+
static_cast<SQLINTEGER>(query.size()));
9193
}
9294

9395
SQLRETURN SQL_API SQLForeignKeys(SQLHSTMT statement_handle, SQLCHAR *pk_catalog_name, SQLSMALLINT name_length1,
@@ -155,7 +157,8 @@ WHERE 1 < 0
155157
return ret;
156158
}
157159

158-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
160+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
161+
static_cast<SQLINTEGER>(query.size()));
159162
}
160163

161164
SQLRETURN SQL_API SQLProcedureColumns(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
@@ -171,7 +174,7 @@ SQLRETURN SQL_API SQLProcedureColumnsW(SQLHSTMT statement_handle, SQLWCHAR *cata
171174
auto catalog_name_conv = duckdb::widechar::utf16_conv(catalog_name, name_length1);
172175
auto schema_name_conv = duckdb::widechar::utf16_conv(schema_name, name_length2);
173176
auto proc_name_conv = duckdb::widechar::utf16_conv(proc_name, name_length3);
174-
auto column_name_conv = duckdb::widechar::utf16_conv(column_name, name_length3);
177+
auto column_name_conv = duckdb::widechar::utf16_conv(column_name, name_length4);
175178
return ProcedureColumnsInternal(statement_handle, catalog_name_conv.utf8_str, catalog_name_conv.utf8_len_smallint(),
176179
schema_name_conv.utf8_str, schema_name_conv.utf8_len_smallint(),
177180
proc_name_conv.utf8_str, proc_name_conv.utf8_len_smallint(),
@@ -203,7 +206,8 @@ WHERE 1 < 0
203206
return ret;
204207
}
205208

206-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
209+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
210+
static_cast<SQLINTEGER>(query.size()));
207211
}
208212

209213
SQLRETURN SQL_API SQLProcedures(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
@@ -216,11 +220,12 @@ SQLRETURN SQL_API SQLProcedures(SQLHSTMT statement_handle, SQLCHAR *catalog_name
216220
SQLRETURN SQL_API SQLProceduresW(SQLHSTMT statement_handle, SQLWCHAR *catalog_name, SQLSMALLINT name_length1,
217221
SQLWCHAR *schema_name, SQLSMALLINT name_length2, SQLWCHAR *proc_name,
218222
SQLSMALLINT name_length3) {
219-
const auto catalog_name_conv = duckdb::widechar::utf16_conv(catalog_name, name_length1);
220-
const auto schema_name_conv = duckdb::widechar::utf16_conv(schema_name, name_length2);
221-
const auto proc_name_conv = duckdb::widechar::utf16_conv(proc_name, name_length3);
222-
return ProceduresInternal(statement_handle, catalog_name_conv.utf8_str, name_length1, schema_name_conv.utf8_str,
223-
name_length2, proc_name_conv.utf8_str, name_length3);
223+
auto catalog_name_conv = duckdb::widechar::utf16_conv(catalog_name, name_length1);
224+
auto schema_name_conv = duckdb::widechar::utf16_conv(schema_name, name_length2);
225+
auto proc_name_conv = duckdb::widechar::utf16_conv(proc_name, name_length3);
226+
return ProceduresInternal(statement_handle, catalog_name_conv.utf8_str, catalog_name_conv.utf8_len_smallint(),
227+
schema_name_conv.utf8_str, schema_name_conv.utf8_len_smallint(), proc_name_conv.utf8_str,
228+
proc_name_conv.utf8_len_smallint());
224229
}
225230

226231
// -----------------------------------------------------------------------------
@@ -248,7 +253,8 @@ WHERE 1 < 0
248253
return ret;
249254
}
250255

251-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
256+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
257+
static_cast<SQLINTEGER>(query.size()));
252258
}
253259

254260
SQLRETURN SQL_API SQLColumnPrivileges(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
@@ -295,7 +301,8 @@ WHERE 1 < 0
295301
return ret;
296302
}
297303

298-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
304+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
305+
static_cast<SQLINTEGER>(query.size()));
299306
}
300307

301308
SQLRETURN SQL_API SQLTablePrivileges(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
@@ -342,7 +349,8 @@ WHERE 1 < 0
342349
return ret;
343350
}
344351

345-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
352+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
353+
static_cast<SQLINTEGER>(query.size()));
346354
}
347355

348356
SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT statement_handle, SQLUSMALLINT identifier_type, SQLCHAR *catalog_name,
@@ -396,7 +404,8 @@ WHERE 1 < 0
396404
return ret;
397405
}
398406

399-
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query), query.size());
407+
return duckdb::ExecDirectStmt(stmt, duckdb::OdbcUtils::ConvertStringToSQLCHAR(query),
408+
static_cast<SQLINTEGER>(query.size()));
400409
}
401410

402411
SQLRETURN SQL_API SQLStatistics(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
@@ -421,7 +430,7 @@ SQLRETURN SQL_API SQLStatisticsW(SQLHSTMT statement_handle, SQLWCHAR *catalog_na
421430
// Functions explicitly marked as not implemented (SetNotImplemented)
422431
// ============================================================================
423432

424-
SQLRETURN SetNotImplemented(duckdb::OdbcHandle *handle, const std::string &func_name) {
433+
static SQLRETURN SetNotImplemented(duckdb::OdbcHandle *handle, const std::string &func_name) {
425434
return SetDiagnosticRecord(handle, SQL_ERROR, func_name, func_name + " is not implemented",
426435
duckdb::SQLStateType::ST_HYC00, "");
427436
}
@@ -452,17 +461,18 @@ SQLRETURN SQL_API SQLNativeSqlW(SQLHDBC connection_handle, SQLWCHAR *in_statemen
452461
SQLWCHAR *out_statement_text, SQLINTEGER buffer_length, SQLINTEGER *text_length2_ptr) {
453462
auto in_statement_text_conv = duckdb::widechar::utf16_conv(in_statement_text, text_length1);
454463
auto out_statement_text_conv = duckdb::widechar::utf16_conv(out_statement_text, buffer_length);
455-
return NativeSQLInternal(connection_handle, in_statement_text_conv.utf8_str, in_statement_text_conv.utf8_len(),
456-
out_statement_text_conv.utf8_str, buffer_length, text_length2_ptr);
464+
return NativeSQLInternal(connection_handle, in_statement_text_conv.utf8_str,
465+
in_statement_text_conv.utf8_len_smallint(), out_statement_text_conv.utf8_str,
466+
out_statement_text_conv.utf8_len_smallint(), text_length2_ptr);
457467
}
458468

459469
// --------------------------------------------------------------
460470
// SQLBrowseConnect
461471
// --------------------------------------------------------------
462472

463-
SQLRETURN SQL_API SQLBrowseConnect(SQLHDBC connection_handle, SQLCHAR *in_connection_string, SQLSMALLINT string_length1,
464-
SQLCHAR *out_connection_string, SQLSMALLINT buffer_length,
465-
SQLSMALLINT *string_length2_ptr) {
473+
static SQLRETURN BrowseConnectInternal(SQLHDBC connection_handle, SQLCHAR *in_connection_string,
474+
SQLSMALLINT string_length1, SQLCHAR *out_connection_string,
475+
SQLSMALLINT buffer_length, SQLSMALLINT *string_length2_ptr) {
466476
duckdb::OdbcHandle *hdl;
467477
const auto ret = ConvertHandle(connection_handle, hdl);
468478
if (ret != SQL_SUCCESS) {
@@ -472,6 +482,23 @@ SQLRETURN SQL_API SQLBrowseConnect(SQLHDBC connection_handle, SQLCHAR *in_connec
472482
return SetNotImplemented(hdl, "SQLBrowseConnect");
473483
}
474484

485+
SQLRETURN SQL_API SQLBrowseConnect(SQLHDBC connection_handle, SQLCHAR *in_connection_string, SQLSMALLINT string_length1,
486+
SQLCHAR *out_connection_string, SQLSMALLINT buffer_length,
487+
SQLSMALLINT *string_length2_ptr) {
488+
return BrowseConnectInternal(connection_handle, in_connection_string, string_length1, out_connection_string,
489+
buffer_length, string_length2_ptr);
490+
}
491+
492+
SQLRETURN SQL_API SQLBrowseConnectW(SQLHDBC connection_handle, SQLWCHAR *in_connection_string,
493+
SQLSMALLINT string_length1, SQLWCHAR *out_connection_string,
494+
SQLSMALLINT buffer_length, SQLSMALLINT *string_length2_ptr) {
495+
auto in_connection_string_conv = duckdb::widechar::utf16_conv(in_connection_string, string_length1);
496+
auto out_connection_string_conv = duckdb::widechar::utf16_conv(out_connection_string, buffer_length);
497+
return BrowseConnectInternal(connection_handle, in_connection_string_conv.utf8_str,
498+
in_connection_string_conv.utf8_len_smallint(), out_connection_string_conv.utf8_str,
499+
out_connection_string_conv.utf8_len_smallint(), string_length2_ptr);
500+
}
501+
475502
// --------------------------------------------------------------
476503
// SQLBulkOperations
477504
// --------------------------------------------------------------

test/tests/test_empty_stubs.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ TEST_CASE("Test Empty Stubs -- Should return error", "[odbc]") {
234234
CheckForErrorAndDiagnosticRecord(ret, dbc, SQL_HANDLE_DBC);
235235
}
236236

237+
{
238+
// SQLBrowseConnectW
239+
const std::string connect_str = "DRIVER={Dummy};";
240+
SQLWCHAR output_conn[256];
241+
SQLSMALLINT output_len = 0;
242+
243+
const auto ret = SQLBrowseConnectW(dbc, ConvertToSQLWCHARNTS(connect_str).data(),
244+
static_cast<SQLSMALLINT>(connect_str.size()), output_conn,
245+
sizeof(output_conn) / sizeof(SQLWCHAR), &output_len);
246+
CheckForErrorAndDiagnosticRecord(ret, dbc, SQL_HANDLE_DBC);
247+
}
248+
237249
// Allocate a statement handle
238250
EXECUTE_AND_CHECK("SQLAllocHandle (HSTMT)", hstmt, SQLAllocHandle, SQL_HANDLE_STMT, dbc, &hstmt);
239251

0 commit comments

Comments
 (0)