• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ psql_error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中psql_error函数的典型用法代码示例。如果您正苦于以下问题:C++ psql_error函数的具体用法?C++ psql_error怎么用?C++ psql_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了psql_error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: pg_calloc

void *
pg_calloc(size_t nmemb, size_t size)
{
	void	   *tmp;

	tmp = calloc(nmemb, size);
	if (!tmp)
	{
		psql_error("out of memory\n");
		exit(EXIT_FAILURE);
	}
	return tmp;
}
开发者ID:dankrusi,项目名称:postgres,代码行数:13,代码来源:common.c


示例2: start_lo_xact

/*
 * Prepare to do a large-object operation.  We *must* be inside a transaction
 * block for all these operations, so start one if needed.
 *
 * Returns TRUE if okay, FALSE if failed.  *own_transaction is set to indicate
 * if we started our own transaction or not.
 */
static bool
start_lo_xact(const char *operation, bool *own_transaction)
{
	PGTransactionStatusType tstatus;
	PGresult   *res;

	*own_transaction = false;

	if (!pset.db)
	{
		psql_error("%s: not connected to a database\n", operation);
		return false;
	}

	tstatus = PQtransactionStatus(pset.db);

	switch (tstatus)
	{
		case PQTRANS_IDLE:
			/* need to start our own xact */
			if (!(res = PSQLexec("BEGIN", false)))
				return false;
			PQclear(res);
			*own_transaction = true;
			break;
		case PQTRANS_INTRANS:
			/* use the existing xact */
			break;
		case PQTRANS_INERROR:
			psql_error("%s: current transaction is aborted\n", operation);
			return false;
		default:
			psql_error("%s: unknown transaction status\n", operation);
			return false;
	}

	return true;
}
开发者ID:BioBD,项目名称:Hypothetical_Indexes,代码行数:45,代码来源:large_obj.c


示例3: saveHistory

/*
 * This function is for saving the readline history when user
 * runs \s command or when psql finishes.
 *
 * We have an argument named encodeFlag to handle the cases differently.
 * In case of call via \s we don't really need to encode \n as \x01,
 * but when we save history for Readline we must do that conversion.
 */
bool
saveHistory(char *fname, bool encodeFlag)
{
#ifdef USE_READLINE

	/*
	 * Suppressing the write attempt when HISTFILE is set to /dev/null may
	 * look like a negligible optimization, but it's necessary on e.g. Darwin,
	 * where write_history will fail because it tries to chmod the target
	 * file.
	 */
	if (useHistory && fname &&
		strcmp(fname, DEVNULL) != 0)
	{
		if (encodeFlag)
			encode_history();

		/*
		 * return value of write_history is not standardized across GNU
		 * readline and libedit.  Therefore, check for errno becoming set to
		 * see if the write failed.
		 */
		errno = 0;
		(void) write_history(fname);
		if (errno == 0)
			return true;

		psql_error("could not save history to file \"%s\": %s\n",
				   fname, strerror(errno));
	}
#else
	/* only get here in \s case, so complain */
	psql_error("history is not supported by this installation\n");
#endif

	return false;
}
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:45,代码来源:input.c


示例4: saveHistory

