2010-10-24 03:12:37 +04:00
|
|
|
/*
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
#include "postgresql.h"
|
|
|
|
|
|
|
|
const char *build_conninfo(const char *db, const char *username, const char *password, const char *host, const char *port)
|
|
|
|
{
|
|
|
|
static char conninfo[1024];
|
|
|
|
|
|
|
|
conninfo[0]='\0';
|
|
|
|
strcat(conninfo, "dbname='");
|
|
|
|
strcat(conninfo, db);
|
|
|
|
strcat(conninfo, "'");
|
|
|
|
|
2010-12-10 19:13:07 +03:00
|
|
|
if (username)
|
|
|
|
{
|
2010-10-24 03:12:37 +04:00
|
|
|
strcat(conninfo, " user='");
|
|
|
|
strcat(conninfo, username);
|
|
|
|
strcat(conninfo, "'");
|
|
|
|
}
|
2010-12-10 19:13:07 +03:00
|
|
|
if (password)
|
|
|
|
{
|
2010-10-24 03:12:37 +04:00
|
|
|
strcat(conninfo, " password='");
|
|
|
|
strcat(conninfo, password);
|
|
|
|
strcat(conninfo, "'");
|
|
|
|
}
|
2010-12-10 19:13:07 +03:00
|
|
|
if (host)
|
|
|
|
{
|
2010-10-24 03:12:37 +04:00
|
|
|
strcat(conninfo, " host='");
|
|
|
|
strcat(conninfo, host);
|
|
|
|
strcat(conninfo, "'");
|
|
|
|
}
|
2010-12-10 19:13:07 +03:00
|
|
|
if (port)
|
|
|
|
{
|
2010-10-24 03:12:37 +04:00
|
|
|
strcat(conninfo, " port='");
|
|
|
|
strcat(conninfo, port);
|
|
|
|
strcat(conninfo, "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
return conninfo;
|
|
|
|
}
|