本文整理汇总了C++中createPQExpBuffer函数的典型用法代码示例。如果您正苦于以下问题:C++ createPQExpBuffer函数的具体用法?C++ createPQExpBuffer怎么用?C++ createPQExpBuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createPQExpBuffer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: runPgDump
/*
* Run pg_dump on dbname.
*/
static int
runPgDump(const char *dbname)
{
PQExpBuffer cmd = createPQExpBuffer();
int ret;
appendPQExpBuffer(cmd, SYSTEMQUOTE "\"%s\" %s", pg_dump_bin,
pgdumpopts->data);
/*
* If we have a filename, use the undocumented plain-append pg_dump
* format.
*/
if (filename)
appendPQExpBuffer(cmd, " -Fa ");
else
appendPQExpBuffer(cmd, " -Fp ");
doShellQuoting(cmd, dbname);
appendPQExpBuffer(cmd, "%s", SYSTEMQUOTE);
if (verbose)
fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data);
fflush(stdout);
fflush(stderr);
ret = system(cmd->data);
destroyPQExpBuffer(cmd);
return ret;
}
开发者ID:joshuawingfield,项目名称:pgsql,代码行数:37,代码来源:pg_dumpall.c
示例2: lookup_function_oid
/*
* This function takes a function description, e.g. "x" or "x(int)", and
* issues a query on the given connection to retrieve the function's OID
* using a cast to regproc or regprocedure (as appropriate). The result,
* if there is one, is returned at *foid. Note that we'll fail if the
* function doesn't exist OR if there are multiple matching candidates
* OR if there's something syntactically wrong with the function description;
* unfortunately it can be hard to tell the difference.
*/
static bool
lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
{
bool result = true;
PQExpBuffer query;
PGresult *res;
query = createPQExpBuffer();
printfPQExpBuffer(query, "SELECT ");
appendStringLiteralConn(query, desc, conn);
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
strchr(desc, '(') ? "regprocedure" : "regproc");
res = PQexec(conn, query->data);
if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
*foid = atooid(PQgetvalue(res, 0, 0));
else
{
minimal_error_message(res);
result = false;
}
PQclear(res);
destroyPQExpBuffer(query);
return result;
}
开发者ID:50wu,项目名称:gpdb,代码行数:36,代码来源:command.c
示例3: makeAlterConfigCommand
/*
* Helper function for dumpXXXConfig().
*/
static void
makeAlterConfigCommand(const char *arrayitem, const char *type, const char *name)
{
char *pos;
char *mine;
PQExpBuffer buf = createPQExpBuffer();
mine = strdup(arrayitem);
pos = strchr(mine, '=');
if (pos == NULL)
return;
*pos = 0;
appendPQExpBuffer(buf, "ALTER %s %s ", type, fmtId(name));
appendPQExpBuffer(buf, "SET %s TO ", fmtId(mine));
/*
* Some GUC variable names are 'LIST' type and hence must not be quoted.
*/
if (pg_strcasecmp(mine, "DateStyle") == 0
|| pg_strcasecmp(mine, "search_path") == 0)
appendPQExpBuffer(buf, "%s", pos + 1);
else
appendStringLiteral(buf, pos + 1, false);
appendPQExpBuffer(buf, ";\n");
printf("%s", buf->data);
destroyPQExpBuffer(buf);
free(mine);
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:33,代码来源:pg_dumpall.c
示例4: DoCancelNotifyListen
/*
* DoCancelNotifyListen: This function executes a LISTEN or a NOTIFY command, with
* name in the format N%s_%d_%d, where the %s is replaced by the CDBDumpKey,
* and the 2 integers are the contentid and dbid.
*/
void
DoCancelNotifyListen(PGconn *pConn,
bool bListen,
const char *pszCDBDumpKey,
int role_id,
int db_id,
int target_db_id,
const char *pszSuffix)
{
PGresult *pRes;
PQExpBuffer q = createPQExpBuffer();
char *pszCmd = bListen ? "LISTEN" : "NOTIFY";
appendPQExpBuffer(q, "%s N%s_%d_%d",
pszCmd, pszCDBDumpKey, role_id, db_id);
/* this is valid only for restore operations */
if (target_db_id != -1)
appendPQExpBuffer(q, "_T%d", target_db_id);
if (pszSuffix != NULL)
appendPQExpBuffer(q, "_%s", pszSuffix);
pRes = PQexec(pConn, q->data);
if (pRes == NULL || PQresultStatus(pRes) != PGRES_COMMAND_OK)
{
mpp_err_msg_cache("%s command failed for for backup key %s, instid %d, segid %d failed : %s",
pszCmd, pszCDBDumpKey, role_id, db_id, PQerrorMessage(pConn));
}
PQclear(pRes);
destroyPQExpBuffer(q);
}
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:38,代码来源:cdb_dump_util.c
示例5: dumpGroups
/*
* Dump group memberships from a pre-8.1 server. It's annoying that we
* can't share any useful amount of code with the post-8.1 case, but
* the catalog representations are too different.
*
* Note: we expect dumpRoles already created all the roles, but there is
* no membership yet.
*/
static void
dumpGroups(PGconn *conn)
{
PQExpBuffer buf = createPQExpBuffer();
PGresult *res;
int i;
res = executeQuery(conn,
"SELECT groname, grolist FROM pg_group ORDER BY 1");
if (PQntuples(res) > 0)
printf("--\n-- Role memberships\n--\n\n");
for (i = 0; i < PQntuples(res); i++)
{
char *groname = PQgetvalue(res, i, 0);
char *grolist = PQgetvalue(res, i, 1);
PGresult *res2;
int j;
/*
* Array representation is {1,2,3} ... convert to (1,2,3)
*/
if (strlen(grolist) < 3)
continue;
grolist = strdup(grolist);
grolist[0] = '(';
grolist[strlen(grolist) - 1] = ')';
printfPQExpBuffer(buf,
"SELECT usename FROM pg_shadow "
"WHERE usesysid IN %s ORDER BY 1",
grolist);
free(grolist);
res2 = executeQuery(conn, buf->data);
for (j = 0; j < PQntuples(res2); j++)
{
char *usename = PQgetvalue(res2, j, 0);
/*
* Don't try to grant a role to itself; can happen if old
* installation has identically named user and group.
*/
if (strcmp(groname, usename) == 0)
continue;
printf("GRANT %s", fmtId(groname));
printf(" TO %s;\n", fmtId(usename));
}
PQclear(res2);
}
PQclear(res);
destroyPQExpBuffer(buf);
printf("\n\n");
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:68,代码来源:pg_dumpall.c
示例6: dumpDbRoleConfig
/*
* Dump user-and-database-specific configuration
*/
static void
dumpDbRoleConfig(PGconn *conn)
{
PQExpBuffer buf = createPQExpBuffer();
PGresult *res;
int i;
printfPQExpBuffer(buf, "SELECT rolname, datname, unnest(setconfig) "
"FROM pg_db_role_setting, pg_authid, pg_database "
"WHERE setrole = pg_authid.oid AND setdatabase = pg_database.oid");
res = executeQuery(conn, buf->data);
if (PQntuples(res) > 0)
{
fprintf(OPF, "--\n-- Per-Database Role Settings \n--\n\n");
for (i = 0; i < PQntuples(res); i++)
{
makeAlterConfigCommand(conn, PQgetvalue(res, i, 2),
"ROLE", PQgetvalue(res, i, 0),
"DATABASE", PQgetvalue(res, i, 1));
}
fprintf(OPF, "\n\n");
}
PQclear(res);
destroyPQExpBuffer(buf);
}
开发者ID:joshuawingfield,项目名称:pgsql,代码行数:32,代码来源:pg_dumpall.c
示例7: get_create_function_cmd
/*
* Fetches the "CREATE OR REPLACE FUNCTION ..." command that describes the
* function with the given OID. If successful, the result is stored in buf.
*/
static bool
get_create_function_cmd(PGconn *conn, Oid oid, PQExpBuffer buf)
{
bool result = true;
PQExpBuffer query;
PGresult *res;
query = createPQExpBuffer();
printfPQExpBuffer(query, "SELECT pg_catalog.pg_get_functiondef(%u)", oid);
res = PQexec(conn, query->data);
if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
{
resetPQExpBuffer(buf);
appendPQExpBufferStr(buf, PQgetvalue(res, 0, 0));
}
else
{
minimal_error_message(res);
result = false;
}
PQclear(res);
destroyPQExpBuffer(query);
return result;
}
开发者ID:50wu,项目名称:gpdb,代码行数:31,代码来源:command.c
示例8: dumpDatabaseConfig
/*
* Dump database-specific configuration
*/
static void
dumpDatabaseConfig(PGconn *conn, const char *dbname)
{
PQExpBuffer buf = createPQExpBuffer();
int count = 1;
for (;;)
{
PGresult *res;
printfPQExpBuffer(buf, "SELECT datconfig[%d] FROM pg_database WHERE datname = ", count);
appendStringLiteral(buf, dbname, true);
appendPQExpBuffer(buf, ";");
res = executeQuery(conn, buf->data);
if (!PQgetisnull(res, 0, 0))
{
makeAlterConfigCommand(PQgetvalue(res, 0, 0), "DATABASE", dbname);
PQclear(res);
count++;
}
else
{
PQclear(res);
break;
}
}
destroyPQExpBuffer(buf);
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:33,代码来源:pg_dumpall.c
示例9: appendStringLiteralDQ
/*
* Convert a string value to a dollar quoted literal and append it to
* the given buffer. If the dqprefix parameter is not NULL then the
* dollar quote delimiter will begin with that (after the opening $).
*
* No escaping is done at all on str, in compliance with the rules
* for parsing dollar quoted strings. Also, we need not worry about
* encoding issues.
*/
void
appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix)
{
static const char suffixes[] = "_XXXXXXX";
int nextchar = 0;
PQExpBuffer delimBuf = createPQExpBuffer();
/* start with $ + dqprefix if not NULL */
appendPQExpBufferChar(delimBuf, '$');
if (dqprefix)
appendPQExpBufferStr(delimBuf, dqprefix);
/*
* Make sure we choose a delimiter which (without the trailing $) is not
* present in the string being quoted. We don't check with the trailing $
* because a string ending in $foo must not be quoted with $foo$.
*/
while (strstr(str, delimBuf->data) != NULL)
{
appendPQExpBufferChar(delimBuf, suffixes[nextchar++]);
nextchar %= sizeof(suffixes) - 1;
}
/* add trailing $ */
appendPQExpBufferChar(delimBuf, '$');
/* quote it and we are all done */
appendPQExpBufferStr(buf, delimBuf->data);
appendPQExpBufferStr(buf, str);
appendPQExpBufferStr(buf, delimBuf->data);
destroyPQExpBuffer(delimBuf);
}
开发者ID:denishpatel,项目名称:postgres,代码行数:42,代码来源:dumputils.c
示例10: ExecuteSimpleCommands
/*
* Process non-COPY table data (that is, INSERT commands).
*
* The commands have been run together as one long string for compressibility,
* and we are receiving them in bufferloads with arbitrary boundaries, so we
* have to locate command boundaries and save partial commands across calls.
* All state must be kept in AH->sqlparse, not in local variables of this
* routine. We assume that AH->sqlparse was filled with zeroes when created.
*
* We have to lex the data to the extent of identifying literals and quoted
* identifiers, so that we can recognize statement-terminating semicolons.
* We assume that INSERT data will not contain SQL comments, E'' literals,
* or dollar-quoted strings, so this is much simpler than a full SQL lexer.
*
* Note: when restoring from a pre-9.0 dump file, this code is also used to
* process BLOB COMMENTS data, which has the same problem of containing
* multiple SQL commands that might be split across bufferloads. Fortunately,
* that data won't contain anything complicated to lex either.
*/
static void
ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
{
const char *qry = buf;
const char *eos = buf + bufLen;
/* initialize command buffer if first time through */
if (AH->sqlparse.curCmd == NULL)
AH->sqlparse.curCmd = createPQExpBuffer();
for (; qry < eos; qry++)
{
char ch = *qry;
/* For neatness, we skip any newlines between commands */
if (!(ch == '\n' && AH->sqlparse.curCmd->len == 0))
appendPQExpBufferChar(AH->sqlparse.curCmd, ch);
switch (AH->sqlparse.state)
{
case SQL_SCAN: /* Default state == 0, set in _allocAH */
if (ch == ';')
{
/*
* We've found the end of a statement. Send it and reset
* the buffer.
*/
ExecuteSqlCommand(AH, AH->sqlparse.curCmd->data,
"could not execute query");
resetPQExpBuffer(AH->sqlparse.curCmd);
}
else if (ch == '\'')
{
AH->sqlparse.state = SQL_IN_SINGLE_QUOTE;
AH->sqlparse.backSlash = false;
}
else if (ch == '"')
{
AH->sqlparse.state = SQL_IN_DOUBLE_QUOTE;
}
break;
case SQL_IN_SINGLE_QUOTE:
/* We needn't handle '' specially */
if (ch == '\'' && !AH->sqlparse.backSlash)
AH->sqlparse.state = SQL_SCAN;
else if (ch == '\\' && !AH->public__.std_strings)
AH->sqlparse.backSlash = !AH->sqlparse.backSlash;
else
AH->sqlparse.backSlash = false;
break;
case SQL_IN_DOUBLE_QUOTE:
/* We needn't handle "" specially */
if (ch == '"')
AH->sqlparse.state = SQL_SCAN;
break;
}
}
}
开发者ID:jarulraj,项目名称:postgres-cpp,代码行数:79,代码来源:pg_backup_db.c
示例11: buildDefaultACLCommands
/*
* Build ALTER DEFAULT PRIVILEGES command(s) for single pg_default_acl entry.
*
* type: the object type (TABLES, FUNCTIONS, etc)
* nspname: schema name, or NULL for global default privileges
* acls: the ACL string fetched from the database
* owner: username of privileges owner (will be passed through fmtId)
* remoteVersion: version of database
*
* Returns TRUE if okay, FALSE if could not parse the acl string.
* The resulting commands (if any) are appended to the contents of 'sql'.
*/
bool
buildDefaultACLCommands(const char *type, const char *nspname,
const char *acls, const char *owner,
int remoteVersion,
PQExpBuffer sql)
{
bool result;
PQExpBuffer prefix;
prefix = createPQExpBuffer();
/*
* We incorporate the target role directly into the command, rather than
* playing around with SET ROLE or anything like that. This is so that a
* permissions error leads to nothing happening, rather than changing
* default privileges for the wrong user.
*/
appendPQExpBuffer(prefix, "ALTER DEFAULT PRIVILEGES FOR ROLE %s ",
fmtId(owner));
if (nspname)
appendPQExpBuffer(prefix, "IN SCHEMA %s ", fmtId(nspname));
result = buildACLCommands("", NULL,
type, acls, owner,
prefix->data, remoteVersion,
sql);
destroyPQExpBuffer(prefix);
return result;
}
开发者ID:denishpatel,项目名称:postgres,代码行数:43,代码来源:dumputils.c
示例12: main
int
main(int argc, char** argv)
{
int c, i, optindex;
static struct option long_options[] = {
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
if (argc == 1 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-?"))
help();
while ((c = getopt_long(argc, argv, "h:p:U:",
long_options, &optindex)) != -1)
{
switch (c)
{
case 'h': /* host for tranlsting oids */
pghost = optarg;
break;
case 'p': /* port for translating oids */
pgport = optarg;
break;
case 'U': /* username for translating oids */
username = optarg;
break;
default:
fprintf(stderr, "Try \"changetrackingdump --help\" for more information.\n");
exit(1);
}
}
if(pghost)
{
conn = DBConnect(pghost, pgport, "template1", username);
}
dbQry = createPQExpBuffer();
for (i = optind; i < argc; i++)
{
char *fname = argv[i];
logFd = open(fname, O_RDONLY | PG_BINARY, 0);
if (logFd < 0)
{
perror(fname);
continue;
}
dumpChangeTracking(fname);
}
exit_gracefuly(0);
/* just to avoid a warning */
return 0;
}
开发者ID:asubramanya,项目名称:gpdb,代码行数:60,代码来源:changetrackingdump.c
示例13: dumpUserConfig
/*
* Dump user-specific configuration
*/
static void
dumpUserConfig(PGconn *conn, const char *username)
{
PQExpBuffer buf = createPQExpBuffer();
int count = 1;
for (;;)
{
PGresult *res;
if (server_version >= 80100)
printfPQExpBuffer(buf, "SELECT rolconfig[%d] FROM pg_authid WHERE rolname = ", count);
else
printfPQExpBuffer(buf, "SELECT useconfig[%d] FROM pg_shadow WHERE usename = ", count);
appendStringLiteral(buf, username, true);
res = executeQuery(conn, buf->data);
if (PQntuples(res) == 1 &&
!PQgetisnull(res, 0, 0))
{
makeAlterConfigCommand(PQgetvalue(res, 0, 0), "ROLE", username);
PQclear(res);
count++;
}
else
{
PQclear(res);
break;
}
}
destroyPQExpBuffer(buf);
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:36,代码来源:pg_dumpall.c
示例14: gets_fromFile
/*
* gets_fromFile
*
* Gets a line of noninteractive input from a file (which could be stdin).
* The result is a malloc'd string, or NULL on EOF or input error.
*
* Caller *must* have set up sigint_interrupt_jmp before calling.
*
* Note: we re-use a static PQExpBuffer for each call. This is to avoid
* leaking memory if interrupted by SIGINT.
*/
char *
gets_fromFile(FILE *source)
{
static PQExpBuffer buffer = NULL;
char line[1024];
if (buffer == NULL) /* first time through? */
buffer = createPQExpBuffer();
else
resetPQExpBuffer(buffer);
for (;;)
{
char *result;
/* Enable SIGINT to longjmp to sigint_interrupt_jmp */
sigint_interrupt_enabled = true;
/* Get some data */
result = fgets(line, sizeof(line), source);
/* Disable SIGINT again */
sigint_interrupt_enabled = false;
/* EOF or error? */
if (result == NULL)
{
if (ferror(source))
{
psql_error("could not read from input file: %s\n",
strerror(errno));
return NULL;
}
break;
}
appendPQExpBufferStr(buffer, line);
if (PQExpBufferBroken(buffer))
{
psql_error("out of memory\n");
return NULL;
}
/* EOL? */
if (buffer->data[buffer->len - 1] == '\n')
{
buffer->data[buffer->len - 1] = '\0';
return pg_strdup(buffer->data);
}
}
if (buffer->len > 0) /* EOF after reading some bufferload(s) */
return pg_strdup(buffer->data);
/* EOF, so return null */
return NULL;
}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:70,代码来源:input.c
示例15: ReadBackendBackupFileError
/*
* ReadBackendBackupFile: This function calls the backend function gp_read_backup_file
* which reads the contents out of the appropriate file on the database server.
* If the call succeeds/fails, it returns status code 0/-1, an appropriate error string
* is inserted into the buffer of pszRtn.
*/
int
ReadBackendBackupFileError(PGconn *pConn, const char *pszBackupDirectory, const char *pszKey,
BackupFileType fileType, const char *progName, PQExpBuffer pszRtn)
{
char *pszFileType;
PQExpBuffer Qry;
PGresult *pRes;
int status = 0;
switch (fileType)
{
case BFT_BACKUP:
pszFileType = "0";
break;
case BFT_BACKUP_STATUS:
pszFileType = "1";
break;
case BFT_RESTORE_STATUS:
pszFileType = "2";
break;
default:
appendPQExpBuffer(pszRtn, "Unknown file type passed to ReadBackendBackupFile");
mpp_err_msg("ERROR", progName, " %s: %d\n", pszRtn->data, fileType);
return -1;
}
Qry = createPQExpBuffer();
appendPQExpBuffer(Qry, "SELECT * FROM gp_read_backup_file('%s', '%s', %s)",
StringNotNull(pszBackupDirectory, ""),
StringNotNull(pszKey, ""),
pszFileType);
pRes = PQexec(pConn, Qry->data);
if (!pRes || PQresultStatus(pRes) != PGRES_TUPLES_OK || PQntuples(pRes) == 0)
{
appendPQExpBuffer(pszRtn, "Error executing query %s : %s\n", Qry->data, PQerrorMessage(pConn));
mpp_err_msg_cache("ERROR", progName, pszRtn->data);
status = -1;
}
else
{
char *res = PQgetvalue(pRes, 0, 0);
appendPQExpBufferStr(pszRtn, res);
if (strstr(res, "ERROR:") || strstr(res, "[ERROR]"))
{
status = -1;
}
}
PQclear(pRes);
destroyPQExpBuffer(Qry);
return status;
}
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:61,代码来源:cdb_dump_util.c
示例16: runPgDump
/*
* Run pg_dump on dbname.
*/
static int
runPgDump(const char *dbname)
{
PQExpBuffer cmd = createPQExpBuffer();
const char *p;
int ret;
/*
* Win32 has to use double-quotes for args, rather than single quotes.
* Strangely enough, this is the only place we pass a database name on the
* command line, except "postgres" which doesn't need quoting.
*/
#ifndef WIN32
appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin,
#else
appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp \"", SYSTEMQUOTE, pg_dump_bin,
#endif
pgdumpopts->data);
/* Shell quoting is not quite like SQL quoting, so can't use fmtId */
for (p = dbname; *p; p++)
{
#ifndef WIN32
if (*p == '\'')
appendPQExpBuffer(cmd, "'\"'\"'");
#else
if (*p == '"')
appendPQExpBuffer(cmd, "\\\"");
#endif
else
appendPQExpBufferChar(cmd, *p);
}
#ifndef WIN32
appendPQExpBufferChar(cmd, '\'');
#else
appendPQExpBufferChar(cmd, '"');
#endif
appendPQExpBuffer(cmd, "%s", SYSTEMQUOTE);
if (verbose)
fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data);
fflush(stdout);
fflush(stderr);
ret = system(cmd->data);
destroyPQExpBuffer(cmd);
return ret;
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:56,代码来源:pg_dumpall.c
示例17: dump_rows
/*
* Issue a query on a catalog table, and produce calls to a preassign support
* function from the result set.
*
* The output is a string, containing SQL calls like:
*
* SELECT binary_upgrade.preassign_*_oid(<oid>, <other args);
*
* 'funcname' is the "preassign_*_oid" function to use.
* 'sql' is the query to issue. The columns of the result set are passed as
* arguments to the preassign-support function.
*
*/
static void
dump_rows(migratorContext *ctx, PQExpBuffer buf, FILE *file, PGconn *conn,
const char *sql, const char *funcname)
{
int ntups;
int ncols;
int row;
int col;
PGresult *res;
if (file != NULL)
buf = createPQExpBuffer();
/*
* Add a WHERE or AND clause to filter out built-in objects.
*
* If the query contains "UNION ALL", then it's the caller's
* responsibility to do the filtering. This special case is for the
* one more complicated query in get_old_oids() function; all the
* other queries are very simple ones.
*/
if (strstr(sql, "WHERE ") == NULL)
res = executeQueryOrDie(ctx, conn, "%s WHERE oid >= %u", sql, FirstNormalObjectId);
else if (strstr(sql, "UNION ALL") == NULL)
res = executeQueryOrDie(ctx, conn, "%s AND oid >= %u", sql, FirstNormalObjectId);
else
res = executeQueryOrDie(ctx, conn, "%s", sql);
ntups = PQntuples(res);
ncols = PQnfields(res);
for (row = 0; row < ntups; row++)
{
appendPQExpBuffer(buf, "SELECT binary_upgrade.%s('%s'",
funcname,
simple_escape_literal(ctx, conn, PQgetvalue(res, row, 0)));
for (col = 1; col < ncols; col++)
appendPQExpBuffer(buf, ", '%s'",
simple_escape_literal(ctx, conn, PQgetvalue(res, row, col)));
appendPQExpBuffer(buf, ");\n");
if (file)
{
fwrite(buf->data, buf->len, 1, file);
resetPQExpBuffer(buf);
}
}
PQclear(res);
if (file != NULL)
destroyPQExpBuffer(buf);
}
开发者ID:phan-pivotal,项目名称:gpdb,代码行数:66,代码来源:oid_dump.c
示例18: get_old_oids
/*
* Read all pg_type and pg_class OIDs from old cluster, into the DbInfo structs.
*
* The OIDs of types and relations need to be preserved from the old cluster.
* In the upstream, we use a different mechanism, integrated into pg_dump, for
* this, but things are a bit more complicated in GPDB, because of partitions,
* auxiliary AO segment tables, and bitmap index LOV tables. So we use a
* different strategy.
*/
void
get_old_oids(migratorContext *ctx)
{
int dbnum;
prep_status(ctx, "Exporting object OIDs from the old cluster");
for (dbnum = 0; dbnum < ctx->old.dbarr.ndbs; dbnum++)
{
DbInfo *olddb = &ctx->old.dbarr.dbs[dbnum];
PGconn *conn;
PQExpBuffer buf = createPQExpBuffer();
conn = connectToServer(ctx, olddb->db_name, CLUSTER_OLD);
PQclear(executeQueryOrDie(ctx, conn, "set search_path='pg_catalog';"));
dump_rows(ctx, buf, NULL, conn,
"SELECT oid, nspname FROM pg_namespace",
"preassign_namespace_oid");
dump_rows(ctx, buf, NULL, conn,
"SELECT oid, typname, typnamespace FROM pg_type",
"preassign_type_oid");
/*
* A table's TOAST table might not be named the usual way in the old
* cluster, so dump it according to the way it will be named when created
* in the new cluster, instead of the current name.
*
* For example, "alter_distpol_g_char_11_false_false", in the regression
* database. FIXME: I don't quite understand how that happens.
*
* We don't preserve the OIDs of AO segment tables.
*/
dump_rows(ctx, buf, NULL, conn,
"SELECT oid, relname, relnamespace FROM pg_class "
" WHERE relnamespace NOT IN "
" ( " CppAsString2(PG_TOAST_NAMESPACE) ", "
"" CppAsString2(PG_AOSEGMENT_NAMESPACE) ") "
" AND oid >= " CppAsString2(FirstNormalObjectId) " "
"UNION ALL "
"SELECT reltoastrelid, 'pg_toast_' || oid, " CppAsString2(PG_TOAST_NAMESPACE) " FROM pg_class WHERE reltoastrelid <> 0 AND oid >= " CppAsString2(FirstNormalObjectId) " ",
"preassign_relation_oid");
PQfinish(conn);
olddb->reserved_oids = buf->data;
}
check_ok(ctx);
}
开发者ID:phan-pivotal,项目名称:gpdb,代码行数:59,代码来源:oid_dump.c
示例19: ReadBackendBackupFile
/*
* ReadBackendBackupFile: This function calls the backend function gp_read_backup_file
* which reads the contents out of the appropriate file on the database server.
* If the call fails, it returns NULL. The returned pointer must be freed by the caller.
*/
char *
ReadBackendBackupFile(PGconn *pConn, const char *pszBackupDirectory, const char *pszKey, BackupFileType fileType, const char *progName)
{
char *pszRtn = NULL;
char *pszFileType;
PQExpBuffer Qry;
PGresult *pRes;
switch (fileType)
{
case BFT_BACKUP:
pszFileType = "0";
break;
case BFT_BACKUP_STATUS:
pszFileType = "1";
break;
case BFT_RESTORE_STATUS:
pszFileType = "2";
break;
default:
mpp_err_msg("ERROR", progName, "Unknown file type passed to ReadBackendBackupFile : %d\n", fileType);
return NULL;
}
Qry = createPQExpBuffer();
appendPQExpBuffer(Qry, "SELECT * FROM gp_read_backup_file('%s', '%s', %s)",
StringNotNull(pszBackupDirectory, ""),
StringNotNull(pszKey, ""),
pszFileType);
pRes = PQexec(pConn, Qry->data);
if (!pRes || PQresultStatus(pRes) != PGRES_TUPLES_OK || PQntuples(pRes) == 0)
{
mpp_err_msg_cache("ERROR", progName, "Error executing query %s : %s\n",
Qry->data,
PQerrorMessage(pConn));
}
else
{
pszRtn = strdup(PQgetvalue(pRes, 0, 0));
}
PQclear(pRes);
destroyPQExpBuffer(Qry);
return pszRtn;
}
开发者ID:hellower,项目名称:gpdb,代码行数:52,代码来源:cdb_dump_util.c
示例20: gets_fromFile
/*
* gets_fromFile
*
* Gets a line of noninteractive input from a file (which could be stdin).
* The result is a malloc'd string.
*
* Caller *must* have set up sigint_interrupt_jmp before calling.
*
* Note: we re-use a static PQExpBuffer for each call. This is to avoid
* leaking memory if interrupted by SIGINT.
*/
char *
gets_fromFile(FILE *source)
{
static PQExpBuffer buffer = NULL;
char line[1024];
if (buffer == NULL) /* first time through? */
buffer = createPQExpBuffer();
else
resetPQExpBuffer(buffer);
for (;;)
{
char *result;
/* Enable SIGINT to longjmp to sigint_interrupt_jmp */
sigint_interrupt_enabled = true;
/* Get some data */
result = fgets(line, sizeof(line), source);
/* Disable SIGINT again */
sigint_interrupt_enabled = false;
/* EOF? */
if (result == NULL)
break;
appendPQExpBufferStr(buffer, line);
/* EOL? */
if (buffer->data[buffer->len - 1] == '\n')
{
buffer->data[buffer->len - 1] = '\0';
return pg_strdup(buffer->data);
}
}
if (buffer->len > 0) /* EOF after reading some bufferload(s) */
return pg_strdup(buffer->data);
/* EOF, so return null */
return NULL;
}
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:56,代码来源:input.c
注:本文中的createPQExpBuffer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论