本文整理汇总了C++中psql_error函数的典型用法代码示例。如果您正苦于以下问题:C++ psql_error函数的具体用法?C++ psql_error怎么用?C++ psql_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了psql_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}