allow to use host connection parameter
This commit is contained in:
parent
ac77abb8fd
commit
d384929e75
|
@ -402,13 +402,15 @@ void PostgreSQLConnector::set_conn_param(const std::wstring & database_conn_stri
|
|||
}
|
||||
|
||||
|
||||
void PostgreSQLConnector::set_conn_param(const std::wstring & database_hostaddr,
|
||||
void PostgreSQLConnector::set_conn_param(const std::wstring & database_host,
|
||||
const std::wstring & database_hostaddr,
|
||||
const std::wstring & database_port,
|
||||
const std::wstring & database_name,
|
||||
const std::wstring & user,
|
||||
const std::wstring & pass)
|
||||
{
|
||||
db_conn_string.clear();
|
||||
db_host = database_host;
|
||||
db_hostaddr = database_hostaddr;
|
||||
db_port = database_port;
|
||||
db_database = database_name;
|
||||
|
@ -420,6 +422,7 @@ void PostgreSQLConnector::set_conn_param(const std::wstring & database_hostaddr,
|
|||
void PostgreSQLConnector::set_conn_param(const std::wstring & database_name, const std::wstring & user, const std::wstring & pass)
|
||||
{
|
||||
db_conn_string.clear();
|
||||
db_host.clear();
|
||||
db_hostaddr.clear();
|
||||
db_port.clear();
|
||||
db_database = database_name;
|
||||
|
@ -472,6 +475,13 @@ void PostgreSQLConnector::connect()
|
|||
db_expression->esc(db_pass, stream);
|
||||
stream << "'";
|
||||
|
||||
if( !db_host.empty() )
|
||||
{
|
||||
stream << " host='";
|
||||
db_expression->esc(db_host, stream);
|
||||
stream << "'";
|
||||
}
|
||||
|
||||
if( !db_hostaddr.empty() )
|
||||
{
|
||||
stream << " hostaddr='";
|
||||
|
|
|
@ -74,7 +74,37 @@ public:
|
|||
* https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNSTRING
|
||||
*/
|
||||
virtual void set_conn_param(const std::wstring & database_conn_string);
|
||||
virtual void set_conn_param(const std::wstring & database_hostaddr, const std::wstring & database_port, const std::wstring & database, const std::wstring & user, const std::wstring & pass);
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* database_host - name of host to connect to (can be empty)
|
||||
* database_hostaddr - numeric IP address of host to connect to (can be empty)
|
||||
*
|
||||
*
|
||||
* meaning of this parameters is the same as described in
|
||||
* https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNSTRING
|
||||
*
|
||||
* from above documentation:
|
||||
* Using hostaddr allows the application to avoid a host name look-up, which might be important
|
||||
* in applications with time constraints. However, a host name is required for GSSAPI or SSPI
|
||||
* authentication methods, as well as for verify-full SSL certificate verification.
|
||||
* The following rules are used:
|
||||
*
|
||||
* - If host is specified without hostaddr, a host name lookup occurs.
|
||||
*
|
||||
* - If hostaddr is specified without host, the value for hostaddr gives the server network address.
|
||||
* The connection attempt will fail if the authentication method requires a host name.
|
||||
*
|
||||
* - If both host and hostaddr are specified, the value for hostaddr gives the server network address.
|
||||
* The value for host is ignored unless the authentication method requires it, in which case it will
|
||||
* be used as the host name.
|
||||
*
|
||||
*/
|
||||
virtual void set_conn_param(const std::wstring & database_host, const std::wstring & database_hostaddr, const std::wstring & database_port,
|
||||
const std::wstring & database, const std::wstring & user, const std::wstring & pass);
|
||||
|
||||
|
||||
virtual void set_conn_param(const std::wstring & database, const std::wstring & user, const std::wstring & pass);
|
||||
|
||||
virtual void connect();
|
||||
|
@ -95,6 +125,7 @@ protected:
|
|||
std::string query_str;
|
||||
|
||||
std::wstring db_conn_string;
|
||||
std::wstring db_host;
|
||||
std::wstring db_hostaddr;
|
||||
std::wstring db_port;
|
||||
std::wstring db_database;
|
||||
|
|
Loading…
Reference in New Issue