Basic support for passing postgresql uri on the commandline
This commit is contained in:
parent
4b4c95e57e
commit
4caccf1000
11 changed files with 453 additions and 192 deletions
38
pglablib/utils/PostgresqlUrlParser.cpp
Normal file
38
pglablib/utils/PostgresqlUrlParser.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "PostgresqlUrlParser.h"
|
||||
|
||||
#include <ConnectionConfig.h>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
|
||||
//PostgresqlUrlParser::PostgresqlUrlParser() {}
|
||||
|
||||
bool TryParsePostgresqlUrl(const QString &urlString, ConnectionConfig &out)
|
||||
{
|
||||
const char* shortPrefix = "postgres";
|
||||
const char* longPrefix = "postgresql";
|
||||
|
||||
auto url = QUrl(urlString, QUrl::StrictMode);
|
||||
if (url.scheme() != shortPrefix && url.scheme() != longPrefix)
|
||||
return false;
|
||||
|
||||
out.setUser(url.userName());
|
||||
out.setPassword(url.password());
|
||||
out.setHost(url.host());
|
||||
out.setDbname(url.fileName());
|
||||
out.setPort(url.port());
|
||||
|
||||
QUrlQuery query(url.query());
|
||||
for (auto && param : query.queryItems())
|
||||
{
|
||||
if (param.first == "ssl" && param.second == "true") {
|
||||
out.setSslMode(SslMode::require);
|
||||
}
|
||||
else
|
||||
{
|
||||
out.setParameter(param.first, param.second);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue