Skip to content

Commit 88e79d7

Browse files
authored
Merge pull request #124 from maiadegraaf/empty_stubs_improvements
Empty Stub Improvements
2 parents 1d23172 + d7eda0b commit 88e79d7

10 files changed

+748
-205
lines changed

duckdb_odbc.def

+1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ SQLAllocHandle
475475
SQLBindCol
476476
SQLBindParameter
477477
SQLBrowseConnect
478+
SQLBrowseConnectW
478479
SQLBulkOperations
479480
SQLCancel
480481
SQLCloseCursor

duckdb_odbc.exp

+1
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ _SQLAllocHandle
472472
_SQLBindCol
473473
_SQLBindParameter
474474
_SQLBrowseConnect
475+
_SQLBrowseConnectW
475476
_SQLBulkOperations
476477
_SQLCancel
477478
_SQLCloseCursor

duckdb_odbc.map

+1
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ DUCKDB_ODBC {
474474
SQLBindCol;
475475
SQLBindParameter;
476476
SQLBrowseConnect;
477+
SQLBrowseConnectW;
477478
SQLBulkOperations;
478479
SQLCancel;
479480
SQLCloseCursor;

include/odbc_utils.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct OdbcUtils {
9292
static SQLUINTEGER SQLPointerToSQLUInteger(SQLPOINTER value);
9393
static std::string ConvertSQLCHARToString(SQLCHAR *str);
9494
static LPCSTR ConvertStringToLPCSTR(const std::string &str);
95+
static SQLCHAR *ConvertStringToSQLCHAR(const std::string &str);
9596
};
9697
} // namespace duckdb
9798
#endif

src/common/odbc_utils.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,14 @@ std::string OdbcUtils::ConvertSQLCHARToString(SQLCHAR *str) {
252252
return std::string(reinterpret_cast<char *>(str));
253253
}
254254

