mirror of
https://github.com/haiwen/ccnet-server.git
synced 2025-08-31 12:26:45 +00:00
Merge pull request #5 from haiwen/pgsql_port_setting
Postgresql port setting
This commit is contained in:
@@ -56,6 +56,7 @@ ccnet_db_new_mysql (const char *host,
|
||||
|
||||
CcnetDB *
|
||||
ccnet_db_new_pgsql (const char *host,
|
||||
unsigned int port,
|
||||
const char *user,
|
||||
const char *passwd,
|
||||
const char *db_name,
|
||||
@@ -72,7 +73,7 @@ ccnet_db_new_pgsql (const char *host,
|
||||
|
||||
db->type = CCNET_DB_TYPE_PGSQL;
|
||||
|
||||
db->pool = db_conn_pool_new_pgsql (host, user, passwd, db_name, unix_socket,
|
||||
db->pool = db_conn_pool_new_pgsql (host, port, user, passwd, db_name, unix_socket,
|
||||
max_connections);
|
||||
|
||||
return db;
|
||||
|
@@ -30,6 +30,7 @@ ccnet_db_new_mysql (const char *host,
|
||||
|
||||
CcnetDB *
|
||||
ccnet_db_new_pgsql (const char *host,
|
||||
unsigned int port,
|
||||
const char *user,
|
||||
const char *passwd,
|
||||
const char *db_name,
|
||||
|
@@ -95,6 +95,7 @@ db_conn_pool_new_mysql (const char *host,
|
||||
|
||||
DBConnPool *
|
||||
db_conn_pool_new_pgsql (const char *host,
|
||||
unsigned int port,
|
||||
const char *user,
|
||||
const char *password,
|
||||
const char *db_name,
|
||||
@@ -124,7 +125,7 @@ db_conn_pool_new_pgsql (const char *host,
|
||||
|
||||
DBConnPool *pool;
|
||||
|
||||
pool = pgsql_db_conn_pool_new (host, user, password, db_name, unix_socket);
|
||||
pool = pgsql_db_conn_pool_new (host, port, user, password, db_name, unix_socket);
|
||||
init_conn_pool_common (pool, max_connections);
|
||||
|
||||
return pool;
|
||||
|
@@ -29,6 +29,7 @@ db_conn_pool_new_mysql (const char *host,
|
||||
|
||||
DBConnPool *
|
||||
db_conn_pool_new_pgsql (const char *host,
|
||||
unsigned int port,
|
||||
const char *user,
|
||||
const char *password,
|
||||
const char *db_name,
|
||||
|
@@ -8,6 +8,7 @@
|
||||
typedef struct PGDBConnPool {
|
||||
DBConnPool parent;
|
||||
char *host;
|
||||
unsigned int port;
|
||||
char *user;
|
||||
char *password;
|
||||
char *db_name;
|
||||
@@ -16,6 +17,7 @@ typedef struct PGDBConnPool {
|
||||
|
||||
DBConnPool *
|
||||
pgsql_db_conn_pool_new (const char *host,
|
||||
unsigned int port,
|
||||
const char *user,
|
||||
const char *password,
|
||||
const char *db_name,
|
||||
@@ -24,6 +26,7 @@ pgsql_db_conn_pool_new (const char *host,
|
||||
PGDBConnPool *pool = g_new0 (PGDBConnPool, 1);
|
||||
|
||||
pool->host = g_strdup (host);
|
||||
pool->port = port;
|
||||
pool->user = g_strdup (user);
|
||||
pool->password = g_strdup (password);
|
||||
pool->db_name = g_strdup(db_name);
|
||||
@@ -88,6 +91,10 @@ connect_pgsql (PGDBConnPool *pool, GError **error)
|
||||
g_string_append_printf (buf, "host='%s' ", pool->host);
|
||||
}
|
||||
|
||||
if (pool->port > 0) {
|
||||
g_string_append_printf (buf, "port=%u ", pool->port);
|
||||
}
|
||||
|
||||
g_string_append_printf (buf, "dbname='%s' ", pool->db_name);
|
||||
|
||||
db = PQconnectdb (buf->str);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
DBConnPool *
|
||||
pgsql_db_conn_pool_new (const char *host,
|
||||
unsigned int port,
|
||||
const char *user,
|
||||
const char *password,
|
||||
const char *db_name,
|
||||
|
@@ -197,6 +197,7 @@ static int init_mysql_database (CcnetSession *session)
|
||||
static int init_pgsql_database (CcnetSession *session)
|
||||
{
|
||||
char *host, *user, *passwd, *db, *unix_socket;
|
||||
unsigned int port;
|
||||
|
||||
host = ccnet_key_file_get_string (session->keyf, "Database", "HOST");
|
||||
user = ccnet_key_file_get_string (session->keyf, "Database", "USER");
|
||||
@@ -219,10 +220,17 @@ static int init_pgsql_database (CcnetSession *session)
|
||||
g_warning ("DB name not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
port = g_key_file_get_integer (session->keyf, "Database", "PORT", &error);
|
||||
if (error) {
|
||||
port = 0;
|
||||
g_clear_error (&error);
|
||||
}
|
||||
unix_socket = ccnet_key_file_get_string (session->keyf,
|
||||
"Database", "UNIX_SOCKET");
|
||||
|
||||
session->db = ccnet_db_new_pgsql (host, user, passwd, db, unix_socket,
|
||||
session->db = ccnet_db_new_pgsql (host, port, user, passwd, db, unix_socket,
|
||||
DEFAULT_MAX_CONNECTIONS);
|
||||
if (!session->db) {
|
||||
g_warning ("Failed to open database.\n");
|
||||
|
Reference in New Issue
Block a user