Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ odbc_internal::StatusRecordOr<SQLSMALLINT> GetSQLDataType(
return SQL_VARCHAR;
}
if (type == "INTEGER" || type == "INT64") {
return SQL_BIGINT;
return SQL_INTEGER;
}
if (type == "BOOL" || type == "BOOLEAN") {
return SQL_BIT;
Expand Down
20 changes: 13 additions & 7 deletions google/cloud/odbc/bq_driver/internal/odbc_procedure_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,36 @@ StatusRecordOr<Procedure> ValidateProcedureColumnParameters(
}
}

if (IsSearchPatternArgument(reinterpret_cast<char const*>(catalog_name))) {
if (catalog_name != nullptr && IsSearchPatternArgument(reinterpret_cast<char const*>(catalog_name))) {
LOG(ERROR) << "ValidateProcedureColumnParameters:: Catalog name cannot be "
"a search pattern.";
return StatusRecord{SQLStates::k_HY090(),
"Catalog name cannot be a search pattern"};
}

std::string catalog =
(catalog_name_len == SQL_NTS)
std::string catalog = "";
if (catalog_name != nullptr) {
catalog = (catalog_name_len == SQL_NTS)
? std::string(reinterpret_cast<char const*>(catalog_name))
: std::string(reinterpret_cast<char const*>(catalog_name),
catalog_name_len);
}

std::string dataset =
(schema_name_len == SQL_NTS)
std::string dataset = "";
if (schema_name != nullptr) {
dataset = (schema_name_len == SQL_NTS)
? std::string(reinterpret_cast<char const*>(schema_name))
: std::string(reinterpret_cast<char const*>(schema_name),
schema_name_len);
}

std::string proc_name =
(procedure_name_len == SQL_NTS)
std::string proc_name = "";
if (procedure_name != nullptr) {
proc_name = (procedure_name_len == SQL_NTS)
? std::string(reinterpret_cast<char const*>(procedure_name))
: std::string(reinterpret_cast<char const*>(procedure_name),
procedure_name_len);
}

if (catalog.empty()) {
LOG(ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ odbc_internal::StatusRecord ValidateColumnParameters(
}
// Validate SQLColumns specific parameters.

if (IsSearchPatternArgument(reinterpret_cast<char const*>(catalog_name))) {
if (catalog_name != nullptr && IsSearchPatternArgument(reinterpret_cast<char const*>(catalog_name))) {
LOG(ERROR) << "ValidateColumnParameters:: Catalog name cannot be a search "
"pattern.";
return StatusRecord{SQLStates::k_HY090(),
Expand Down
4 changes: 4 additions & 0 deletions google/cloud/odbc/bq_driver/internal/odbc_sql_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ SQLGetInfoSqlUSmallInt::GetSupportedInfoType(SQLUSMALLINT info_type) {
result.info_val = kTxnCapable;
break;
}
case SQL_ODBC_API_CONFORMANCE: {
result.info_val = kOdbcApiConformance;
break;
}
default: {
return InvalidType(info_type);
}
Expand Down
18 changes: 18 additions & 0 deletions google/cloud/odbc/bq_driver/internal/odbc_sql_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
#include "google/cloud/odbc/internal/status_record_or.h"
#include "google/cloud/odbc/internal/version.h"

// ODBC 2.x info type constant for API conformance level.
// Not defined in ODBC 3.x headers but still queried by applications like
// MS Access. Value 9, returns SQLUSMALLINT.
#ifndef SQL_ODBC_API_CONFORMANCE
#define SQL_ODBC_API_CONFORMANCE 9
#endif

#ifndef SQL_OAC_NONE
#define SQL_OAC_NONE 0
#endif
#ifndef SQL_OAC_LEVEL1
#define SQL_OAC_LEVEL1 1
#endif
#ifndef SQL_OAC_LEVEL2
#define SQL_OAC_LEVEL2 2
#endif

namespace google::cloud::odbc_bq_driver_internal {

// Constants specific to SQLGetInfo Information type
Expand Down Expand Up @@ -61,6 +78,7 @@ constexpr SQLUSMALLINT kMaxTableNameLen = 1024;
constexpr SQLUSMALLINT kNullCollation = SQL_NC_LOW;
constexpr SQLUSMALLINT kQuotedIdentifierCase = SQL_IC_SENSITIVE;
constexpr SQLUSMALLINT kTxnCapable = SQL_TC_DML;
constexpr SQLUSMALLINT kOdbcApiConformance = SQL_OAC_LEVEL2;

// Constants specific to SQLGetInfo Information type
// values for SQLGetInfoSqlUInteger value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ static std::map<SQLUSMALLINT, SQLUSMALLINT> const kSupportedUSmallIntMap = {
{SQL_MAX_TABLE_NAME_LEN, 1024},
{SQL_NULL_COLLATION, 1},
{SQL_QUOTED_IDENTIFIER_CASE, 3},
{SQL_TXN_CAPABLE, 1}};
{SQL_TXN_CAPABLE, 1},
{SQL_ODBC_API_CONFORMANCE, 2}};

static std::map<SQLUSMALLINT, SQLUINTEGER> const kSupportedUIntMap = {
{SQL_ASYNC_MODE, 2},
Expand Down
6 changes: 3 additions & 3 deletions google/cloud/odbc/bq_driver/internal/odbc_sql_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct TypeInfoRow {
TypeInfoRow const kBqInt64TypeInfoRow = {
const_cast<SQLCHAR*>(
reinterpret_cast<const SQLCHAR*>("INT64")), // type_name
SQL_BIGINT, // data_type
SQL_INTEGER, // data_type
19, // col_size
nullptr, // literal_prefix
nullptr, // literal_suffix
Expand All @@ -63,7 +63,7 @@ TypeInfoRow const kBqInt64TypeInfoRow = {
reinterpret_cast<const SQLCHAR*>("INT64")), // local_type_name
0, // minimum_scale
0, // maximum_scale
SQL_BIGINT, // sql_data_type
SQL_INTEGER, // sql_data_type
0, // sql_datetime_sub
10, // num_prec_radix
0, // interval_precision
Expand Down Expand Up @@ -484,7 +484,7 @@ TypeInfoRow const kBqBignumericTypeInfoRow = {
};

std::map<SQLSMALLINT, std::map<std::string, TypeInfoRow>> const
kSqlToBqDataTypes = {{SQL_BIGINT,
kSqlToBqDataTypes = {{SQL_INTEGER,
{
{"INT64", kBqInt64TypeInfoRow},
}},
Expand Down
25 changes: 22 additions & 3 deletions google/cloud/odbc/bq_driver/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,13 @@ SQLRETURN SQL_API SQLGetInfoW(SQLHDBC connectionHandle, SQLUSMALLINT infoType,
}
}
}
if (infoValueStringLen)
*infoValueStringLen = info_val_buffer_len * WireWcharSize();
if (infoValueStringLen) {
if (IsInfoTypeString(infoType)) {
*infoValueStringLen = info_val_buffer_len * WireWcharSize();
} else {
*infoValueStringLen = info_val_buffer_len;
}
}

return rc;
}
Expand Down Expand Up @@ -2708,7 +2713,7 @@ SQLRETURN SQL_API SQLColumnsW(SQLHSTMT statementHandle, SQLWCHAR* catalogName,
return utf8_schema_name.GetCalculatedReturnCode();
}
sqlchar_schema_name = ToSqlChar(utf8_schema_name->data());
if (catalogNameLen && catalogNameLen != SQL_NTS)
if (schemaNameLen && schemaNameLen != SQL_NTS)
schemaNameLen = utf8_schema_name->length();
}

Expand Down Expand Up @@ -3212,6 +3217,9 @@ SQLRETURN SQL_API SQLSpecialColumns(

// Call to common internal function for SQLSpecialColumns and
// SQLSpecialColumnsW in odbc_driver_metadata.h.
rc = ::google::cloud::odbc_bq_driver::SQLSpecialColumnsInternal(
statementHandle, identifierType, catalogName, catalogNameLen, schemaName,
schemaNameLen, tableName, tableNameLen, minRowIdScope, colNullable);

// Call to Trace function exit in odbc_trace.h if tracing is enabled.

Expand Down Expand Up @@ -3271,6 +3279,10 @@ SQLRETURN SQL_API SQLSpecialColumnsW(
}
// Call to common internal function for SQLSpecialColumns and
// SQLSpecialColumnsW in odbc_driver_metadata.h.
rc = ::google::cloud::odbc_bq_driver::SQLSpecialColumnsInternal(
statementHandle, identifierType, sqlchar_category_name, catalogNameLen,
sqlchar_schema_name, schemaNameLen, sqlchar_table_name, tableNameLen,
minRowIdScope, colNullable);
// Handle Unicode conversion of output parameters.

return rc;
Expand Down Expand Up @@ -3311,6 +3323,9 @@ SQLRETURN SQL_API SQLStatistics(SQLHSTMT statementHandle, SQLCHAR* catalogName,

// Call to common internal function for SQLStatistics and SQLStatisticsW
// in odbc_driver_metadata.h.
rc = ::google::cloud::odbc_bq_driver::SQLStatisticsInternal(
statementHandle, catalogName, catalogNameLen, schemaName, schemaNameLen,
tableName, tableNameLen, indexType, reserved);

// Call to Trace function exit in odbc_trace.h if tracing is enabled.

Expand Down Expand Up @@ -3371,6 +3386,10 @@ SQLRETURN SQL_API SQLStatisticsW(

// Call to common internal function for SQLStatistics and SQLStatisticsW
// in odbc_driver_metadata.h.
rc = ::google::cloud::odbc_bq_driver::SQLStatisticsInternal(
statementHandle, sqlchar_category_name, catalogNameLen,
sqlchar_schema_name, schemaNameLen, sqlchar_table_name, tableNameLen,
indexType, reserved);
// Handle Unicode conversion of output parameters.

return rc;
Expand Down
Loading
Loading