zeroshade commented on code in PR #3876:
URL: https://github.com/apache/arrow-adbc/pull/3876#discussion_r2790832468


##########
c/driver_manager/adbc_driver_manager.cc:
##########
@@ -398,6 +416,81 @@ AdbcStatusCode LoadDriverFromRegistry(HKEY root, const 
std::wstring& driver_name
 }
 #endif  // _WIN32
 
+#define CHECK_STATUS(EXPR)                                \
+  if (auto _status = (EXPR); _status != ADBC_STATUS_OK) { \
+    return _status;                                       \
+  }
+
+AdbcStatusCode ProcessProfileValue(std::string_view value, std::string& out,
+                                   struct AdbcError* error) {
+  if (value.empty()) {
+    SetError(error, "Profile value is null");
+    return ADBC_STATUS_INVALID_ARGUMENT;
+  }
+
+  size_t pos = 0;
+  size_t prev_pos = 0;
+  out.resize(0);
+  while ((pos = value.find("env_var(", prev_pos)) != std::string_view::npos) {
+    const auto closing_paren = value.find_first_of(')', pos);
+    if (closing_paren == std::string_view::npos) {
+      SetError(error, "Malformed env_var() profile value: missing closing 
parenthesis");
+      return ADBC_STATUS_INVALID_ARGUMENT;
+    }
+
+    const auto env_var_start = pos + 8;
+    const auto env_var_len = closing_paren - env_var_start;
+    if (env_var_len == 0) {
+      SetError(error,
+               "Malformed env_var() profile value: missing environment 
variable name");
+      return ADBC_STATUS_INVALID_ARGUMENT;
+    }
+
+    out.append(value.substr(prev_pos, pos - prev_pos));
+    prev_pos = closing_paren + 1;
+
+    // Extract the environment variable name from the value
+    // which should be formatted as env_var(VAR_NAME) as we confirmed
+    // above.
+    const auto env_var_name = value.substr(env_var_start, env_var_len);
+#ifdef _WIN32
+    auto local_env_var = Utf8Decode(std::string(env_var_name));
+    DWORD required_size = GetEnvironmentVariableW(local_env_var.c_str(), NULL, 
0);
+    if (required_size == 0) {
+      out = "";
+      return ADBC_STATUS_OK;
+    }

Review Comment:
   I can agree with this, let's follow up in a separate PR for this though as 
you suggest.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to