255-
LPCSTR duckdb::OdbcUtils::ConvertStringToLPCSTR(const std::string &str) {
255+
LPCSTR OdbcUtils::ConvertStringToLPCSTR(const std::string &str) {
256256
return reinterpret_cast<LPCSTR>(const_cast<char *>(str.c_str()));
257257
}
258258

259+
SQLCHAR *OdbcUtils::ConvertStringToSQLCHAR(const std::string &str) {
260+
return reinterpret_cast<SQLCHAR *>(const_cast<char *>(str.c_str()));
261+
}
262+
259263
template <typename INT_TYPE>
260264
static void WriteStringInternal(const SQLCHAR *utf8_data, std::size_t utf8_data_len, SQLWCHAR *out_buf, SQLLEN buf_len,
261265
INT_TYPE *out_len) {

src/empty_stubs.cpp

+467-63
Large diffs are not rendered by default.

src/statement/statement.cpp

-91
Original file line numberDiff line numberDiff line change
@@ -577,97 +577,6 @@ SQLRETURN SQL_API SQLColumnsW(SQLHSTMT statement_handle, SQLWCHAR *catalog_name,
577577
column_name_conv.utf8_len_smallint());
578578
}
579579

580-
static SQLRETURN SpecialColumnsInternal(SQLHSTMT statement_handle, SQLUSMALLINT identifier_type, SQLCHAR *catalog_name,
581-
SQLSMALLINT name_length1, SQLCHAR *schema_name, SQLSMALLINT name_length2,
582-
SQLCHAR *table_name, SQLSMALLINT name_length3, SQLUSMALLINT scope,
583-
SQLUSMALLINT nullable) {
584-
std::string query = R"#(
585-
SELECT
586-
CAST(0 AS SMALLINT) AS "SCOPE",
587-
CAST('' AS VARCHAR ) AS "COLUMN_NAME",
588-
CAST(0 AS SMALLINT) AS "DATA_TYPE",
589-
CAST('' AS VARCHAR ) AS "TYPE_NAME",
590-
CAST(0 AS INT ) AS "COLUMN_SIZE",
591-
CAST(0 AS INT ) AS "BUFFER_LENGTH",
592-
CAST(0 AS SMALLINT) AS "DECIMAL_DIGITS",
593-
CAST(0 AS SMALLINT) AS "PSEUDO_COLUMN"
594-
WHERE 1 < 0
595-
)#";
596-
SQLRETURN ret =
597-
duckdb::ExecDirectStmt(statement_handle, (SQLCHAR *)query.c_str(), static_cast<SQLINTEGER>(query.size()));
598-
if (!SQL_SUCCEEDED(ret)) {
599-
return ret;
600-
}
601-
return SQL_SUCCESS;
602-
}
603-
604-
SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT statement_handle, SQLUSMALLINT identifier_type, SQLCHAR *catalog_name,
605-
SQLSMALLINT name_length1, SQLCHAR *schema_name, SQLSMALLINT name_length2,
606-
SQLCHAR *table_name, SQLSMALLINT name_length3, SQLUSMALLINT scope,
607-
SQLUSMALLINT nullable) {
608-
return SpecialColumnsInternal(statement_handle, identifier_type, catalog_name, name_length1, schema_name,
609-
name_length2, table_name, name_length3, scope, nullable);
610-
}
611-
612-
SQLRETURN SQL_API SQLSpecialColumnsW(SQLHSTMT statement_handle, SQLSMALLINT identifier_type, SQLWCHAR *catalog_name,
613-
SQLSMALLINT name_length1, SQLWCHAR *schema_name, SQLSMALLINT name_length2,
614-
SQLWCHAR *table_name, SQLSMALLINT name_length3, SQLSMALLINT scope,
615-
SQLSMALLINT nullable) {
616-
auto catalog_name_conv = duckdb::widechar::utf16_conv(catalog_name, name_length1);
617-
auto schema_name_conv = duckdb::widechar::utf16_conv(schema_name, name_length2);
618-
auto table_name_conv = duckdb::widechar::utf16_conv(table_name, name_length3);
619-
return SpecialColumnsInternal(statement_handle, identifier_type, catalog_name_conv.utf8_str,
620-
catalog_name_conv.utf8_len_smallint(), schema_name_conv.utf8_str,
621-
schema_name_conv.utf8_len_smallint(), table_name_conv.utf8_str,
622-
table_name_conv.utf8_len_smallint(), scope, nullable);
623-
}
624-
625-
static SQLRETURN StatisticsInternal(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
626-
SQLCHAR *schema_name, SQLSMALLINT name_length2, SQLCHAR *table_name,
627-
SQLSMALLINT name_length3, SQLUSMALLINT unique, SQLUSMALLINT reserved) {
628-
std::string query = R"#(
629-
SELECT
630-
CAST('' AS VARCHAR ) AS "TABLE_CAT",
631-
CAST('' AS VARCHAR ) AS "TABLE_SCHEM",
632-
CAST('' AS VARCHAR ) AS "TABLE_NAME",
633-
CAST(0 AS SMALLINT) AS "NON_UNIQUE",
634-
CAST('' AS VARCHAR ) AS "INDEX_QUALIFIER",
635-
CAST('' AS VARCHAR ) AS "INDEX_NAME",
636-
CAST(0 AS SMALLINT) AS "TYPE",
637-
CAST(0 AS SMALLINT) AS "ORDINAL_POSITION",
638-
CAST('' AS VARCHAR ) AS "COLUMN_NAME",
639-
CAST('' AS CHAR(1) ) AS "ASC_OR_DESC",
640-
CAST(0 AS INT ) AS "CARDINALITY",
641-
CAST(0 AS INT ) AS "PAGES",
642-
CAST('' AS VARCHAR ) AS "FILTER_CONDITION"
643-
WHERE 1 < 0
644-
)#";
645-
SQLRETURN ret =
646-
duckdb::ExecDirectStmt(statement_handle, (SQLCHAR *)query.c_str(), static_cast<SQLINTEGER>(query.size()));
647-
if (!SQL_SUCCEEDED(ret)) {
648-
return ret;
649-
}
650-
return SQL_SUCCESS;
651-
}
652-
653-
SQLRETURN SQL_API SQLStatistics(SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1,
654-
SQLCHAR *schema_name, SQLSMALLINT name_length2, SQLCHAR *table_name,
655-
SQLSMALLINT name_length3, SQLUSMALLINT unique, SQLUSMALLINT reserved) {
656-
return StatisticsInternal(statement_handle, catalog_name, name_length1, schema_name, name_length2, table_name,
657-
name_length3, unique, reserved);
658-
}
659-
660-
SQLRETURN SQL_API SQLStatisticsW(SQLHSTMT statement_handle, SQLWCHAR *catalog_name, SQLSMALLINT name_length1,
661-
SQLWCHAR *schema_name, SQLSMALLINT name_length2, SQLWCHAR *table_name,
662-
SQLSMALLINT name_length3, SQLUSMALLINT unique, SQLUSMALLINT reserved) {
663-
auto catalog_name_conv = duckdb::widechar::utf16_conv(catalog_name, name_length1);
664-
auto schema_name_conv = duckdb::widechar::utf16_conv(schema_name, name_length2);
665-
auto table_name_conv = duckdb::widechar::utf16_conv(table_name, name_length3);
666-
return StatisticsInternal(statement_handle, catalog_name_conv.utf8_str, catalog_name_conv.utf8_len_smallint(),
667-
schema_name_conv.utf8_str, schema_name_conv.utf8_len_smallint(), table_name_conv.utf8_str,
668-
table_name_conv.utf8_len_smallint(), unique, reserved);
669-
}
670-
671580
template <typename T>
672581
static SQLRETURN SetNumericAttributePtr(duckdb::OdbcHandleStmt *hstmt, const T &val, SQLLEN *numeric_attribute_ptr) {
673582
if (numeric_attribute_ptr) {

test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ add_executable(
2626
tests/multicolumn_param_bind.cpp
2727
tests/numeric.cpp
2828
tests/quotes.cpp
29+
tests/test_empty_stubs.cpp
2930
tests/result_conversion.cpp
3031
tests/test_allowed_paths.cpp
31-
tests/test_stubs.cpp
3232
tests/test_timestamp.cpp
3333
tests/test_widechar_conv.cpp
3434
tests/test_widechar_data.cpp

0 commit comments

Comments
 (0)