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
22fe451c
Commit
22fe451c
authored
Apr 25, 1999
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
psql's recognition of comments didn't work right in MULTIBYTE
environments; it was being careless about character lengths.
parent
109cbc72
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
58 deletions
+32
-58
src/bin/psql/psql.c
src/bin/psql/psql.c
+32
-58
No files found.
src/bin/psql/psql.c
View file @
22fe451c
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.17
5 1999/04/15 02:24:41
tgl Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.17
6 1999/04/25 23:10:36
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1120,9 +1120,8 @@ static char *
gets_fromFile
(
char
*
prompt
,
FILE
*
source
)
{
char
*
line
;
int
len
;
line
=
malloc
(
MAX_QUERY_BUFFER
+
1
);
line
=
malloc
(
MAX_QUERY_BUFFER
);
/* read up to MAX_QUERY_BUFFER characters */
if
(
fgets
(
line
,
MAX_QUERY_BUFFER
,
source
)
==
NULL
)
...
...
@@ -1131,12 +1130,11 @@ gets_fromFile(char *prompt, FILE *source)
return
NULL
;
}
line
[
MAX_QUERY_BUFFER
-
1
]
=
'\0'
;
len
=
strlen
(
line
);
if
(
len
==
MAX_QUERY_BUFFER
)
line
[
MAX_QUERY_BUFFER
-
1
]
=
'\0'
;
/* this is unnecessary, I think */
if
(
strlen
(
line
)
==
MAX_QUERY_BUFFER
-
1
)
{
fprintf
(
stderr
,
"line read exceeds maximum length. Truncating at %d
\n
"
,
MAX_QUERY_BUFFER
);
MAX_QUERY_BUFFER
-
1
);
}
return
line
;
}
...
...
@@ -2585,18 +2583,22 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
else
{
int
i
;
/*
* The current character is at line[i], the prior character
* at line[i - prevlen], the next character at line[i + thislen].
*/
#ifdef MULTIBYTE
int
mblen
=
1
;
int
prevlen
=
0
;
int
thislen
=
(
len
>
0
)
?
PQmblen
(
line
)
:
0
;
#define ADVANCE_I (prevlen = thislen, i += thislen, thislen = PQmblen(line+i))
#else
#define prevlen 1
#define thislen 1
#define ADVANCE_I (i++)
#endif
was_bslash
=
false
;
#ifdef MULTIBYTE
for
(
i
=
0
;
i
<
len
;
mblen
=
PQmblen
(
line
+
i
),
i
+=
mblen
)
#else
for
(
i
=
0
;
i
<
len
;
i
++
)
#endif
for
(
i
=
0
;
i
<
len
;
ADVANCE_I
)
{
if
(
line
[
i
]
==
'\\'
&&
!
in_quote
)
{
...
...
@@ -2616,8 +2618,6 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
line
[
i
]
=
hold_char
;
query_start
=
line
+
i
;
break
;
/* handle command */
/* start an extended comment? */
}
if
(
querySent
&&
...
...
@@ -2630,55 +2630,30 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
if
(
was_bslash
)
was_bslash
=
false
;
#ifdef MULTIBYTE
else
if
(
i
>
0
&&
line
[
i
-
mblen
]
==
'\\'
)
#else
else
if
(
i
>
0
&&
line
[
i
-
1
]
==
'\\'
)
#endif
else
if
(
i
>
0
&&
line
[
i
-
prevlen
]
==
'\\'
)
was_bslash
=
true
;
/* inside a quote? */
if
(
in_quote
&&
(
line
[
i
]
!=
in_quote
||
was_bslash
))
/* do nothing */
;
else
if
(
xcomment
!=
NULL
)
/* inside an extended
* comment? */
/* inside an extended comment? */
else
if
(
xcomment
!=
NULL
)
{
#ifdef MULTIBYTE
if
(
line
[
i
]
==
'*'
&&
line
[
i
+
mblen
]
==
'/'
)
#else
if
(
line
[
i
]
==
'*'
&&
line
[
i
+
1
]
==
'/'
)
#endif
if
(
line
[
i
]
==
'*'
&&
line
[
i
+
thislen
]
==
'/'
)
{
xcomment
=
NULL
;
#ifdef MULTIBYTE
i
+=
mblen
;
#else
i
++
;
#endif
ADVANCE_I
;
}
}
/* possible backslash command? */
#ifdef MULTIBYTE
else
if
(
line
[
i
]
==
'/'
&&
line
[
i
+
mblen
]
==
'*'
)
#else
else
if
(
line
[
i
]
==
'/'
&&
line
[
i
+
1
]
==
'*'
)
#endif
/* start of extended comment? */
else
if
(
line
[
i
]
==
'/'
&&
line
[
i
+
thislen
]
==
'*'
)
{
xcomment
=
line
+
i
;
#ifdef MULTIBYTE
i
+=
mblen
;
#else
i
++
;
#endif
ADVANCE_I
;
}
/* single-line comment? truncate line */
#ifdef MULTIBYTE
else
if
((
line
[
i
]
==
'-'
&&
line
[
i
+
mblen
]
==
'-'
)
||
(
line
[
i
]
==
'/'
&&
line
[
i
+
mblen
]
==
'/'
))
#else
else
if
((
line
[
i
]
==
'-'
&&
line
[
i
+
1
]
==
'-'
)
||
(
line
[
i
]
==
'/'
&&
line
[
i
+
1
]
==
'/'
))
#endif
else
if
((
line
[
i
]
==
'-'
&&
line
[
i
+
thislen
]
==
'-'
)
||
(
line
[
i
]
==
'/'
&&
line
[
i
+
thislen
]
==
'/'
))
{
/* print comment at top of query */
if
(
pset
->
singleStep
)
...
...
@@ -2693,9 +2668,9 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
/* semi-colon? then send query now */
else
if
(
!
paren_level
&&
line
[
i
]
==
';'
)
{
char
hold_char
=
line
[
i
+
1
];
char
hold_char
=
line
[
i
+
thislen
];
line
[
i
+
1
]
=
'\0'
;
line
[
i
+
thislen
]
=
'\0'
;
if
(
query_start
[
0
]
!=
'\0'
)
{
if
(
query
[
0
]
!=
'\0'
)
...
...
@@ -2708,11 +2683,10 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
}
success
=
SendQuery
(
pset
,
query
,
NULL
,
NULL
);
successResult
&=
success
;
line
[
i
+
1
]
=
hold_char
;
query_start
=
line
+
i
+
1
;
line
[
i
+
thislen
]
=
hold_char
;
query_start
=
line
+
i
+
thislen
;
/* sometimes, people do ';\g', don't execute twice */
if
(
*
query_start
&&
/* keeps us from going off the end */
*
query_start
==
'\\'
&&
if
(
*
query_start
==
'\\'
&&
*
(
query_start
+
1
)
==
'g'
)
query_start
+=
2
;
querySent
=
true
;
...
...
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