mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
Reimplement pg_dumpall in C. Currently no change in functionality,
except that it's more robust, reconnects less often, and is NLS'ed.
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.55 2002/08/20 17:54:44 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.56 2002/08/27 18:57:26 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -24,14 +24,14 @@
|
||||
#include "pg_dump.h"
|
||||
#include "pg_backup_archiver.h"
|
||||
#include "pg_backup_db.h"
|
||||
#include "dumputils.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h> /* for dup */
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pqexpbuffer.h"
|
||||
#include "libpq/libpq-fs.h"
|
||||
#include "parser/keywords.h"
|
||||
|
||||
|
||||
typedef enum _teReqs_
|
||||
@ -2105,117 +2105,6 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Quotes input string if it's not a legitimate SQL identifier as-is.
|
||||
*
|
||||
* Note that the returned string must be used before calling fmtId again,
|
||||
* since we re-use the same return buffer each time. Non-reentrant but
|
||||
* avoids memory leakage.
|
||||
*/
|
||||
const char *
|
||||
fmtId(const char *rawid)
|
||||
{
|
||||
static PQExpBuffer id_return = NULL;
|
||||
const char *cp;
|
||||
bool need_quotes = false;
|
||||
|
||||
if (id_return) /* first time through? */
|
||||
resetPQExpBuffer(id_return);
|
||||
else
|
||||
id_return = createPQExpBuffer();
|
||||
|
||||
/* These checks need to match the identifier production in scan.l.
|
||||
* Don't use islower() etc. */
|
||||
|
||||
if (ScanKeywordLookup(rawid))
|
||||
need_quotes = true;
|
||||
/* slightly different rules for first character */
|
||||
else if (!((rawid[0] >= 'a' && rawid[0] <= 'z') || rawid[0] == '_'))
|
||||
need_quotes = true;
|
||||
else
|
||||
{
|
||||
/* otherwise check the entire string */
|
||||
for (cp = rawid; *cp; cp++)
|
||||
{
|
||||
if (!((*cp >= 'a' && *cp <= 'z')
|
||||
|| (*cp >= '0' && *cp <= '9')
|
||||
|| (*cp == '_')))
|
||||
{
|
||||
need_quotes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!need_quotes)
|
||||
{
|
||||
/* no quoting needed */
|
||||
appendPQExpBufferStr(id_return, rawid);
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBufferChar(id_return, '\"');
|
||||
for (cp = rawid; *cp; cp++)
|
||||
{
|
||||
/*
|
||||
* Did we find a double-quote in the string? Then make this a
|
||||
* double double-quote per SQL99. Before, we put in a
|
||||
* backslash/double-quote pair. - thomas 2000-08-05
|
||||
*/
|
||||
if (*cp == '\"')
|
||||
appendPQExpBufferChar(id_return, '\"');
|
||||
appendPQExpBufferChar(id_return, *cp);
|
||||
}
|
||||
appendPQExpBufferChar(id_return, '\"');
|
||||
}
|
||||
|
||||
return id_return->data;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert a string value to an SQL string literal and append it to
|
||||
* the given buffer.
|
||||
*
|
||||
* Special characters are escaped. Quote mark ' goes to '' per SQL
|
||||
* standard, other stuff goes to \ sequences. If escapeAll is false,
|
||||
* whitespace characters are not escaped (tabs, newlines, etc.). This
|
||||
* is appropriate for dump file output.
|
||||
*/
|
||||
void
|
||||
appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
|
||||
{
|
||||
appendPQExpBufferChar(buf, '\'');
|
||||
while (*str)
|
||||
{
|
||||
char ch = *str++;
|
||||
|
||||
if (ch == '\\' || ch == '\'')
|
||||
{
|
||||
appendPQExpBufferChar(buf, ch); /* double these */
|
||||
appendPQExpBufferChar(buf, ch);
|
||||
}
|
||||
else if ((unsigned char) ch < (unsigned char) ' ' &&
|
||||
(escapeAll
|
||||
|| (ch != '\t' && ch != '\n' && ch != '\v' && ch != '\f' && ch != '\r')
|
||||
))
|
||||
{
|
||||
/*
|
||||
* generate octal escape for control chars other than
|
||||
* whitespace
|
||||
*/
|
||||
appendPQExpBufferChar(buf, '\\');
|
||||
appendPQExpBufferChar(buf, ((ch >> 6) & 3) + '0');
|
||||
appendPQExpBufferChar(buf, ((ch >> 3) & 7) + '0');
|
||||
appendPQExpBufferChar(buf, (ch & 7) + '0');
|
||||
}
|
||||
else
|
||||
appendPQExpBufferChar(buf, ch);
|
||||
}
|
||||
appendPQExpBufferChar(buf, '\'');
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData)
|
||||
|
Reference in New Issue
Block a user