bool
saveHistory(char *fname)
{
#ifdef USE_READLINE
	if (useHistory && fname)
	{
		if (write_history(fname) == 0)
			return true;

		psql_error("could not save history to file \"%s\": %s\n", fname, strerror(errno));
	}
#endif

	return false;
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:15,代码来源:input.c


示例5: pg_malloc

void *
pg_malloc(size_t size)
{
	void	   *tmp;

	/* Avoid unportable behavior of malloc(0) */
	if (size == 0)
		size = 1;
	tmp = malloc(size);
	if (!tmp)
	{
		psql_error("out of memory\n");
		exit(EXIT_FAILURE);
	}
	return tmp;
}
开发者ID:AllenDou,项目名称:postgresql,代码行数:16,代码来源:common.c


示例6: setQFout

/*
 * setQFout
 * -- handler for -o command line option and \o command
 *
 * Tries to open file fname (or pipe if fname starts with '|')
 * and stores the file handle in pset)
 * Upon failure, sets stdout and returns false.
 */
bool
setQFout(const char *fname)
{
	bool		status = true;

	/* Close old file/pipe */
	if (pset.queryFout && pset.queryFout != stdout && pset.queryFout != stderr)
	{
		if (pset.queryFoutPipe)
			pclose(pset.queryFout);
		else
			fclose(pset.queryFout);
	}

	/* If no filename, set stdout */
	if (!fname || fname[0] == '\0')
	{
		pset.queryFout = stdout;
		pset.queryFoutPipe = false;
	}
	else if (*fname == '|')
	{
		pset.queryFout = popen(fname + 1, "w");
		pset.queryFoutPipe = true;
	}
	else
	{
		pset.queryFout = fopen(fname, "w");
		pset.queryFoutPipe = false;
	}

	if (!(pset.queryFout))
	{
		psql_error("%s: %s\n", fname, strerror(errno));
		pset.queryFout = stdout;
		pset.queryFoutPipe = false;
		status = false;
	}

	/* Direct signals */
#ifndef WIN32
	pqsignal(SIGPIPE, pset.queryFoutPipe ? SIG_IGN : SIG_DFL);
#endif

	return status;
}
开发者ID:GisKook,项目名称:Gis,代码行数:54,代码来源:common.c


示例7: PSQLexec

/*
 * PSQLexec
 *
 * This is the way to send "backdoor" queries (those not directly entered
 * by the user). It is subject to -E but not -e.
 *
 * Caller is responsible for handling the ensuing processing if a COPY
 * command is sent.
 *
 * Note: we don't bother to check PQclientEncoding; it is assumed that no
 * caller uses this path to issue "SET CLIENT_ENCODING".
 */
PGresult *
PSQLexec(const char *query)
{
	PGresult   *res;

	if (!pset.db)
	{
		psql_error("You are currently not connected to a database.\n");
		return NULL;
	}

	if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
	{
		printf(_("********* QUERY **********\n"
				 "%s\n"
				 "**************************\n\n"), query);
		fflush(stdout);
		if (pset.logfile)
		{
			fprintf(pset.logfile,
					_("********* QUERY **********\n"
					  "%s\n"
					  "**************************\n\n"), query);
			fflush(pset.logfile);
		}

		if (pset.echo_hidden == PSQL_ECHO_HIDDEN_NOEXEC)
			return NULL;
	}

	SetCancelConn();

	res = PQexec(pset.db, query);

	ResetCancelConn();

	if (!AcceptResult(res))
	{
		PQclear(res);
		res = NULL;
	}

	return res;
}
开发者ID:PJMODOS,项目名称:postgres,代码行数:56,代码来源:common.c


示例8: pg_strdup

/*
 * "Safe" wrapper around strdup()
 */
char *
pg_strdup(const char *string)
{
	char	   *tmp;

	if (!string)
	{
		fprintf(stderr, _("%s: pg_strdup: cannot duplicate null pointer (internal error)\n"),
				pset.progname);
		exit(EXIT_FAILURE);
	}
	tmp = strdup(string);
	if (!tmp)
	{
		psql_error("out of memory\n");
		exit(EXIT_FAILURE);
	}
	return tmp;
}
开发者ID:GisKook,项目名称:Gis,代码行数:22,代码来源:common.c


示例9: echo_hook

static void
echo_hook(const char *newval)
{
    if (newval == NULL)
        pset.echo = PSQL_ECHO_NONE;
    else if (pg_strcasecmp(newval, "queries") == 0)
        pset.echo = PSQL_ECHO_QUERIES;
    else if (pg_strcasecmp(newval, "errors") == 0)
        pset.echo = PSQL_ECHO_ERRORS;
    else if (pg_strcasecmp(newval, "all") == 0)
        pset.echo = PSQL_ECHO_ALL;
    else if (pg_strcasecmp(newval, "none") == 0)
        pset.echo = PSQL_ECHO_NONE;
    else
    {
        psql_error("unrecognized value \"%s\" for \"%s\"; assuming \"%s\"\n",
                   newval, "ECHO", "none");
        pset.echo = PSQL_ECHO_NONE;
    }
}
开发者ID:stalkerg,项目名称:postgres_cpp,代码行数:20,代码来源:startup.c


示例10: comp_keyword_case_hook

static void
comp_keyword_case_hook(const char *newval)
{
    if (newval == NULL)
        pset.comp_case = PSQL_COMP_CASE_PRESERVE_UPPER;
    else if (pg_strcasecmp(newval, "preserve-upper") == 0)
        pset.comp_case = PSQL_COMP_CASE_PRESERVE_UPPER;
    else if (pg_strcasecmp(newval, "preserve-lower") == 0)
        pset.comp_case = PSQL_COMP_CASE_PRESERVE_LOWER;
    else if (pg_strcasecmp(newval, "upper") == 0)
        pset.comp_case = PSQL_COMP_CASE_UPPER;
    else if (pg_strcasecmp(newval, "lower") == 0)
        pset.comp_case = PSQL_COMP_CASE_LOWER;
    else
    {
        psql_error("unrecognized value \"%s\" for \"%s\"; assuming \"%s\"\n",
                   newval, "COMP_KEYWORD_CASE", "preserve-upper");
        pset.comp_case = PSQL_COMP_CASE_PRESERVE_UPPER;
    }
}
开发者ID:stalkerg,项目名称:postgres_cpp,代码行数:20,代码来源:startup.c


示例11: histcontrol_hook

static void
histcontrol_hook(const char *newval)
{
    if (newval == NULL)
        pset.histcontrol = hctl_none;
    else if (pg_strcasecmp(newval, "ignorespace") == 0)
        pset.histcontrol = hctl_ignorespace;
    else if (pg_strcasecmp(newval, "ignoredups") == 0)
        pset.histcontrol = hctl_ignoredups;
    else if (pg_strcasecmp(newval, "ignoreboth") == 0)
        pset.histcontrol = hctl_ignoreboth;
    else if (pg_strcasecmp(newval, "none") == 0)
        pset.histcontrol = hctl_none;
    else
    {
        psql_error("unrecognized value \"%s\" for \"%s\"; assuming \"%s\"\n",
                   newval, "HISTCONTROL", "none");
        pset.histcontrol = hctl_none;
    }
}
开发者ID:stalkerg,项目名称:postgres_cpp,代码行数:20,代码来源:startup.c


示例12: verbosity_hook

static void
verbosity_hook(const char *newval)
{
    if (newval == NULL)
        pset.verbosity = PQERRORS_DEFAULT;
    else if (pg_strcasecmp(newval, "default") == 0)
        pset.verbosity = PQERRORS_DEFAULT;
    else if (pg_strcasecmp(newval, "terse") == 0)
        pset.verbosity = PQERRORS_TERSE;
    else if (pg_strcasecmp(newval, "verbose") == 0)
        pset.verbosity = PQERRORS_VERBOSE;
    else
    {
        psql_error("unrecognized value \"%s\" for \"%s\"; assuming \"%s\"\n",
                   newval, "VERBOSITY", "default");
        pset.verbosity = PQERRORS_DEFAULT;
    }

    if (pset.db)
        PQsetErrorVerbosity(pset.db, pset.verbosity);
}
开发者ID:stalkerg,项目名称:postgres_cpp,代码行数:21,代码来源:startup.c


示例13: show_context_hook

static void
show_context_hook(const char *newval)
{
    if (newval == NULL)
        pset.show_context = PQSHOW_CONTEXT_ERRORS;
    else if (pg_strcasecmp(newval, "never") == 0)
        pset.show_context = PQSHOW_CONTEXT_NEVER;
    else if (pg_strcasecmp(newval, "errors") == 0)
        pset.show_context = PQSHOW_CONTEXT_ERRORS;
    else if (pg_strcasecmp(newval, "always") == 0)
        pset.show_context = PQSHOW_CONTEXT_ALWAYS;
    else
    {
        psql_error("unrecognized value \"%s\" for \"%s\"; assuming \"%s\"\n",
                   newval, "SHOW_CONTEXT", "errors");
        pset.show_context = PQSHOW_CONTEXT_ERRORS;
    }

    if (pset.db)
        PQsetErrorContextVisibility(pset.db, pset.show_context);
}
开发者ID:stalkerg,项目名称:postgres_cpp,代码行数:21,代码来源:startup.c


示例14: do_shell

static bool
do_shell(const char *command)
{
	int			result;

	if (!command)
	{
		char	   *sys;
		const char *shellName;

		shellName = getenv("SHELL");
#ifdef WIN32
		if (shellName == NULL)
			shellName = getenv("COMSPEC");
#endif
		if (shellName == NULL)
			shellName = DEFAULT_SHELL;

		sys = pg_malloc(strlen(shellName) + 16);
#ifndef WIN32
		sprintf(sys,
		/* See EDITOR handling comment for an explaination */
				"exec %s", shellName);
#else
		/* See EDITOR handling comment for an explaination */
		sprintf(sys, SYSTEMQUOTE "\"%s\"" SYSTEMQUOTE, shellName);
#endif
		result = system(sys);
		free(sys);
	}
	else
		result = system(command);

	if (result == 127 || result == -1)
	{
		psql_error("\\!: failed\n");
		return false;
	}
	return true;
}
开发者ID:50wu,项目名称:gpdb,代码行数:40,代码来源:command.c


示例15: ParseVariableBool

/*
 * Try to interpret "value" as a boolean value, and if successful,
 * store it in *result.  Otherwise don't clobber *result.
 *
 * Valid values are: true, false, yes, no, on, off, 1, 0; as well as unique
 * prefixes thereof.
 *
 * "name" is the name of the variable we're assigning to, to use in error
 * report if any.  Pass name == NULL to suppress the error report.
 *
 * Return true when "value" is syntactically valid, false otherwise.
 */
bool
ParseVariableBool(const char *value, const char *name, bool *result)
{
	size_t		len;
	bool		valid = true;

	/* Treat "unset" as an empty string, which will lead to error below */
	if (value == NULL)
		value = "";

	len = strlen(value);

	if (len > 0 && pg_strncasecmp(value, "true", len) == 0)
		*result = true;
	else if (len > 0 && pg_strncasecmp(value, "false", len) == 0)
		*result = false;
	else if (len > 0 && pg_strncasecmp(value, "yes", len) == 0)
		*result = true;
	else if (len > 0 && pg_strncasecmp(value, "no", len) == 0)
		*result = false;
	/* 'o' is not unique enough */
	else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
		*result = true;
	else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
		*result = false;
	else if (pg_strcasecmp(value, "1") == 0)
		*result = true;
	else if (pg_strcasecmp(value, "0") == 0)
		*result = false;
	else
	{
		/* string is not recognized; don't clobber *result */
		if (name)
			psql_error("unrecognized value \"%s\" for \"%s\": boolean expected\n",
					   value, name);
		valid = false;
	}
	return valid;
}
开发者ID:BertrandAreal,项目名称:postgres,代码行数:51,代码来源:variables.c


示例16: AcceptResult

/*
 * AcceptResult
 *
 * Checks whether a result is valid, giving an error message if necessary;
 * resets cancelConn as needed, and ensures that the connection to the backend
 * is still up.
 *
 * Returns true for valid result, false for error state.
 */
static bool
AcceptResult(const PGresult *result)
{
	bool		OK = true;

	ResetCancelConn();

	if (!result)
		OK = false;
	else
		switch (PQresultStatus(result))
		{
			case PGRES_COMMAND_OK:
			case PGRES_TUPLES_OK:
			case PGRES_EMPTY_QUERY:
			case PGRES_COPY_IN:
				/* Fine, do nothing */
				break;

			case PGRES_COPY_OUT:
				/* keep cancel connection for copy out state */
				SetCancelConn();
				break;

			default:
				OK = false;
				break;
		}

	if (!OK)
	{
		psql_error("%s", PQerrorMessage(pset.db));
		CheckConnection();
	}

	return OK;
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:46,代码来源:common.c


示例17: ParseVariableBool

/*
 * Try to interpret value as boolean value.  Valid values are: true,
 * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
 */
bool
ParseVariableBool(const char *value)
{
	size_t		len;

	if (value == NULL)
		return false;			/* not set -> assume "off" */

	len = strlen(value);

	if (pg_strncasecmp(value, "true", len) == 0)
		return true;
	else if (pg_strncasecmp(value, "false", len) == 0)
		return false;
	else if (pg_strncasecmp(value, "yes", len) == 0)
		return true;
	else if (pg_strncasecmp(value, "no", len) == 0)
		return false;
	/* 'o' is not unique enough */
	else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
		return true;
	else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
		return false;
	else if (pg_strcasecmp(value, "1") == 0)
		return true;
	else if (pg_strcasecmp(value, "0") == 0)
		return false;
	else
	{
		/* NULL is treated as false, so a non-matching value is 'true' */
		psql_error("unrecognized boolean value; assuming \"on\".\n");
		return true;
	}
	/* suppress compiler warning */
	return true;
}
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:40,代码来源:variables.c


示例18: minimal_error_message

/*
 * Report just the primary error; this is to avoid cluttering the output
 * with, for instance, a redisplay of the internally generated query
 */
static void
minimal_error_message(PGresult *res)
{
	PQExpBuffer msg;
	const char *fld;

	msg = createPQExpBuffer();

	fld = PQresultErrorField(res, PG_DIAG_SEVERITY);
	if (fld)
		printfPQExpBuffer(msg, "%s:  ", fld);
	else
		printfPQExpBuffer(msg, "ERROR:  ");
	fld = PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY);
	if (fld)
		appendPQExpBufferStr(msg, fld);
	else
		appendPQExpBufferStr(msg, "(not available)");
	appendPQExpBufferStr(msg, "\n");

	psql_error("%s", msg->data);

	destroyPQExpBuffer(msg);
}
开发者ID:50wu,项目名称:gpdb,代码行数:28,代码来源:command.c


示例19: do_edit

/* call this one */
static bool
do_edit(const char *filename_arg, PQExpBuffer query_buf, bool *edited)
{
	char		fnametmp[MAXPGPATH];
	FILE	   *stream = NULL;
	const char *fname;
	bool		error = false;
	int			fd;

	struct stat before,
				after;

	if (filename_arg)
		fname = filename_arg;
	else
	{
		/* make a temp file to edit */
#ifndef WIN32
		const char *tmpdir = getenv("TMPDIR");

		if (!tmpdir)
			tmpdir = "/tmp";
#else
		char		tmpdir[MAXPGPATH];
		int			ret;

		ret = GetTempPath(MAXPGPATH, tmpdir);
		if (ret == 0 || ret > MAXPGPATH)
		{
			psql_error("cannot locate temporary directory: %s\n",
					   !ret ? strerror(errno) : "");
			return false;
		}

		/*
		 * No canonicalize_path() here. EDIT.EXE run from CMD.EXE prepends the
		 * current directory to the supplied path unless we use only
		 * backslashes, so we do that.
		 */
#endif
#ifndef WIN32
		snprintf(fnametmp, sizeof(fnametmp), "%s%spsql.edit.%d", tmpdir,
				 "/", (int) getpid());
#else
		snprintf(fnametmp, sizeof(fnametmp), "%s%spsql.edit.%d", tmpdir,
			   "" /* trailing separator already present */ , (int) getpid());
#endif

		fname = (const char *) fnametmp;

		fd = open(fname, O_WRONLY | O_CREAT | O_EXCL, 0600);
		if (fd != -1)
			stream = fdopen(fd, "w");

		if (fd == -1 || !stream)
		{
			psql_error("could not open temporary file \"%s\": %s\n", fname, strerror(errno));
			error = true;
		}
		else
		{
			unsigned int ql = query_buf->len;

			if (ql == 0 || query_buf->data[ql - 1] != '\n')
			{
				appendPQExpBufferChar(query_buf, '\n');
				ql++;
			}

			if (fwrite(query_buf->data, 1, ql, stream) != ql)
			{
				psql_error("%s: %s\n", fname, strerror(errno));
				fclose(stream);
				remove(fname);
				error = true;
			}
			else if (fclose(stream) != 0)
			{
				psql_error("%s: %s\n", fname, strerror(errno));
				remove(fname);
				error = true;
			}
		}
	}

	if (!error && stat(fname, &before) != 0)
	{
		psql_error("%s: %s\n", fname, strerror(errno));
		error = true;
	}

	/* call editor */
	if (!error)
		error = !editFile(fname);

	if (!error && stat(fname, &after) != 0)
	{
		psql_error("%s: %s\n", fname, strerror(errno));
		error = true;
//.........这里部分代码省略.........
开发者ID:50wu,项目名称:gpdb,代码行数:101,代码来源:command.c


示例20: process_file

/*
 * process_file
 *
 * Read commands from filename and then them to the main processing loop
 * Handler for \i, but can be used for other things as well.  Returns
 * MainLoop() error code.
 */
int
process_file(char *filename, bool single_txn)
{
	FILE	   *fd;
	int			result;
	char	   *oldfilename;
	PGresult   *res;

	if (!filename)
		return EXIT_FAILURE;

	if (strcmp(filename, "-") != 0)
	{
		canonicalize_path(filename);
		fd = fopen(filename, PG_BINARY_R);
	}
	else
		fd = stdin;

	if (!fd)
	{
		psql_error("%s: %s\n", filename, strerror(errno));
		return EXIT_FAILURE;
	}

	oldfilename = pset.inputfile;
	pset.inputfile = filename;

	if (single_txn)
	{
		if ((res = PSQLexec("BEGIN", false)) == NULL)
		{
			if (pset.on_error_stop)
			{
				result = EXIT_USER;
				goto error;
			}
		}
		else
			PQclear(res);
	}

	result = MainLoop(fd);

	if (single_txn)
	{
		if ((res = PSQLexec("COMMIT", false)) == NULL)
		{
			if (pset.on_error_stop)
			{
				result = EXIT_USER;
				goto error;
			}
		}
		else
			PQclear(res);
	}

error:
	if (fd != stdin)
	fclose(fd);
	pset.inputfile = oldfilename;
	return result;
}
开发者ID:50wu,项目名称:gpdb,代码行数:71,代码来源:command.c



注:本文中的psql_error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pstdout_fprintf函数代码示例发布时间:2022-05-30
下一篇:
C++ psprintf函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap