allow to use hostaddr, port or conn_string to connect to PostgreSQL
This commit is contained in:
parent
0bdabfc7b4
commit
ac77abb8fd
|
@ -391,9 +391,37 @@ bool PostgreSQLConnector::query_remove(const pt::TextStream & stream, QueryResul
|
|||
//}
|
||||
|
||||
|
||||
void PostgreSQLConnector::set_conn_param(const std::wstring & database_conn_string)
|
||||
{
|
||||
db_conn_string = database_conn_string;
|
||||
db_hostaddr.clear();
|
||||
db_port.clear();
|
||||
db_database.clear();
|
||||
db_user.clear();
|
||||
db_pass.clear();
|
||||
}
|
||||
|
||||
|
||||
void PostgreSQLConnector::set_conn_param(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_hostaddr = database_hostaddr;
|
||||
db_port = database_port;
|
||||
db_database = database_name;
|
||||
db_user = user;
|
||||
db_pass = pass;
|
||||
}
|
||||
|
||||
|
||||
void PostgreSQLConnector::set_conn_param(const std::wstring & database_name, const std::wstring & user, const std::wstring & pass)
|
||||
{
|
||||
db_conn_string.clear();
|
||||
db_hostaddr.clear();
|
||||
db_port.clear();
|
||||
db_database = database_name;
|
||||
db_user = user;
|
||||
db_pass = pass;
|
||||
|
@ -427,15 +455,37 @@ void PostgreSQLConnector::connect()
|
|||
if( db_expression )
|
||||
{
|
||||
stream.clear();
|
||||
stream << "dbname='";
|
||||
db_expression->esc(db_database, stream);
|
||||
|
||||
stream << "' user='";
|
||||
db_expression->esc(db_user, stream);
|
||||
if( !db_conn_string.empty() )
|
||||
{
|
||||
stream << db_conn_string;
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << "dbname='";
|
||||
db_expression->esc(db_database, stream);
|
||||
|
||||
stream << "' password='";
|
||||
db_expression->esc(db_pass, stream);
|
||||
stream << "'";
|
||||
stream << "' user='";
|
||||
db_expression->esc(db_user, stream);
|
||||
|
||||
stream << "' password='";
|
||||
db_expression->esc(db_pass, stream);
|
||||
stream << "'";
|
||||
|
||||
if( !db_hostaddr.empty() )
|
||||
{
|
||||
stream << " hostaddr='";
|
||||
db_expression->esc(db_hostaddr, stream);
|
||||
stream << "'";
|
||||
}
|
||||
|
||||
if( !db_port.empty() )
|
||||
{
|
||||
stream << " port='";
|
||||
db_expression->esc(db_port, stream);
|
||||
stream << "'";
|
||||
}
|
||||
}
|
||||
|
||||
std::string str;
|
||||
stream.to_str(str);
|
||||
|
|
|
@ -70,7 +70,13 @@ public:
|
|||
bool query_remove(const pt::TextStream & stream, QueryResult & query_result);
|
||||
|
||||
|
||||
/*
|
||||
* 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);
|
||||
virtual void set_conn_param(const std::wstring & database, const std::wstring & user, const std::wstring & pass);
|
||||
|
||||
virtual void connect();
|
||||
virtual void wait_for_connection();
|
||||
virtual void close();
|
||||
|
@ -88,6 +94,9 @@ protected:
|
|||
pt::TextStream stream;
|
||||
std::string query_str;
|
||||
|
||||
std::wstring db_conn_string;
|
||||
std::wstring db_hostaddr;
|
||||
std::wstring db_port;
|
||||
std::wstring db_database;
|
||||
std::wstring db_user;
|
||||
std::wstring db_pass;
|
||||
|
|
Loading…
Reference in New Issue