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
64 changes: 31 additions & 33 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,53 +150,53 @@ SQLRETURN SQL_API SQLPrepare(SQLHSTMT stmt, SQLWCHAR* queryText, SQLINTEGER text

SQLRETURN SQL_API SQLExecute(SQLHSTMT stmt) { return arrow::SQLExecute(stmt); }

SQLRETURN SQL_API SQLBindCol(SQLHSTMT statementHandle, SQLUSMALLINT columnNumber,
SQLRETURN SQL_API SQLBindCol(SQLHSTMT stmt, SQLUSMALLINT columnNumber,
SQLSMALLINT targetType, SQLPOINTER targetValuePtr,
SQLLEN bufferLength, SQLLEN* strLen_or_IndPtr) {
LOG_DEBUG(
"SQLBindCol called with statementHandle: {}, columnNumber: {}, targetType: {}, "
"SQLBindCol called with stmt: {}, columnNumber: {}, targetType: {}, "
"targetValuePtr: {}, bufferLength: {}, strLen_or_IndPtr: {}",
statementHandle, columnNumber, targetType, targetValuePtr, bufferLength,
stmt, columnNumber, targetType, targetValuePtr, bufferLength,
fmt::ptr(strLen_or_IndPtr));
return SQL_ERROR;
}

SQLRETURN SQL_API SQLCancel(SQLHSTMT statementHandle) {
LOG_DEBUG("SQLCancel called with statementHandle: {}", statementHandle);
SQLRETURN SQL_API SQLCancel(SQLHSTMT stmt) {
LOG_DEBUG("SQLCancel called with stmt: {}", stmt);
return SQL_ERROR;
}

SQLRETURN SQL_API SQLCloseCursor(SQLHSTMT statementHandle) {
LOG_DEBUG("SQLCloseCursor called with statementHandle: {}", statementHandle);
SQLRETURN SQL_API SQLCloseCursor(SQLHSTMT stmt) {
LOG_DEBUG("SQLCloseCursor called with stmt: {}", stmt);
return SQL_ERROR;
}

SQLRETURN SQL_API SQLColAttribute(SQLHSTMT statementHandle, SQLUSMALLINT columnNumber,
SQLRETURN SQL_API SQLColAttribute(SQLHSTMT stmt, SQLUSMALLINT columnNumber,
SQLUSMALLINT fieldIdentifier,
SQLPOINTER characterAttributePtr,
SQLSMALLINT bufferLength, SQLSMALLINT* stringLengthPtr,
SQLLEN* numericAttributePtr) {
LOG_DEBUG(
"SQLColAttributeW called with statementHandle: {}, columnNumber: {}, "
"SQLColAttributeW called with stmt: {}, columnNumber: {}, "
"fieldIdentifier: {}, characterAttributePtr: {}, bufferLength: {}, "
"stringLengthPtr: {}, numericAttributePtr: {}",
statementHandle, columnNumber, fieldIdentifier, characterAttributePtr, bufferLength,
stmt, columnNumber, fieldIdentifier, characterAttributePtr, bufferLength,
fmt::ptr(stringLengthPtr), fmt::ptr(numericAttributePtr));
return SQL_ERROR;
}

SQLRETURN SQL_API SQLColumns(SQLHSTMT statementHandle, SQLWCHAR* catalogName,
SQLRETURN SQL_API SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT catalogNameLength, SQLWCHAR* schemaName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
SQLSMALLINT tableNameLength, SQLWCHAR* columnName,
SQLSMALLINT columnNameLength) {
LOG_DEBUG(
"SQLColumnsW called with statementHandle: {}, catalogName: {}, catalogNameLength: "
"SQLColumnsW called with stmt: {}, catalogName: {}, catalogNameLength: "
"{}, "
"schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}, "
"columnName: {}, "
"columnNameLength: {}",
statementHandle, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength, fmt::ptr(columnName),
columnNameLength);
return SQL_ERROR;
Expand All @@ -214,32 +214,30 @@ SQLRETURN SQL_API SQLError(SQLHENV handleType, SQLHDBC handle, SQLHSTMT hstmt,
return SQL_ERROR;
}

SQLRETURN SQL_API SQLForeignKeys(SQLHSTMT statementHandle, SQLWCHAR* pKCatalogName,
SQLRETURN SQL_API SQLForeignKeys(SQLHSTMT stmt, SQLWCHAR* pKCatalogName,
SQLSMALLINT pKCatalogNameLength, SQLWCHAR* pKSchemaName,
SQLSMALLINT pKSchemaNameLength, SQLWCHAR* pKTableName,
SQLSMALLINT pKTableNameLength, SQLWCHAR* fKCatalogName,
SQLSMALLINT fKCatalogNameLength, SQLWCHAR* fKSchemaName,
SQLSMALLINT fKSchemaNameLength, SQLWCHAR* fKTableName,
SQLSMALLINT fKTableNameLength) {
LOG_DEBUG(
"SQLForeignKeysW called with statementHandle: {}, pKCatalogName: {}, "
"SQLForeignKeysW called with stmt: {}, pKCatalogName: {}, "
"pKCatalogNameLength: "
"{}, pKSchemaName: {}, pKSchemaNameLength: {}, pKTableName: {}, pKTableNameLength: "
"{}, "
"fKCatalogName: {}, fKCatalogNameLength: {}, fKSchemaName: {}, fKSchemaNameLength: "
"{}, "
"fKTableName: {}, fKTableNameLength : {}",
statementHandle, fmt::ptr(pKCatalogName), pKCatalogNameLength,
fmt::ptr(pKSchemaName), pKSchemaNameLength, fmt::ptr(pKTableName),
pKTableNameLength, fmt::ptr(fKCatalogName), fKCatalogNameLength,
fmt::ptr(fKSchemaName), fKSchemaNameLength, fmt::ptr(fKTableName),
fKTableNameLength);
stmt, fmt::ptr(pKCatalogName), pKCatalogNameLength, fmt::ptr(pKSchemaName),
pKSchemaNameLength, fmt::ptr(pKTableName), pKTableNameLength,
fmt::ptr(fKCatalogName), fKCatalogNameLength, fmt::ptr(fKSchemaName),
fKSchemaNameLength, fmt::ptr(fKTableName), fKTableNameLength);
return SQL_ERROR;
}

SQLRETURN SQL_API SQLGetTypeInfo(SQLHSTMT statementHandle, SQLSMALLINT dataType) {
LOG_DEBUG("SQLGetTypeInfoW called with statementHandle: {} dataType: {}",
statementHandle, dataType);
SQLRETURN SQL_API SQLGetTypeInfo(SQLHSTMT stmt, SQLSMALLINT dataType) {
LOG_DEBUG("SQLGetTypeInfoW called with stmt: {} dataType: {}", stmt, dataType);
return SQL_ERROR;
}

Expand All @@ -266,40 +264,40 @@ SQLRETURN SQL_API SQLRowCount(SQLHSTMT stmt, SQLLEN* rowCountPtr) {
return arrow::SQLRowCount(stmt, rowCountPtr);
}

SQLRETURN SQL_API SQLPrimaryKeys(SQLHSTMT statementHandle, SQLWCHAR* catalogName,
SQLRETURN SQL_API SQLPrimaryKeys(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT catalogNameLength, SQLWCHAR* schemaName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
SQLSMALLINT tableNameLength) {
LOG_DEBUG(
"SQLPrimaryKeysW called with statementHandle: {}, catalogName: {}, "
"SQLPrimaryKeysW called with stmt: {}, catalogName: {}, "
"catalogNameLength: "
"{}, schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}",
statementHandle, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength);
return SQL_ERROR;
}

SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT statementHandle, SQLINTEGER attribute,
SQLPOINTER valuePtr, SQLINTEGER stringLength) {
SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT stmt, SQLINTEGER attribute, SQLPOINTER valuePtr,
SQLINTEGER stringLength) {
LOG_DEBUG(
"SQLSetStmtAttrW called with statementHandle: {}, attribute: {}, valuePtr: {}, "
"SQLSetStmtAttrW called with stmt: {}, attribute: {}, valuePtr: {}, "
"stringLength: {}",
statementHandle, attribute, valuePtr, stringLength);
stmt, attribute, valuePtr, stringLength);
return SQL_ERROR;
}

SQLRETURN SQL_API SQLTables(SQLHSTMT statementHandle, SQLWCHAR* catalogName,
SQLRETURN SQL_API SQLTables(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT catalogNameLength, SQLWCHAR* schemaName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
SQLSMALLINT tableNameLength, SQLWCHAR* tableType,
SQLSMALLINT tableTypeLength) {
LOG_DEBUG(
"SQLTablesW called with statementHandle: {}, catalogName: {}, catalogNameLength: "
"SQLTablesW called with stmt: {}, catalogName: {}, catalogNameLength: "
"{}, "
"schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}, "
"tableType: {}, "
"tableTypeLength: {}",
statementHandle, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength, fmt::ptr(tableType),
tableTypeLength);
return SQL_ERROR;
Expand Down
89 changes: 47 additions & 42 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,18 @@ SQLRETURN SQLGetDiagField(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT
SQLSMALLINT bufferLength, SQLSMALLINT* stringLengthPtr) {
// TODO: Implement additional fields types
// https://github.com/apache/arrow/issues/46573
using driver::odbcabstraction::Diagnostics;
using ODBC::GetStringAttribute;
using ODBC::ODBCConnection;
using ODBC::ODBCEnvironment;
using ODBC::ODBCStatement;

LOG_DEBUG(
"SQLGetDiagFieldW called with handleType: {}, handle: {}, recNumber: {}, "
"diagIdentifier: {}, diagInfoPtr: {}, bufferLength: {}, stringLengthPtr: {}",
handleType, handle, recNumber, diagIdentifier, diagInfoPtr, bufferLength,
fmt::ptr(stringLengthPtr));

using driver::odbcabstraction::Diagnostics;
using ODBC::GetStringAttribute;
using ODBC::ODBCConnection;
using ODBC::ODBCEnvironment;
using ODBC::ODBCStatement;

if (!handle) {
return SQL_INVALID_HANDLE;
}
Expand Down Expand Up @@ -482,19 +482,19 @@ SQLRETURN SQLGetDiagRec(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT re
SQLWCHAR* sqlState, SQLINTEGER* nativeErrorPtr,
SQLWCHAR* messageText, SQLSMALLINT bufferLength,
SQLSMALLINT* textLengthPtr) {
using driver::odbcabstraction::Diagnostics;
using ODBC::GetStringAttribute;
using ODBC::ODBCConnection;
using ODBC::ODBCEnvironment;
using ODBC::ODBCStatement;

LOG_DEBUG(
"SQLGetDiagRecW called with handleType: {}, handle: {}, recNumber: {}, "
"sqlState: {}, nativeErrorPtr: {}, messageText: {}, bufferLength: {}, "
"textLengthPtr: {}",
handleType, handle, recNumber, fmt::ptr(sqlState), fmt::ptr(nativeErrorPtr),
fmt::ptr(messageText), bufferLength, fmt::ptr(textLengthPtr));

using driver::odbcabstraction::Diagnostics;
using ODBC::GetStringAttribute;
using ODBC::ODBCConnection;
using ODBC::ODBCEnvironment;
using ODBC::ODBCStatement;

if (!handle) {
return SQL_INVALID_HANDLE;
}
Expand Down Expand Up @@ -567,14 +567,14 @@ SQLRETURN SQLGetDiagRec(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT re

SQLRETURN SQLGetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,
SQLINTEGER bufferLength, SQLINTEGER* strLenPtr) {
using driver::odbcabstraction::DriverException;
using ODBC::ODBCEnvironment;

LOG_DEBUG(
"SQLGetEnvAttr called with env: {}, attr: {}, valuePtr: {}, "
"bufferLength: {}, strLenPtr: {}",
env, attr, valuePtr, bufferLength, fmt::ptr(strLenPtr));

using driver::odbcabstraction::DriverException;
using ODBC::ODBCEnvironment;

ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(env);

return ODBCEnvironment::ExecuteWithDiagnostics(environment, SQL_ERROR, [=]() {
Expand Down Expand Up @@ -628,14 +628,14 @@ SQLRETURN SQLGetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,

SQLRETURN SQLSetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,
SQLINTEGER strLen) {
using driver::odbcabstraction::DriverException;
using ODBC::ODBCEnvironment;

LOG_DEBUG(
"SQLSetEnvAttr called with env: {}, attr: {}, valuePtr: {}, "
"strLen: {}",
env, attr, valuePtr, strLen);

using driver::odbcabstraction::DriverException;
using ODBC::ODBCEnvironment;

ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(env);

return ODBCEnvironment::ExecuteWithDiagnostics(environment, SQL_ERROR, [=]() {
Expand Down Expand Up @@ -680,14 +680,14 @@ SQLRETURN SQLSetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,

SQLRETURN SQLGetConnectAttr(SQLHDBC conn, SQLINTEGER attribute, SQLPOINTER valuePtr,
SQLINTEGER bufferLength, SQLINTEGER* stringLengthPtr) {
using driver::odbcabstraction::Connection;
using ODBC::ODBCConnection;

LOG_DEBUG(
"SQLGetConnectAttrW called with conn: {}, attribute: {}, valuePtr: {}, "
"bufferLength: {}, stringLengthPtr: {}",
conn, attribute, valuePtr, bufferLength, fmt::ptr(stringLengthPtr));

using driver::odbcabstraction::Connection;
using ODBC::ODBCConnection;

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
const bool isUnicode = true;
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
Expand All @@ -698,13 +698,13 @@ SQLRETURN SQLGetConnectAttr(SQLHDBC conn, SQLINTEGER attribute, SQLPOINTER value

SQLRETURN SQLSetConnectAttr(SQLHDBC conn, SQLINTEGER attr, SQLPOINTER valuePtr,
SQLINTEGER valueLen) {
using driver::odbcabstraction::Connection;
using ODBC::ODBCConnection;

LOG_DEBUG(
"SQLSetConnectAttrW called with conn: {}, attr: {}, valuePtr: {}, valueLen: {}",
conn, attr, valuePtr, valueLen);

using driver::odbcabstraction::Connection;
using ODBC::ODBCConnection;

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
const bool isUnicode = true;
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
Expand All @@ -720,6 +720,14 @@ SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND windowHandle,
SQLSMALLINT outConnectionStringBufferLen,
SQLSMALLINT* outConnectionStringLen,
SQLUSMALLINT driverCompletion) {
LOG_DEBUG(
"SQLDriverConnectW called with conn: {}, windowHandle: {}, inConnectionString: {}, "
"inConnectionStringLen: {}, outConnectionString: {}, outConnectionStringBufferLen: "
"{}, outConnectionStringLen: {}, driverCompletion: {}",
conn, fmt::ptr(windowHandle), fmt::ptr(inConnectionString), inConnectionStringLen,
fmt::ptr(outConnectionString), outConnectionStringBufferLen,
fmt::ptr(outConnectionStringLen), driverCompletion);

// TODO: Implement FILEDSN and SAVEFILE keywords according to the spec
// https://github.com/apache/arrow/issues/46449

Expand All @@ -730,14 +738,6 @@ SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND windowHandle,
using driver::odbcabstraction::DriverException;
using ODBC::ODBCConnection;

LOG_DEBUG(
"SQLDriverConnectW called with conn: {}, windowHandle: {}, inConnectionString: {}, "
"inConnectionStringLen: {}, outConnectionString: {}, outConnectionStringBufferLen: "
"{}, outConnectionStringLen: {}, driverCompletion: {}",
conn, fmt::ptr(windowHandle), fmt::ptr(inConnectionString), inConnectionStringLen,
fmt::ptr(outConnectionString), outConnectionStringBufferLen,
fmt::ptr(outConnectionStringLen), driverCompletion);

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
std::string connection_string =
Expand Down Expand Up @@ -796,18 +796,18 @@ SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND windowHandle,
SQLRETURN SQLConnect(SQLHDBC conn, SQLWCHAR* dsnName, SQLSMALLINT dsnNameLen,
SQLWCHAR* userName, SQLSMALLINT userNameLen, SQLWCHAR* password,
SQLSMALLINT passwordLen) {
using driver::flight_sql::FlightSqlConnection;
using driver::flight_sql::config::Configuration;
using ODBC::ODBCConnection;

using ODBC::SqlWcharToString;

LOG_DEBUG(
"SQLConnectW called with conn: {}, dsnName: {}, dsnNameLen: {}, userName: {}, "
"userNameLen: {}, password: {}, passwordLen: {}",
conn, fmt::ptr(dsnName), dsnNameLen, fmt::ptr(userName), userNameLen,
fmt::ptr(password), passwordLen);

using driver::flight_sql::FlightSqlConnection;
using driver::flight_sql::config::Configuration;
using ODBC::ODBCConnection;

using ODBC::SqlWcharToString;

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
std::string dsn = SqlWcharToString(dsnName, dsnNameLen);
Expand All @@ -834,10 +834,10 @@ SQLRETURN SQLConnect(SQLHDBC conn, SQLWCHAR* dsnName, SQLSMALLINT dsnNameLen,
}

SQLRETURN SQLDisconnect(SQLHDBC conn) {
using ODBC::ODBCConnection;

LOG_DEBUG("SQLDisconnect called with conn: {}", conn);

using ODBC::ODBCConnection;

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);

Expand All @@ -849,13 +849,13 @@ SQLRETURN SQLDisconnect(SQLHDBC conn) {

SQLRETURN SQLGetInfo(SQLHDBC conn, SQLUSMALLINT infoType, SQLPOINTER infoValuePtr,
SQLSMALLINT bufLen, SQLSMALLINT* stringLengthPtr) {
using ODBC::ODBCConnection;

LOG_DEBUG(
"SQLGetInfo called with conn: {}, infoType: {}, infoValuePtr: {}, bufLen: {}, "
"stringLengthPtr: {}",
conn, infoType, infoValuePtr, bufLen, fmt::ptr(stringLengthPtr));

using ODBC::ODBCConnection;

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);

Expand Down Expand Up @@ -923,6 +923,7 @@ SQLRETURN SQLPrepare(SQLHSTMT stmt, SQLWCHAR* queryText, SQLINTEGER textLength)

SQLRETURN SQLExecute(SQLHSTMT stmt) {
LOG_DEBUG("SQLExecute called with stmt: {}", stmt);

using ODBC::ODBCStatement;
// The driver is built to handle SELECT statements only.
return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
Expand All @@ -936,8 +937,10 @@ SQLRETURN SQLExecute(SQLHSTMT stmt) {

SQLRETURN SQLFetch(SQLHSTMT stmt) {
LOG_DEBUG("SQLFetch called with stmt: {}", stmt);

using ODBC::ODBCDescriptor;
using ODBC::ODBCStatement;

return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);

Expand All @@ -963,7 +966,9 @@ SQLRETURN SQLGetData(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType
"SQLGetData called with stmt: {}, recordNumber: {}, cType: {}, "
"dataPtr: {}, bufferLength: {}, indicatorPtr: {}",
stmt, recordNumber, cType, dataPtr, bufferLength, fmt::ptr(indicatorPtr));

using ODBC::ODBCStatement;

return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);
return statement->GetData(recordNumber, cType, dataPtr, bufferLength, indicatorPtr);
Expand Down
Loading
Loading