Exemple #1
0
/*
 * the result is also available with the global variable 'connection'.
 */
void
reconnect(int elevel)
{
	StringInfoData	buf;
	char		   *new_password;

	disconnect();
	initStringInfo(&buf);
	if (dbname && dbname[0])
		appendStringInfo(&buf, "dbname=%s ", dbname);
	if (host && host[0])
		appendStringInfo(&buf, "host=%s ", host);
	if (port && port[0])
		appendStringInfo(&buf, "port=%s ", port);
	if (username && username[0])
		appendStringInfo(&buf, "user=%s ", username);
	if (password && password[0])
		appendStringInfo(&buf, "password=%s ", password);

	connection = pgut_connect(buf.data, prompt_password, elevel);

	/* update password */
	if (connection)
	{
		new_password = PQpass(connection);
		if (new_password && new_password[0] &&
			(password == NULL || strcmp(new_password, password) != 0))
		{
			free(password);
			password = pgut_strdup(new_password);
		}
	}

	termStringInfo(&buf);
}
Exemple #2
0
int
main(int argc, char *argv[])
{
	PGconn			*conn;
	StringInfoData	 conn_info;
	int				 num_options;

	num_options = pgut_getopt(argc, argv, options);

	/* command-line arguments is not necessary */
	if (num_options != argc)
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("too many argumetns")));

	/* can't specified the mode two or more */
	if ((mode_list && (mode_size || mode_report || mode_snapshot || mode_delete)) ||
		(mode_size && (mode_report || mode_snapshot || mode_delete)) ||
		(mode_report && (mode_snapshot || mode_delete)) ||
		(mode_snapshot && mode_delete))
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("can't specify two or more mode")));

	/* connect to database */
	initStringInfo(&conn_info);
	if (dbname && dbname[0])
		appendStringInfo(&conn_info, "dbname=%s ", dbname);
	if (host && host[0])
		appendStringInfo(&conn_info, "host=%s ", host);
	if (port && port[0])
		appendStringInfo(&conn_info, "port=%s ", port);
	if (username && username[0])
		appendStringInfo(&conn_info, "user=%s ", username);

	conn = pgut_connect(conn_info.data, prompt_password, ERROR);
	termStringInfo(&conn_info);

	/* execute a specified operation */
	if (mode_list)
		do_list(conn, instid);
	else if (mode_size)
		do_size(conn);
	else if (mode_report)
		do_report(conn, mode_report,
			instid, beginid, endid, begindate, enddate, output);
	else if (mode_snapshot)
		do_snapshot(conn, mode_snapshot);
	else if (mode_delete)
		do_delete(conn, mode_delete);
	else
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("please specify operation option (-l, -s, -r, -S, -D)")));

	pgut_disconnect(conn);
	return 0;
}
Exemple #3
0
/*
 * the result is also available with the global variable 'connection'.
 */
PGconn *
reconnect(void)
{
	disconnect();
	return connection = pgut_connect();
}