in modules/platforms/cpp/odbc/src/config/connection_string_parser.cpp [134:466]
void ConnectionStringParser::HandleAttributePair(const std::string &key, const std::string &value,
diagnostic::DiagnosticRecordStorage* diag)
{
std::string lKey = common::ToLower(key);
if (lKey == Key::dsn)
{
cfg.SetDsn(value);
}
else if (lKey == Key::schema)
{
cfg.SetSchema(value);
}
else if (lKey == Key::address)
{
std::vector<EndPoint> endPoints;
ParseAddress(value, endPoints, diag);
cfg.SetAddresses(endPoints);
}
else if (lKey == Key::server)
{
cfg.SetHost(value);
}
else if (lKey == Key::port)
{
if (value.empty())
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Port attribute value is empty. Using default value.", key, value));
}
return;
}
if (!common::AllDigits(value))
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Port attribute value contains unexpected characters."
" Using default value.", key, value));
}
return;
}
if (value.size() >= sizeof("65535"))
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Port attribute value is too large. Using default value.", key, value));
}
return;
}
int32_t numValue = 0;
std::stringstream conv;
conv << value;
conv >> numValue;
if (numValue <= 0 || numValue > 0xFFFF)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Port attribute value is out of range. "
"Using default value.", key, value));
}
return;
}
cfg.SetTcpPort(static_cast<uint16_t>(numValue));
}
else if (lKey == Key::distributedJoins)
{
BoolParseResult::Type res = StringToBool(value);
if (res == BoolParseResult::AI_UNRECOGNIZED)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Unrecognized bool value. Using default value.", key, value));
}
return;
}
cfg.SetDistributedJoins(res == BoolParseResult::AI_TRUE);
}
else if (lKey == Key::enforceJoinOrder)
{
BoolParseResult::Type res = StringToBool(value);
if (res == BoolParseResult::AI_UNRECOGNIZED)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Unrecognized bool value. Using default value.", key, value));
}
return;
}
cfg.SetEnforceJoinOrder(res == BoolParseResult::AI_TRUE);
}
else if (lKey == Key::protocolVersion)
{
try
{
ProtocolVersion version = ProtocolVersion::FromString(value);
if (!version.IsSupported())
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
"Specified version is not supported. Default value used.");
}
return;
}
cfg.SetProtocolVersion(version);
}
catch (IgniteError& err)
{
if (diag)
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED, err.GetText());
}
}
else if (lKey == Key::pageSize)
{
if (!common::AllDigits(value))
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Page size attribute value contains unexpected characters."
" Using default value.", key, value));
}
return;
}
if (value.size() >= sizeof("4294967295"))
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Page size attribute value is too large."
" Using default value.", key, value));
}
return;
}
int64_t numValue = 0;
std::stringstream conv;
conv << value;
conv >> numValue;
if (numValue <= 0 || numValue > 0xFFFFFFFFL)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Page size attribute value is out of range."
" Using default value.", key, value));
}
return;
}
cfg.SetPageSize(static_cast<int32_t>(numValue));
}
else if (lKey == Key::replicatedOnly)
{
BoolParseResult::Type res = StringToBool(value);
if (res == BoolParseResult::AI_UNRECOGNIZED)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Unrecognized bool value. Using default value.", key, value));
}
return;
}
cfg.SetReplicatedOnly(res == BoolParseResult::AI_TRUE);
}
else if (lKey == Key::collocated)
{
BoolParseResult::Type res = StringToBool(value);
if (res == BoolParseResult::AI_UNRECOGNIZED)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Unrecognized bool value. Using default value.", key, value));
}
return;
}
cfg.SetCollocated(res == BoolParseResult::AI_TRUE);
}
else if (lKey == Key::lazy)
{
BoolParseResult::Type res = StringToBool(value);
if (res == BoolParseResult::AI_UNRECOGNIZED)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Unrecognized bool value. Defaulting to 'false'.", key, value));
}
return;
}
cfg.SetLazy(res == BoolParseResult::AI_TRUE);
}
else if (lKey == Key::skipReducerOnUpdate)
{
BoolParseResult::Type res = StringToBool(value);
if (res == BoolParseResult::AI_UNRECOGNIZED)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
MakeErrorMessage("Unrecognized bool value. Defaulting to 'false'.", key, value));
}
return;
}
cfg.SetSkipReducerOnUpdate(res == BoolParseResult::AI_TRUE);
}
else if (lKey == Key::sslMode)
{
ssl::SslMode::Type mode = ssl::SslMode::FromString(value);
if (mode == ssl::SslMode::UNKNOWN)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
"Specified SSL mode is not supported. Default value used ('disable').");
}
return;
}
cfg.SetSslMode(mode);
}
else if (lKey == Key::sslKeyFile)
{
cfg.SetSslKeyFile(value);
}
else if (lKey == Key::sslCertFile)
{
cfg.SetSslCertFile(value);
}
else if (lKey == Key::sslCaFile)
{
cfg.SetSslCaFile(value);
}
else if (lKey == Key::driver)
{
cfg.SetDriver(value);
}
else if (lKey == Key::user || lKey == Key::uid)
{
if (!cfg.GetUser().empty() && diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
"Re-writing USER (have you specified it several times?");
}
cfg.SetUser(value);
}
else if (lKey == Key::password || lKey == Key::pwd)
{
if (!cfg.GetPassword().empty() && diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
"Re-writing PASSWORD (have you specified it several times?");
}
cfg.SetPassword(value);
}
else if (lKey == Key::engineMode)
{
EngineMode::Type mode = EngineMode::FromString(value);
if (mode == EngineMode::UNKNOWN)
{
if (diag)
{
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
"Specified SQL engine is not supported. Default value used ('error').");
}
return;
}
cfg.SetEngineMode(mode);
}
else if (diag)
{
std::stringstream stream;
stream << "Unknown attribute: '" << key << "'. Ignoring.";
diag->AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED, stream.str());
}
}