*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.18 2006/03/05 15:58:43 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.19 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/builtins.h"
+#include "parser/gramparse.h"
/*
cp1 = VARDATA(t);
cp2 = VARDATA(result);
- for (; len-- > 0; cp1++)
- if (*cp1 == '\\')
- {
- *cp2++ = ESCAPE_STRING_SYNTAX;
- break;
- }
+ if (!standard_conforming_strings)
+ for (; len-- > 0; cp1++)
+ if (*cp1 == '\\')
+ {
+ *cp2++ = ESCAPE_STRING_SYNTAX;
+ break;
+ }
len = VARSIZE(t) - VARHDRSZ;
cp1 = VARDATA(t);
*cp2++ = '\'';
while (len-- > 0)
{
- if (SQL_STR_DOUBLE(*cp1))
+ if (SQL_STR_DOUBLE(*cp1, !standard_conforming_strings))
*cp2++ = *cp1;
*cp2++ = *cp1++;
}
* ruleutils.c - Functions to convert stored expressions/querytrees
* back to source text
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.221 2006/04/30 18:30:40 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.222 2006/05/26 23:48:54 momjian Exp $
**********************************************************************/
#include "postgres.h"
#include "nodes/makefuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/tlist.h"
+#include "parser/gramparse.h"
#include "parser/keywords.h"
#include "parser/parse_expr.h"
#include "parser/parse_func.h"
{
if (i > 0)
appendStringInfo(&buf, ", ");
- if (strchr(p, '\\') != NULL)
+ if (!standard_conforming_strings && strchr(p, '\\') != NULL)
appendStringInfoChar(&buf, ESCAPE_STRING_SYNTAX);
appendStringInfoChar(&buf, '\'');
while (*p)
{
- if (SQL_STR_DOUBLE(*p))
+ if (SQL_STR_DOUBLE(*p, !standard_conforming_strings))
appendStringInfoChar(&buf, *p);
appendStringInfoChar(&buf, *p++);
}
char *valptr;
bool isfloat = false;
bool needlabel;
-
+ bool is_e_string = false;
+
if (constval->constisnull)
{
/*
* representation. XXX Any MULTIBYTE considerations here?
*/
for (valptr = extval; *valptr; valptr++)
- if (*valptr == '\\' ||
+ if ((!standard_conforming_strings && *valptr == '\\') ||
(unsigned char) *valptr < (unsigned char) ' ')
{
appendStringInfoChar(buf, ESCAPE_STRING_SYNTAX);
+ is_e_string = true;
break;
}
{
char ch = *valptr;
- if (SQL_STR_DOUBLE(ch))
+ if (SQL_STR_DOUBLE(ch, is_e_string))
{
appendStringInfoChar(buf, ch);
appendStringInfoChar(buf, ch);
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.114 2006/03/21 17:54:28 alvherre Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.115 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
}
/*
- * Escape any single quotes or backslashes in given string
+ * Escape any single quotes or backslashes in given string;
+ * postgresql.conf always enables backslash escapes
*/
static char *
escape_quotes(const char *src)
for (i = 0, j = 0; i < len; i++)
{
- if (SQL_STR_DOUBLE(src[i]))
+ if (SQL_STR_DOUBLE(src[i], true))
result[j++] = src[i];
result[j++] = src[i];
}
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.27 2006/04/30 21:15:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.28 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* 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.
+ * is appropriate for dump file output. Using E'' strings for
+ * backslashes is always safe for standard_conforming_strings on or off.
*/
void
-appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
+appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll,
+ bool e_string_for_backslash)
{
char ch;
const char *p;
+ bool is_e_string = false;
for (p = str; *p; p++)
{
ch = *p;
- if (ch == '\\' ||
+
+ if ((e_string_for_backslash && ch == '\\') ||
((unsigned char) ch < (unsigned char) ' ' &&
(escapeAll ||
(ch != '\t' && ch != '\n' && ch != '\v' &&
ch != '\f' && ch != '\r'))))
{
appendPQExpBufferChar(buf, ESCAPE_STRING_SYNTAX);
+ is_e_string = true;
break;
}
}
for (p = str; *p; p++)
{
ch = *p;
- if (SQL_STR_DOUBLE(ch))
+ if (SQL_STR_DOUBLE(ch, is_e_string))
{
appendPQExpBufferChar(buf, ch);
appendPQExpBufferChar(buf, ch);
bool escapeAll, const char *dqprefix)
{
if (strchr(str, '\'') == NULL && strchr(str, '\\') == NULL)
- appendStringLiteral(buf, str, escapeAll);
+ appendStringLiteral(buf, str, escapeAll, true);
else
appendStringLiteralDQ(buf, str, dqprefix);
}
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.15 2006/03/05 15:58:50 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.16 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pqexpbuffer.h"
-
extern const char *fmtId(const char *identifier);
extern void appendStringLiteral(PQExpBuffer buf, const char *str,
- bool escapeAll);
+ bool escapeAll, bool e_string_for_backslash);
extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str,
const char *dqprefix);
extern void appendStringLiteralDQOpt(PQExpBuffer buf, const char *str,
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.129 2006/05/24 21:20:11 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.130 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
teReqs res = REQ_ALL;
- /* ENCODING objects are dumped specially, so always reject here */
+ /* ENCODING and STDSTRINGS objects are dumped specially, so always reject */
if (strcmp(te->desc, "ENCODING") == 0)
return 0;
+ if (strcmp(te->desc, "STDSTRINGS") == 0)
+ return 0;
/* If it's an ACL, maybe ignore it */
if ((!include_acls || ropt->aclsSkip) && strcmp(te->desc, "ACL") == 0)
{
TocEntry *te;
- /* If we have an encoding setting, emit that */
+ /* If we have an encoding or std_strings setting, emit that */
te = AH->toc->next;
while (te != AH->toc)
{
if (strcmp(te->desc, "ENCODING") == 0)
- {
ahprintf(AH, "%s", te->defn);
- break;
- }
+ if (strcmp(te->desc, "STDSTRINGS") == 0)
+ ahprintf(AH, "%s", te->defn);
te = te->next;
}
* SQL requires a string literal here. Might as well be correct.
*/
if (user && *user)
- appendStringLiteral(cmd, user, false);
+ appendStringLiteral(cmd, user, false, true);
else
appendPQExpBuffer(cmd, "DEFAULT");
appendPQExpBuffer(cmd, ";");
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.433 2006/03/05 15:58:50 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.434 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* activities. */
Archive *g_fout; /* the script file */
PGconn *g_conn; /* the database connection */
+bool std_strings = false; /* GUC variable */
/* various user-settable parameters */
bool dumpInserts; /* dump data using proper insert strings */
static int dumpBlobComments(Archive *AH, void *arg);
static void dumpDatabase(Archive *AH);
static void dumpEncoding(Archive *AH);
+static void dumpStdStrings(Archive *AH);
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
static const char *fmtCopyColumnList(const TableInfo *ti);
static void do_sql_command(PGconn *conn, const char *query);
/* First the special encoding entry. */
dumpEncoding(g_fout);
+ dumpStdStrings(g_fout);
+
/* The database item is always second, unless we don't want it at all */
if (!dataOnly && selectTableName == NULL && selectSchemaName == NULL)
dumpDatabase(g_fout);
default:
/* All other types are printed as string literals. */
resetPQExpBuffer(q);
- appendStringLiteral(q, PQgetvalue(res, tuple, field), false);
+ appendStringLiteral(q, PQgetvalue(res, tuple, field), false, !std_strings);
archputs(q->data, fout);
break;
}
"FROM pg_database "
"WHERE datname = ",
username_subquery);
- appendStringLiteral(dbQry, datname, true);
+ appendStringLiteral(dbQry, datname, true, !std_strings);
}
else if (g_fout->remoteVersion >= 80000)
{
"FROM pg_database "
"WHERE datname = ",
username_subquery);
- appendStringLiteral(dbQry, datname, true);
+ appendStringLiteral(dbQry, datname, true, !std_strings);
}
else if (g_fout->remoteVersion >= 70100)
{
"FROM pg_database "
"WHERE datname = ",
username_subquery);
- appendStringLiteral(dbQry, datname, true);
+ appendStringLiteral(dbQry, datname, true, !std_strings);
}
else
{
"FROM pg_database "
"WHERE datname = ",
username_subquery);
- appendStringLiteral(dbQry, datname, true);
+ appendStringLiteral(dbQry, datname, true, !std_strings);
}
res = PQexec(g_conn, dbQry->data);
if (strlen(encoding) > 0)
{
appendPQExpBuffer(creaQry, " ENCODING = ");
- appendStringLiteral(creaQry, encoding, true);
+ appendStringLiteral(creaQry, encoding, true, !std_strings);
}
if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0)
appendPQExpBuffer(creaQry, " TABLESPACE = %s",
if (comment && strlen(comment)) {
resetPQExpBuffer(dbQry);
appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
- appendStringLiteral(dbQry, comment, false);
+ appendStringLiteral(dbQry, comment, false, !std_strings);
appendPQExpBuffer(dbQry, ";\n");
ArchiveEntry(AH, dbCatId, createDumpId(), datname, NULL, NULL,
resetPQExpBuffer(qry);
appendPQExpBuffer(qry, "SET client_encoding = ");
- appendStringLiteral(qry, PQgetvalue(res, 0, 0), true);
+ appendStringLiteral(qry, PQgetvalue(res, 0, 0), true, !std_strings);
appendPQExpBuffer(qry, ";\n");
ArchiveEntry(AH, nilCatalogId, createDumpId(),
}
+/*
+ * dumpStdStrings: put the correct escape string behavior into the archive
+ */
+static void
+dumpStdStrings(Archive *AH)
+{
+ PQExpBuffer qry;
+ PGresult *res;
+
+ if (g_verbose)
+ write_msg(NULL, "saving standard_conforming_strings setting\n");
+
+ qry = createPQExpBuffer();
+
+ /* standard_conforming_strings not used in pre-8.2 servers */
+ if (AH->remoteVersion < 80200)
+ {
+ appendPQExpBuffer(qry, "SET standard_conforming_strings = 'off';\n");
+ std_strings = false;
+ }
+ else
+ {
+ appendPQExpBuffer(qry, "SHOW standard_conforming_strings");
+
+ res = PQexec(g_conn, qry->data);
+
+ check_sql_result(res, g_conn, qry->data, PGRES_TUPLES_OK);
+
+ PQclear(res);
+
+ resetPQExpBuffer(qry);
+
+ std_strings = (strcmp(PQgetvalue(res, 0, 0), "on") == 0);
+ appendPQExpBuffer(qry, "SET standard_conforming_strings = ");
+ appendStringLiteral(qry, PQgetvalue(res, 0, 0), true, !std_strings);
+ appendPQExpBuffer(qry, ";\n");
+ puts(PQgetvalue(res, 0, 0));
+
+ }
+
+ ArchiveEntry(AH, nilCatalogId, createDumpId(),
+ "STDSTRINGS", NULL, NULL, "",
+ false, "STDSTRINGS", qry->data, "", NULL,
+ NULL, 0,
+ NULL, NULL);
+
+ destroyPQExpBuffer(qry);
+}
+
+
/*
* hasBlobs:
* Test whether database contains any large objects
printfPQExpBuffer(commentcmd, "COMMENT ON LARGE OBJECT %u IS ",
blobOid);
- appendStringLiteral(commentcmd, comment, false);
+ appendStringLiteral(commentcmd, comment, false, !std_strings);
appendPQExpBuffer(commentcmd, ";\n");
archputs(commentcmd->data, AH);
PQExpBuffer query = createPQExpBuffer();
appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
- appendStringLiteral(query, comments->descr, false);
+ appendStringLiteral(query, comments->descr, false, !std_strings);
appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, nilCatalogId, createDumpId(),
resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
- appendStringLiteral(query, descr, false);
+ appendStringLiteral(query, descr, false, !std_strings);
appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, nilCatalogId, createDumpId(),
resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
- appendStringLiteral(query, descr, false);
+ appendStringLiteral(query, descr, false, !std_strings);
appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, nilCatalogId, createDumpId(),
{
appendPQExpBuffer(q, ",\n DEFAULT = ");
if (typdefault_is_literal)
- appendStringLiteral(q, typdefault, true);
+ appendStringLiteral(q, typdefault, true, !std_strings);
else
appendPQExpBufferStr(q, typdefault);
}
if (typdelim && strcmp(typdelim, ",") != 0)
{
appendPQExpBuffer(q, ",\n DELIMITER = ");
- appendStringLiteral(q, typdelim, true);
+ appendStringLiteral(q, typdelim, true, !std_strings);
}
if (strcmp(typalign, "c") == 0)
{
appendPQExpBuffer(q, " DEFAULT ");
if (typdefault_is_literal)
- appendStringLiteral(q, typdefault, true);
+ appendStringLiteral(q, typdefault, true, !std_strings);
else
appendPQExpBufferStr(q, typdefault);
}
if (strcmp(probin, "-") != 0)
{
appendPQExpBuffer(asPart, "AS ");
- appendStringLiteral(asPart, probin, true);
+ appendStringLiteral(asPart, probin, true, !std_strings);
if (strcmp(prosrc, "-") != 0)
{
appendPQExpBuffer(asPart, ", ");
* contains quote or backslash; else use regular quoting.
*/
if (disable_dollar_quoting)
- appendStringLiteral(asPart, prosrc, false);
+ appendStringLiteral(asPart, prosrc, false, !std_strings);
else
appendStringLiteralDQOpt(asPart, prosrc, false, NULL);
}
appendPQExpBuffer(asPart, "AS ");
/* with no bin, dollar quote src unconditionally if allowed */
if (disable_dollar_quoting)
- appendStringLiteral(asPart, prosrc, false);
+ appendStringLiteral(asPart, prosrc, false, !std_strings);
else
appendStringLiteralDQ(asPart, prosrc, NULL);
}
appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
(condefault) ? "DEFAULT " : "",
fmtId(convinfo->dobj.name));
- appendStringLiteral(q, conforencoding, true);
+ appendStringLiteral(q, conforencoding, true, !std_strings);
appendPQExpBuffer(q, " TO ");
- appendStringLiteral(q, contoencoding, true);
+ appendStringLiteral(q, contoencoding, true, !std_strings);
/* regproc is automatically quoted in 7.3 and above */
appendPQExpBuffer(q, " FROM %s;\n", conproc);
if (!PQgetisnull(res, 0, i_agginitval))
{
appendPQExpBuffer(details, ",\n INITCOND = ");
- appendStringLiteral(details, agginitval, true);
+ appendStringLiteral(details, agginitval, true, !std_strings);
}
if (strcmp(aggfinalfn, "-") != 0)
{
appendPQExpBuffer(query, "SELECT definition as viewdef "
" from pg_views where viewname = ");
- appendStringLiteral(query, tbinfo->dobj.name, true);
+ appendStringLiteral(query, tbinfo->dobj.name, true, !std_strings);
appendPQExpBuffer(query, ";");
}
resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = ");
- appendStringLiteral(query, dbname, true);
+ appendStringLiteral(query, dbname, true, !std_strings);
res = PQexec(g_conn, query->data);
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
(owning_tab = findTableByOid(tbinfo->owning_tab)) != NULL)
{
appendPQExpBuffer(query, "pg_catalog.pg_get_serial_sequence(");
- appendStringLiteral(query, fmtId(owning_tab->dobj.name), true);
+ appendStringLiteral(query, fmtId(owning_tab->dobj.name), true, !std_strings);
appendPQExpBuffer(query, ", ");
- appendStringLiteral(query, owning_tab->attnames[tbinfo->owning_col - 1], true);
+ appendStringLiteral(query, owning_tab->attnames[tbinfo->owning_col - 1], true, !std_strings);
appendPQExpBuffer(query, ")");
}
else
- appendStringLiteral(query, fmtId(tbinfo->dobj.name), true);
+ appendStringLiteral(query, fmtId(tbinfo->dobj.name), true, !std_strings);
appendPQExpBuffer(query, ", %s, %s);\n",
last, (called ? "true" : "false"));
appendPQExpBufferChar(query, '\'');
while (s < p)
{
- if (*s == '\'') /* bytea already doubles backslashes */
+ if (*s == '\'')
appendPQExpBufferChar(query, '\'');
+ /*
+ * bytea unconditionally doubles backslashes, so we suppress
+ * the doubling for standard_conforming_strings.
+ */
+ if (std_strings && *s == '\\')
+ s++;
appendPQExpBufferChar(query, *s++);
}
appendPQExpBufferChar(query, '\'');
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.75 2006/05/22 11:21:54 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.76 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
if (!PQgetisnull(res, i, i_rolpassword))
{
appendPQExpBuffer(buf, " PASSWORD ");
- appendStringLiteral(buf, PQgetvalue(res, i, i_rolpassword), true);
+ appendStringLiteral(buf, PQgetvalue(res, i, i_rolpassword), true, true);
}
if (!PQgetisnull(res, i, i_rolvaliduntil))
if (!PQgetisnull(res, i, i_rolcomment)) {
appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename));
- appendStringLiteral(buf, PQgetvalue(res, i, i_rolcomment), true);
+ appendStringLiteral(buf, PQgetvalue(res, i, i_rolcomment), true, true);
appendPQExpBuffer(buf, ";\n");
}
appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
appendPQExpBuffer(buf, " LOCATION ");
- appendStringLiteral(buf, spclocation, true);
+ appendStringLiteral(buf, spclocation, true, true);
appendPQExpBuffer(buf, ";\n");
if (!skip_acls &&
if (spccomment && strlen(spccomment)) {
appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname);
- appendStringLiteral(buf, spccomment, true);
+ appendStringLiteral(buf, spccomment, true, true);
appendPQExpBuffer(buf, ";\n");
}
appendPQExpBuffer(buf, " OWNER = %s", fmtId(dbowner));
appendPQExpBuffer(buf, " ENCODING = ");
- appendStringLiteral(buf, dbencoding, true);
+ appendStringLiteral(buf, dbencoding, true, true);
/* Output tablespace if it isn't default */
if (strcmp(dbtablespace, "pg_default") != 0)
if (strcmp(dbistemplate, "t") == 0)
{
appendPQExpBuffer(buf, "UPDATE pg_database SET datistemplate = 't' WHERE datname = ");
- appendStringLiteral(buf, dbname, true);
+ appendStringLiteral(buf, dbname, true, true);
appendPQExpBuffer(buf, ";\n");
}
}
PGresult *res;
printfPQExpBuffer(buf, "SELECT datconfig[%d] FROM pg_database WHERE datname = ", count);
- appendStringLiteral(buf, dbname, true);
+ appendStringLiteral(buf, dbname, true, true);
appendPQExpBuffer(buf, ";");
res = executeQuery(conn, buf->data);
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);
+ appendStringLiteral(buf, username, true, true);
res = executeQuery(conn, buf->data);
if (PQntuples(res) == 1 &&
|| pg_strcasecmp(mine, "search_path") == 0)
appendPQExpBuffer(buf, "%s", pos + 1);
else
- appendStringLiteral(buf, pos + 1, false);
+ appendStringLiteral(buf, pos + 1, false, true);
appendPQExpBuffer(buf, ";\n");
printf("%s", buf->data);
*
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.134 2006/04/26 23:15:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.135 2006/05/26 23:48:54 momjian Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
appendPQExpBuffer(&namebuf, "\\\\");
/* Ensure chars special to string literals are passed properly */
- if (SQL_STR_DOUBLE(*cp))
+ if (SQL_STR_DOUBLE(*cp, true))
appendPQExpBufferChar(&namebuf, *cp);
i = PQmblen(cp, pset.encoding);
*
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.41 2006/03/05 15:58:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.42 2006/05/26 23:48:54 momjian Exp $
*/
#include "postgres_fe.h"
#include "large_obj.h"
if (strchr(comment_arg, '\\') != NULL)
*bufptr++ = ESCAPE_STRING_SYNTAX;
+
*bufptr++ = '\'';
for (i = 0; i < slen; i++)
{
- if (SQL_STR_DOUBLE(comment_arg[i]))
+ if (SQL_STR_DOUBLE(comment_arg[i], true))
*bufptr++ = comment_arg[i];
*bufptr++ = comment_arg[i];
}
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.16 2006/03/05 15:58:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.17 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
if (comment)
{
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
- appendStringLiteral(&sql, comment, false);
+ appendStringLiteral(&sql, comment, false, true);
appendPQExpBuffer(&sql, ";\n");
conn = connectDatabase(dbname, host, port, username, password, progname);
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.27 2006/03/05 15:58:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.28 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
fprintf(stderr, _("Password encryption failed.\n"));
exit(1);
}
- appendStringLiteral(&sql, encrypted_password, false);
+ appendStringLiteral(&sql, encrypted_password, false, true);
PQfreemem(encrypted_password);
}
else
- appendStringLiteral(&sql, newpassword, false);
+ appendStringLiteral(&sql, newpassword, false, true);
}
if (superuser == TRI_YES)
appendPQExpBuffer(&sql, " SUPERUSER");
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/c.h,v 1.200 2006/04/14 03:38:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/c.h,v 1.201 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#define NameStr(name) ((name).data)
-#define SQL_STR_DOUBLE(ch) ((ch) == '\'' || (ch) == '\\')
+/*
+ * In 8.2, we are warning for \ in a non-E string if std_strings are off.
+ * For this reason, we use E for \ strings, unless standard_conforming_strings
+ * is on.
+ */
+#define SQL_STR_DOUBLE(ch, escape_backslash) \
+ ((ch) == '\'' || ((escape_backslash) && (ch) == '\\'))
+
#define ESCAPE_STRING_SYNTAX 'E'
/* ----------------------------------------------------------------
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.45 2006/04/24 09:45:22 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.46 2006/05/26 23:48:54 momjian Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
-/* This function returns a newly malloced string that has the \
- in the argument quoted with \ and the ' quoted with ' as SQL92 says.
+/*
+ * This function returns a newly malloced string that has ' and \
+ * escaped.
*/
static char *
quote_postgres(char *arg, int lineno)
if (!res)
return (res);
+ /*
+ * We don't know if the target database is using
+ * standard_conforming_strings, so we always use E'' strings.
+ */
if (strchr(arg, '\\') != NULL)
res[ri++] = ESCAPE_STRING_SYNTAX;
res[ri++] = '\'';
for (i = 0; arg[i]; i++, ri++)
{
- if (SQL_STR_DOUBLE(arg[i]))
+ if (SQL_STR_DOUBLE(arg[i], true))
res[ri++] = arg[i];
res[ri] = arg[i];
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.88 2006/03/23 04:22:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.89 2006/05/26 23:48:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "plpgsql.h"
#include "parser/parser.h"
+#include "parser/gramparse.h"
static PLpgSQL_expr *read_sql_construct(int until,
int until2,
strcpy(buf, "SELECT ");
cp1 = new->refname;
cp2 = buf + strlen(buf);
- if (strchr(cp1, '\\') != NULL)
+ if (!standard_conforming_strings && strchr(cp1, '\\') != NULL)
*cp2++ = ESCAPE_STRING_SYNTAX;
*cp2++ = '\'';
while (*cp1)
{
- if (SQL_STR_DOUBLE(*cp1))
+ if (SQL_STR_DOUBLE(*cp1, !standard_conforming_strings))
*cp2++ = *cp1;
*cp2++ = *cp1++;
}