Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
74b49a81
Commit
74b49a81
authored
Jul 02, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add E'' to internally created SQL strings that contain backslashes.
Improve code clarity by using macros for E'' processing.
parent
654efe6a
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
91 additions
and
89 deletions
+91
-89
src/backend/utils/adt/quote.c
src/backend/utils/adt/quote.c
+13
-7
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/ruleutils.c
+17
-8
src/bin/initdb/initdb.c
src/bin/initdb/initdb.c
+3
-3
src/bin/pg_dump/dumputils.c
src/bin/pg_dump/dumputils.c
+12
-17
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.c
+3
-4
src/bin/psql/describe.c
src/bin/psql/describe.c
+3
-3
src/bin/psql/large_obj.c
src/bin/psql/large_obj.c
+8
-4
src/include/c.h
src/include/c.h
+3
-1
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/ecpglib/execute.c
+5
-12
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/preproc/preproc.y
+11
-6
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/fe-exec.c
+5
-19
src/pl/plpgsql/src/gram.y
src/pl/plpgsql/src/gram.y
+8
-5
No files found.
src/backend/utils/adt/quote.c
View file @
74b49a81
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.1
5 2005/03/21 16:29:20 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.1
6 2005/07/02 17:01:50 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -60,19 +60,25 @@ quote_literal(PG_FUNCTION_ARGS)
len
=
VARSIZE
(
t
)
-
VARHDRSZ
;
/* We make a worst-case result area; wasting a little space is OK */
result
=
(
text
*
)
palloc
(
len
*
2
+
2
+
VARHDRSZ
);
result
=
(
text
*
)
palloc
(
len
*
2
+
3
+
VARHDRSZ
);
cp1
=
VARDATA
(
t
);
cp2
=
VARDATA
(
result
);
for
(;
len
--
>
0
;
cp1
++
)
if
(
*
cp1
==
'\\'
)
{
*
cp2
++
=
ESCAPE_STRING_SYNTAX
;
break
;
}
len
=
VARSIZE
(
t
)
-
VARHDRSZ
;
cp1
=
VARDATA
(
t
);
*
cp2
++
=
'\''
;
while
(
len
--
>
0
)
{
if
(
*
cp1
==
'\''
)
*
cp2
++
=
'\''
;
else
if
(
*
cp1
==
'\\'
)
*
cp2
++
=
'\\'
;
if
(
SQL_STR_DOUBLE
(
*
cp1
))
*
cp2
++
=
*
cp1
;
*
cp2
++
=
*
cp1
++
;
}
*
cp2
++
=
'\''
;
...
...
src/backend/utils/adt/ruleutils.c
View file @
74b49a81
...
...
@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.20
2 2005/06/28 05:09:01 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.20
3 2005/07/02 17:01:50 momjian
Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
...
...
@@ -564,12 +564,14 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
{
if
(
i
>
0
)
appendStringInfo
(
&
buf
,
", "
);
if
(
strchr
(
p
,
'\\'
)
!=
NULL
)
appendStringInfoChar
(
&
buf
,
ESCAPE_STRING_SYNTAX
);
appendStringInfoChar
(
&
buf
,
'\''
);
while
(
*
p
)
{
/* escape quotes and backslashes */
if
(
*
p
==
'\''
||
*
p
==
'\\'
)
appendStringInfoChar
(
&
buf
,
'\\'
);
if
(
SQL_STR_DOUBLE
(
*
p
))
appendStringInfoChar
(
&
buf
,
*
p
);
appendStringInfoChar
(
&
buf
,
*
p
++
);
}
p
++
;
...
...
@@ -3869,22 +3871,29 @@ get_const_expr(Const *constval, deparse_context *context)
break
;
default:
/*
* We must quote any funny characters in the constant's
* representation. XXX Any MULTIBYTE considerations here?
*/
for
(
valptr
=
extval
;
*
valptr
;
valptr
++
)
if
(
*
valptr
==
'\\'
||
(
unsigned
char
)
*
valptr
<
(
unsigned
char
)
' '
)
{
appendStringInfoChar
(
buf
,
ESCAPE_STRING_SYNTAX
);
break
;
}
appendStringInfoChar
(
buf
,
'\''
);
for
(
valptr
=
extval
;
*
valptr
;
valptr
++
)
{
char
ch
=
*
valptr
;
if
(
ch
==
'\''
||
ch
==
'\\'
)
if
(
SQL_STR_DOUBLE
(
ch
)
)
{
appendStringInfoChar
(
buf
,
'\\'
);
appendStringInfoChar
(
buf
,
ch
);
appendStringInfoChar
(
buf
,
ch
);
}
else
if
((
(
unsigned
char
)
ch
)
<
((
unsigned
char
)
' '
)
)
else
if
((
unsigned
char
)
ch
<
(
unsigned
char
)
' '
)
appendStringInfo
(
buf
,
"
\\
%03o"
,
(
int
)
ch
);
else
appendStringInfoChar
(
buf
,
ch
);
...
...
src/bin/initdb/initdb.c
View file @
74b49a81
...
...
@@ -42,7 +42,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.
89 2005/07/01 17:40:28
momjian Exp $
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.
90 2005/07/02 17:01:50
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1986,8 +1986,8 @@ escape_quotes(const char *src)
for
(
i
=
0
,
j
=
0
;
i
<
len
;
i
++
)
{
if
(
src
[
i
]
==
'\\'
||
src
[
i
]
==
'\''
)
result
[
j
++
]
=
src
[
i
];
/* double these */
if
(
SQL_STR_DOUBLE
(
src
[
i
])
)
result
[
j
++
]
=
src
[
i
];
result
[
j
++
]
=
src
[
i
];
}
result
[
j
]
=
'\0'
;
...
...
src/bin/pg_dump/dumputils.c
View file @
74b49a81
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.1
8 2005/07/01 21:03:25
momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.1
9 2005/07/02 17:01:51
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -111,38 +111,33 @@ fmtId(const char *rawid)
void
appendStringLiteral
(
PQExpBuffer
buf
,
const
char
*
str
,
bool
escapeAll
)
{
bool
has_escapes
=
false
;
const
char
*
str2
=
str
;
char
ch
;
const
char
*
p
;
while
(
*
str2
)
for
(
p
=
str
;
*
p
;
p
++
)
{
char
ch
=
*
str2
++
;
ch
=
*
p
;
if
(
ch
==
'\\'
||
((
unsigned
char
)
ch
<
(
unsigned
char
)
' '
&&
((
unsigned
char
)
ch
<
(
unsigned
char
)
' '
&&
(
escapeAll
||
(
ch
!=
'\t'
&&
ch
!=
'\n'
&&
ch
!=
'\v'
&&
ch
!=
'\f'
&&
ch
!=
'\r'
))))
{
has_escapes
=
true
;
appendPQExpBufferChar
(
buf
,
ESCAPE_STRING_SYNTAX
)
;
break
;
}
}
if
(
has_escapes
)
appendPQExpBufferChar
(
buf
,
'E'
);
appendPQExpBufferChar
(
buf
,
'\''
);
while
(
*
str
)
for
(
p
=
str
;
*
p
;
p
++
)
{
char
ch
=
*
str
++
;
if
(
ch
==
'\\'
||
ch
==
'\''
)
ch
=
*
p
;
if
(
SQL_STR_DOUBLE
(
ch
))
{
appendPQExpBufferChar
(
buf
,
ch
);
/* double these */
appendPQExpBufferChar
(
buf
,
ch
);
appendPQExpBufferChar
(
buf
,
ch
);
}
else
if
((
unsigned
char
)
ch
<
(
unsigned
char
)
' '
&&
else
if
((
unsigned
char
)
ch
<
(
unsigned
char
)
' '
&&
(
escapeAll
||
(
ch
!=
'\t'
&&
ch
!=
'\n'
&&
ch
!=
'\v'
&&
ch
!=
'\f'
&&
ch
!=
'\r'
)))
...
...
src/bin/pg_dump/pg_dump.c
View file @
74b49a81
...
...
@@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.41
2 2005/07/01 21:03:25
momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.41
3 2005/07/02 17:01:51
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -7792,18 +7792,17 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
}
p
--
;
/* do we need E''? */
while
(
s2
<
p
)
if
(
*
s2
++
==
'\\'
)
{
appendPQExpBufferChar
(
query
,
'E'
);
appendPQExpBufferChar
(
query
,
ESCAPE_STRING_SYNTAX
);
break
;
}
appendPQExpBufferChar
(
query
,
'\''
);
while
(
s
<
p
)
{
if
(
*
s
==
'\''
)
if
(
*
s
==
'\''
)
/* bytea already doubles backslashes */
appendPQExpBufferChar
(
query
,
'\''
);
appendPQExpBufferChar
(
query
,
*
s
++
);
}
...
...
src/bin/psql/describe.c
View file @
74b49a81
...
...
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.1
19 2005/07/01 17:40:28
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.1
20 2005/07/02 17:01:52
momjian Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
...
...
@@ -1898,8 +1898,8 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
appendPQExpBuffer
(
&
namebuf
,
"
\\\\
"
);
/* Ensure chars special to string literals are passed properly */
if
(
*
cp
==
'\''
||
*
cp
==
'\\'
)
appendPQExpBufferChar
(
&
namebuf
,
*
cp
);
/* double these */
if
(
SQL_STR_DOUBLE
(
*
cp
)
)
appendPQExpBufferChar
(
&
namebuf
,
*
cp
);
i
=
PQmblen
(
cp
,
pset
.
encoding
);
while
(
i
--
)
...
...
src/bin/psql/large_obj.c
View file @
74b49a81
...
...
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.3
8 2005/07/01 17:40:28
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.3
9 2005/07/02 17:01:52
momjian Exp $
*/
#include "postgres_fe.h"
#include "large_obj.h"
...
...
@@ -172,13 +172,17 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
if
(
!
cmdbuf
)
return
fail_lo_xact
(
"
\\
lo_import"
,
own_transaction
);
sprintf
(
cmdbuf
,
"COMMENT ON LARGE OBJECT %u IS
'
"
,
"COMMENT ON LARGE OBJECT %u IS "
,
loid
);
bufptr
=
cmdbuf
+
strlen
(
cmdbuf
);
if
(
strchr
(
comment_arg
,
'\\'
)
!=
NULL
)
*
bufptr
++
=
ESCAPE_STRING_SYNTAX
;
*
bufptr
++
=
'\''
;
for
(
i
=
0
;
i
<
slen
;
i
++
)
{
if
(
comment_arg
[
i
]
==
'\''
||
comment_arg
[
i
]
==
'\\'
)
*
bufptr
++
=
comment_arg
[
i
];
/* double these */
if
(
SQL_STR_DOUBLE
(
comment_arg
[
i
])
)
*
bufptr
++
=
comment_arg
[
i
];
*
bufptr
++
=
comment_arg
[
i
];
}
strcpy
(
bufptr
,
"'"
);
...
...
src/include/c.h
View file @
74b49a81
...
...
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/c.h,v 1.18
6 2005/06/28 05:09:04 tgl
Exp $
* $PostgreSQL: pgsql/src/include/c.h,v 1.18
7 2005/07/02 17:01:52 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -479,6 +479,8 @@ typedef NameData *Name;
#define NameStr(name) ((name).data)
#define SQL_STR_DOUBLE(ch) ((ch) == '\'' || (ch) == '\\')
#define ESCAPE_STRING_SYNTAX 'E'
/* ----------------------------------------------------------------
* Section 4: IsValid macros for system types
...
...
src/interfaces/ecpg/ecpglib/execute.c
View file @
74b49a81
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.4
0 2005/06/02 12:35:11 meskes
Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.4
1 2005/07/02 17:01:53 momjian
Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
...
...
@@ -45,21 +45,14 @@ quote_postgres(char *arg, int lineno)
if
(
!
res
)
return
(
res
);
if
(
strchr
(
arg
,
'\\'
)
!=
NULL
)
res
[
ri
++
]
=
ESCAPE_STRING_SYNTAX
;
res
[
ri
++
]
=
'\''
;
for
(
i
=
0
;
arg
[
i
];
i
++
,
ri
++
)
{
switch
(
arg
[
i
])
{
case
'\''
:
res
[
ri
++
]
=
'\''
;
break
;
case
'\\'
:
res
[
ri
++
]
=
'\\'
;
break
;
default:
;
}
if
(
SQL_STR_DOUBLE
(
arg
[
i
]))
res
[
ri
++
]
=
arg
[
i
];
res
[
ri
]
=
arg
[
i
];
}
...
...
src/interfaces/ecpg/preproc/preproc.y
View file @
74b49a81
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.30
7 2005/02/10 08:06:35 meskes
Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.30
8 2005/07/02 17:01:53 momjian
Exp $ */
/* Copyright comment */
%{
...
...
@@ -4216,11 +4216,16 @@ Bconst: BCONST { $$ = make_name();};
Xconst: XCONST { $$ = make_name();};
Sconst: SCONST
{
$$ = (char *)mm_alloc(strlen($1) + 3);
$$[0]='\'';
strcpy($$+1, $1);
$$[strlen($1)+2]='\0';
$$[strlen($1)+1]='\'';
char *ret;
$$ = ret = (char *)mm_alloc(strlen($1) + 4);
if (strchr($1, '\\') != NULL)
*ret++ = ESCAPE_STRING_SYNTAX;
*ret++ = '\'';
strcpy(ret, $1);
ret += strlen($1);
*ret++ = '\'';
*ret++ = '\0';
free($1);
}
;
...
...
src/interfaces/libpq/fe-exec.c
View file @
74b49a81
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.1
69 2005/06/12 00:00:21 neilc
Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.1
70 2005/07/02 17:01:54 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -2368,23 +2368,9 @@ PQescapeString(char *to, const char *from, size_t length)
while
(
remaining
>
0
&&
*
source
!=
'\0'
)
{
switch
(
*
source
)
{
case
'\\'
:
*
target
++
=
'\\'
;
*
target
++
=
'\\'
;
break
;
case
'\''
:
*
target
++
=
'\''
;
*
target
++
=
'\''
;
break
;
default:
*
target
++
=
*
source
;
break
;
}
source
++
;
if
(
SQL_STR_DOUBLE
(
*
source
))
*
target
++
=
*
source
;
*
target
++
=
*
source
++
;
remaining
--
;
}
...
...
@@ -2449,7 +2435,7 @@ PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
}
else
if
(
*
vp
==
'\''
)
{
rp
[
0
]
=
'\
\
'
;
rp
[
0
]
=
'\
'
'
;
rp
[
1
]
=
'\''
;
rp
+=
2
;
}
...
...
src/pl/plpgsql/src/gram.y
View file @
74b49a81
...
...
@@ -4,7 +4,7 @@
* procedural language
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.
79 2005/07/02 08:59:47 neilc
Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.
80 2005/07/02 17:01:59 momjian
Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
...
...
@@ -389,13 +389,16 @@ decl_statement : decl_varname decl_const decl_datatype decl_notnull decl_defval
curname_def = palloc0(sizeof(PLpgSQL_expr));
curname_def->dtype = PLPGSQL_DTYPE_EXPR;
strcpy(buf, "SELECT
'
");
strcpy(buf, "SELECT ");
cp1 = new->refname;
cp2 = buf + strlen(buf);
while (*cp1 != '\0')
if (strchr(cp1, '\\') != NULL)
*cp2++ = ESCAPE_STRING_SYNTAX;
*cp2++ = '\'';
while (*cp1)
{
if (
*cp1 == '\\' || *cp1 == '\''
)
*cp2++ = *cp1;
/* double these */
if (
SQL_STR_DOUBLE(*cp1)
)
*cp2++ = *cp1;
*cp2++ = *cp1++;
}
strcpy(cp2, "'::refcursor");
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment