|
5 | 5 | #if !defined(_WIN32) && !defined(_WIN64) |
6 | 6 | #include <signal.h> |
7 | 7 | #endif |
| 8 | + |
| 9 | +#ifndef SQL_DRIVER_CONN_ATTR_BASE |
| 10 | + #define SQL_DRIVER_CONN_ATTR_BASE 0x00004000 |
| 11 | +#endif |
| 12 | +#define SQL_SF_CONN_ATTR_BASE (SQL_DRIVER_CONN_ATTR_BASE + 0x53) |
| 13 | +#define SQL_SF_CONN_ATTR_PRIV_KEY (SQL_SF_CONN_ATTR_BASE + 1) |
| 14 | +#define SQL_SF_CONN_ATTR_PRIV_KEY_CONTENT (SQL_SF_CONN_ATTR_BASE + 3) |
| 15 | +#define SQL_SF_CONN_ATTR_PRIV_KEY_PASSWORD (SQL_SF_CONN_ATTR_BASE + 4) |
8 | 16 | namespace odbc { |
9 | 17 | namespace utils { |
10 | 18 |
|
@@ -34,19 +42,42 @@ namespace utils { |
34 | 42 | attributes.push_back(nanodbc::connection::attribute( |
35 | 43 | SQL_ATTR_LOGIN_TIMEOUT, SQL_IS_UINTEGER, (void*)(std::intptr_t)timeout)); |
36 | 44 | } |
37 | | - std::shared_ptr< void > buffer; |
38 | 45 | if ( r_attributes_.isNotNull() ) |
39 | 46 | { |
40 | 47 | Rcpp::List r_attributes( r_attributes_ ); |
41 | | - if ( r_attributes.containsElementNamed( "azure_token" ) && |
42 | | - !Rf_isNull(r_attributes["azure_token"]) ) |
| 48 | + if (r_attributes.containsElementNamed( "azure_token" ) && |
| 49 | + !Rf_isNull(r_attributes["azure_token"])) |
43 | 50 | { |
44 | 51 | std::string azure_token = |
45 | 52 | Rcpp::as<std::string>(r_attributes["azure_token"]); |
46 | 53 | std::shared_ptr< void > buffer = serialize_azure_token( azure_token ); |
47 | 54 | attributes.push_back(nanodbc::connection::attribute( |
48 | 55 | SQL_COPT_SS_ACCESS_TOKEN, SQL_IS_POINTER, buffer.get())); |
49 | | - buffer_context.push_back( buffer ); |
| 56 | + buffer_context.push_back(buffer); |
| 57 | + } |
| 58 | + if (r_attributes.containsElementNamed("sf_private_key") && |
| 59 | + !Rf_isNull(r_attributes["sf_private_key"])) |
| 60 | + { |
| 61 | + std::shared_ptr<std::string> priv_key = |
| 62 | + std::make_shared<std::string>(Rcpp::as<std::string>(r_attributes["sf_private_key"])); |
| 63 | + std::shared_ptr< void > buffer(malloc(priv_key->size()), std::free); |
| 64 | + // Copy null terminator as well |
| 65 | + std::memcpy(buffer.get(), priv_key->c_str(), priv_key->size() + 1); |
| 66 | + attributes.push_back(nanodbc::connection::attribute( |
| 67 | + SQL_SF_CONN_ATTR_PRIV_KEY_CONTENT, SQL_NTS, buffer.get())); |
| 68 | + buffer_context.push_back(buffer); |
| 69 | + } |
| 70 | + if (r_attributes.containsElementNamed("sf_private_key_password") && |
| 71 | + !Rf_isNull(r_attributes["sf_private_key_password"])) |
| 72 | + { |
| 73 | + std::shared_ptr<std::string> key_pass = |
| 74 | + std::make_shared<std::string>(Rcpp::as<std::string>(r_attributes["sf_private_key_password"])); |
| 75 | + std::shared_ptr< void > buffer(malloc(key_pass->size()), std::free); |
| 76 | + // Copy null terminator as well |
| 77 | + std::memcpy(buffer.get(), key_pass->c_str(), key_pass->size() + 1); |
| 78 | + attributes.push_back(nanodbc::connection::attribute( |
| 79 | + SQL_SF_CONN_ATTR_PRIV_KEY_PASSWORD, SQL_NTS, buffer.get())); |
| 80 | + buffer_context.push_back(buffer); |
50 | 81 | } |
51 | 82 | } |
52 | 83 | } |
|
0 commit comments