| 82 | } |
| 83 | |
| 84 | std::vector<std::string> ReadAllKeys(const std::string& dsn) { |
| 85 | CONVERT_SQLWCHAR_STR(wdsn, dsn); |
| 86 | |
| 87 | std::vector<SQLWCHAR> buf(BUFFER_SIZE); |
| 88 | |
| 89 | int ret = SQLGetPrivateProfileString(reinterpret_cast<LPCWSTR>(wdsn.c_str()), NULL, |
| 90 | reinterpret_cast<LPCWSTR>(L""), buf.data(), |
| 91 | static_cast<int>(buf.size()), ODBC_INI); |
| 92 | |
| 93 | if (ret > BUFFER_SIZE) { |
| 94 | // If there wasn't enough space, try again with the right size buffer. |
| 95 | buf.resize(ret + 1); |
| 96 | ret = SQLGetPrivateProfileString(reinterpret_cast<LPCWSTR>(wdsn.c_str()), NULL, |
| 97 | reinterpret_cast<LPCWSTR>(L""), buf.data(), |
| 98 | static_cast<int>(buf.size()), ODBC_INI); |
| 99 | } |
| 100 | |
| 101 | // When you pass NULL to SQLGetPrivateProfileString it gives back a \0 delimited list of |
| 102 | // all the keys. The below loop simply tokenizes all the keys and places them into a |
| 103 | // vector. |
| 104 | std::vector<std::string> keys; |
| 105 | SQLWCHAR* begin = buf.data(); |
| 106 | while (begin && *begin != '\0') { |
| 107 | SQLWCHAR* cur; |
| 108 | for (cur = begin; *cur != '\0'; ++cur) { |
| 109 | } |
| 110 | |
| 111 | std::string key(""); |
| 112 | SQLINTEGER key_len = static_cast<SQLINTEGER>(cur - begin); |
| 113 | SetAttributeSQLWCHAR(begin, key_len * GetSqlWCharSize(), key); |
| 114 | keys.emplace_back(key); |
| 115 | begin = ++cur; |
| 116 | } |
| 117 | return keys; |
| 118 | } |
| 119 | } // namespace |
| 120 | |
| 121 | Configuration::Configuration() { |
no test coverage detected