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
255363f8
Commit
255363f8
authored
Dec 13, 1996
by
Bryan Henderson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up. Get rid of tabs and overly long lines.
parent
ea8b5196
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
714 additions
and
672 deletions
+714
-672
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/fe-exec.c
+714
-672
No files found.
src/interfaces/libpq/fe-exec.c
View file @
255363f8
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.
19 1996/11/20 22:35:19 momjian
Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.
20 1996/12/13 09:25:08 bryanh
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -32,7 +32,7 @@ struct winsize {
}
screen_size
;
#endif
/* the
tuples array in a PGresGroup has to grow to accommodate the tuple
s */
/* the
rows array in a PGresGroup has to grow to accommodate the row
s */
/* returned. Each time, we grow by this much: */
#define TUPARR_GROW_BY 100
...
...
@@ -66,7 +66,7 @@ PQclear(PGresult* res)
if
(
!
res
)
return
;
/* free all the
tuple
s */
/* free all the
row
s */
for
(
i
=
0
;
i
<
res
->
ntups
;
i
++
)
{
for
(
j
=
0
;
j
<
res
->
numAttributes
;
j
++
)
{
if
(
res
->
tuples
[
i
][
j
].
value
)
...
...
@@ -114,7 +114,7 @@ makeEmptyPGresult(PGconn *conn, ExecStatusType status)
/*
* getTuple -
* get the next
tuple
from the stream
* get the next
row
from the stream
*
* the CALLER is responsible from freeing the PGresAttValue returned
*/
...
...
@@ -147,7 +147,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
if
(
pqGetnchar
(
bitmap
,
nbytes
,
pfin
,
pfdebug
)
==
1
){
sprintf
(
conn
->
errorMessage
,
"Error reading null-values bitmap from tuple
data stream
\n
"
);
"Error reading null-values bitmap from row
data stream
\n
"
);
return
NULL
;
}
...
...
@@ -191,7 +191,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
/*
* addTuple
* add a
tuple
to the PGresult structure, growing it if necessary
* add a
row
to the PGresult structure, growing it if necessary
* to accommodate
*
*/
...
...
@@ -217,11 +217,11 @@ addTuple(PGresult* res, PGresAttValue* tup)
/*
* PGresult
* fill out the PGresult structure with result
tuple
s from the backend
* fill out the PGresult structure with result
row
s from the backend
* this is called after query has been successfully run and we have
* a portal name
*
* ASSUMPTION: we assume only *1*
tuple
group is returned from the backend
* ASSUMPTION: we assume only *1*
row
group is returned from the backend
*
* the CALLER is reponsible for free'ing the new PGresult allocated here
*
...
...
@@ -284,34 +284,30 @@ makePGresult(PGconn* conn, char* pname)
/* process the data stream until we're finished */
while
(
!
done
)
{
switch
(
id
)
{
case
'T'
:
/* a new
tuple
group */
case
'T'
:
/* a new
row
group */
sprintf
(
conn
->
errorMessage
,
"makePGresult() -- is not equipped to handle multiple tuple groups.
\n
"
);
"makePGresult() -- "
"is not equipped to handle multiple row groups.
\n
"
);
goto
makePGresult_badResponse_return
;
case
'B'
:
/* a
tuple
in binary format */
case
'D'
:
/* a
tuple
in ASCII format */
case
'B'
:
/* a
row
in binary format */
case
'D'
:
/* a
row
in ASCII format */
newTup
=
getTuple
(
conn
,
result
,
(
id
==
'B'
));
if
(
newTup
==
NULL
)
goto
makePGresult_badResponse_return
;
addTuple
(
result
,
newTup
);
break
;
/* case 'A':
sprintf(conn->errorMessage, "Asynchronous portals not supported");
result->resultStatus = PGRES_NONFATAL_ERROR;
return result;
break;
*/
case
'C'
:
/* end of portal tuple stream */
case
'C'
:
/* end of portal row stream */
{
char
command
[
MAX_MESSAGE_LEN
];
pqGets
(
command
,
MAX_MESSAGE_LEN
,
pfin
,
pfdebug
);
/* read
the
command tag */
pqGets
(
command
,
MAX_MESSAGE_LEN
,
pfin
,
pfdebug
);
/* read command tag */
done
=
1
;
}
break
;
case
'E'
:
/* errors */
if
(
pqGets
(
conn
->
errorMessage
,
ERROR_MSG_LENGTH
,
pfin
,
pfdebug
)
==
1
)
{
sprintf
(
conn
->
errorMessage
,
"Error return detected from backend, but error message cannot be read"
);
"Error return detected from backend, "
"but error message cannot be read"
);
}
result
->
resultStatus
=
PGRES_FATAL_ERROR
;
return
result
;
...
...
@@ -319,7 +315,8 @@ makePGresult(PGconn* conn, char* pname)
case
'N'
:
/* notices from the backend */
if
(
pqGets
(
conn
->
errorMessage
,
ERROR_MSG_LENGTH
,
pfin
,
pfdebug
)
==
1
)
{
sprintf
(
conn
->
errorMessage
,
"Notice return detected from backend, but error message cannot be read"
);
"Notice return detected from backend, "
"but error message cannot be read"
);
}
else
/* XXXX send Notices to stderr for now */
fprintf
(
stderr
,
"%s
\n
"
,
conn
->
errorMessage
);
...
...
@@ -327,7 +324,9 @@ makePGresult(PGconn* conn, char* pname)
default:
/* uh-oh
this should never happen but frequently does when the
backend dumps core */
sprintf
(
conn
->
errorMessage
,
"FATAL: unexpected results from the backend, it probably dumped core."
);
sprintf
(
conn
->
errorMessage
,
"FATAL: unrecognized data from the backend. "
"It probably dumped core."
);
fprintf
(
stderr
,
conn
->
errorMessage
);
result
->
resultStatus
=
PGRES_FATAL_ERROR
;
return
result
;
...
...
@@ -445,10 +444,11 @@ PQexec(PGconn* conn, const char* query)
/* async messages are piggy'ed back on other messages,
so we stay in the while loop for other messages */
break
;
case
'C'
:
/* portal query command, no
tuple
s returned */
case
'C'
:
/* portal query command, no
row
s returned */
if
(
pqGets
(
cmdStatus
,
MAX_MESSAGE_LEN
,
pfin
,
pfdebug
)
==
1
)
{
sprintf
(
conn
->
errorMessage
,
"PQexec() -- query command completed, but return message from backend cannot be read"
);
"PQexec() -- query command completed, "
"but return message from backend cannot be read."
);
return
(
PGresult
*
)
NULL
;
}
else
{
...
...
@@ -495,7 +495,8 @@ PQexec(PGconn* conn, const char* query)
case
'E'
:
/* error return */
if
(
pqGets
(
conn
->
errorMessage
,
ERROR_MSG_LENGTH
,
pfin
,
pfdebug
)
==
1
)
{
(
void
)
sprintf
(
conn
->
errorMessage
,
"PQexec() -- error return detected from backend, but error message cannot be read"
);
"PQexec() -- error return detected from backend, "
"but attempt to read the error message failed."
);
}
return
(
PGresult
*
)
NULL
;
break
;
...
...
@@ -506,7 +507,6 @@ PQexec(PGconn* conn, const char* query)
if
((
c
=
pqGetc
(
pfin
,
pfdebug
))
!=
'\0'
)
{
fprintf
(
stderr
,
"error!, unexpected character %c following 'I'
\n
"
,
c
);
}
#ifdef PQ_NOTIFY_PATCH
if
(
isCommand
)
{
/*
* If this is the result of a portal query command set the
...
...
@@ -516,7 +516,6 @@ PQexec(PGconn* conn, const char* query)
strncpy
(
result
->
cmdStatus
,
cmdStatus
,
CMDSTATUS_LEN
-
1
);
return
result
;
}
#endif
result
=
makeEmptyPGresult
(
conn
,
PGRES_EMPTY_QUERY
);
return
result
;
}
...
...
@@ -524,16 +523,17 @@ PQexec(PGconn* conn, const char* query)
case
'N'
:
/* notices from the backend */
if
(
pqGets
(
conn
->
errorMessage
,
ERROR_MSG_LENGTH
,
pfin
,
pfdebug
)
==
1
)
{
sprintf
(
conn
->
errorMessage
,
"PQexec() -- error return detected from backend, but error message cannot be read"
);
"PQexec() -- Notice detected from backend, "
"but attempt to read the notice failed."
);
return
(
PGresult
*
)
NULL
;
}
else
fprintf
(
stderr
,
"%s"
,
conn
->
errorMessage
);
break
;
case
'P'
:
/* synchronous (normal) portal */
pqGets
(
pname
,
MAX_MESSAGE_LEN
,
pfin
,
pfdebug
);
/* read in
the
portal name*/
pqGets
(
pname
,
MAX_MESSAGE_LEN
,
pfin
,
pfdebug
);
/* read in portal name*/
break
;
case
'T'
:
/* actual
tuple
results: */
case
'T'
:
/* actual
row
results: */
return
makePGresult
(
conn
,
pname
);
break
;
case
'D'
:
/* copy command began successfully */
...
...
@@ -668,7 +668,8 @@ PQendcopy(PGconn *conn)
case
'N'
:
if
(
pqGets
(
conn
->
errorMessage
,
ERROR_MSG_LENGTH
,
pfin
,
pfdebug
)
==
1
)
{
sprintf
(
conn
->
errorMessage
,
"Error return detected from backend, but error message cannot be read"
);
"Error return detected from backend, "
"but attempt to read the message failed."
);
}
return
(
0
);
break
;
...
...
@@ -813,7 +814,7 @@ PQprintTuples(PGresult *res,
}
else
sprintf
(
formatString
,
"%%s %%s"
);
if
(
nFields
>
0
)
{
/* only print
tuple
s with at least 1 field. */
if
(
nFields
>
0
)
{
/* only print
row
s with at least 1 field. */
if
(
!
TerseOutput
)
{
...
...
@@ -856,13 +857,206 @@ PQprintTuples(PGresult *res,
}
}
static
void
do_field
(
PQprintOpt
*
po
,
PGresult
*
res
,
const
int
i
,
const
int
j
,
char
*
buf
,
const
int
fs_len
,
char
*
fields
[],
const
int
nFields
,
char
*
fieldNames
[],
unsigned
char
fieldNotNum
[],
int
fieldMax
[],
const
int
fieldMaxLen
,
FILE
*
fout
)
{
char
*
pval
,
*
p
,
*
o
;
int
plen
;
bool
skipit
;
plen
=
PQgetlength
(
res
,
i
,
j
);
pval
=
PQgetvalue
(
res
,
i
,
j
);
if
(
plen
<
1
||
!
pval
||
!*
pval
)
{
if
(
po
->
align
||
po
->
expanded
)
skipit
=
true
;
else
{
skipit
=
false
;
goto
efield
;
}
}
else
skipit
=
false
;
if
(
!
skipit
)
{
for
(
p
=
pval
,
o
=
buf
;
*
p
;
*
(
o
++
)
=*
(
p
++
))
{
if
((
fs_len
==
1
&&
(
*
p
==*
(
po
->
fieldSep
)))
||
*
p
==
'\\'
)
*
(
o
++
)
=
'\\'
;
if
(
po
->
align
&&
(
*
pval
==
'E'
||
*
pval
==
'e'
||
!
((
*
p
>=
'0'
&&
*
p
<=
'9'
)
||
*
p
==
'.'
||
*
p
==
'E'
||
*
p
==
'e'
||
*
p
==
' '
||
*
p
==
'-'
)))
fieldNotNum
[
j
]
=
1
;
}
*
o
=
'\0'
;
if
(
!
po
->
expanded
&&
(
po
->
align
||
po
->
html3
))
{
int
n
=
strlen
(
buf
);
if
(
n
>
fieldMax
[
j
])
fieldMax
[
j
]
=
n
;
if
(
!
(
fields
[
i
*
nFields
+
j
]
=
(
char
*
)
malloc
(
n
+
1
)))
{
perror
(
"malloc"
);
exit
(
1
);
}
strcpy
(
fields
[
i
*
nFields
+
j
],
buf
);
}
else
{
if
(
po
->
expanded
)
{
if
(
po
->
html3
)
fprintf
(
fout
,
"<tr><td align=left><b>%s</b></td>"
"<td align=%s>%s</td></tr>
\n
"
,
fieldNames
[
j
],
fieldNotNum
[
j
]
?
"left"
:
"right"
,
buf
);
else
{
if
(
po
->
align
)
fprintf
(
fout
,
"%-*s%s %s
\n
"
,
fieldMaxLen
-
fs_len
,
fieldNames
[
j
],
po
->
fieldSep
,
buf
);
else
fprintf
(
fout
,
"%s%s%s
\n
"
,
fieldNames
[
j
],
po
->
fieldSep
,
buf
);
}
}
else
{
if
(
!
po
->
html3
)
{
fputs
(
buf
,
fout
);
efield:
if
((
j
+
1
)
<
nFields
)
fputs
(
po
->
fieldSep
,
fout
);
else
fputc
(
'\n'
,
fout
);
}
}
}
}
}
static
void
do_header
(
FILE
*
fout
,
PQprintOpt
*
po
,
const
int
nFields
,
int
fieldMax
[],
char
*
fieldNames
[],
unsigned
char
fieldNotNum
[],
const
int
fs_len
,
char
*
border
,
PGresult
*
res
)
{
int
j
;
/* for loop index */
if
(
po
->
html3
)
fputs
(
"<tr>"
,
fout
);
else
{
int
j
;
/* for loop index */
int
tot
=
0
;
int
n
=
0
;
char
*
p
;
for
(;
n
<
nFields
;
n
++
)
tot
+=
fieldMax
[
n
]
+
fs_len
+
(
po
->
standard
?
2
:
0
);
if
(
po
->
standard
)
tot
+=
fs_len
*
2
+
2
;
if
(
!
(
p
=
border
=
malloc
(
tot
+
1
)))
{
perror
(
"malloc"
);
exit
(
1
);
}
if
(
po
->
standard
)
{
char
*
fs
=
po
->
fieldSep
;
while
(
*
fs
++
)
*
p
++=
'+'
;
}
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
int
len
;
for
(
len
=
fieldMax
[
j
]
+
(
po
->
standard
?
2
:
0
)
;
len
--
;
*
p
++=
'-'
);
if
(
po
->
standard
||
(
j
+
1
)
<
nFields
)
{
char
*
fs
=
po
->
fieldSep
;
while
(
*
fs
++
)
*
p
++=
'+'
;
}
}
*
p
=
'\0'
;
if
(
po
->
standard
)
fprintf
(
fout
,
"%s
\n
"
,
border
);
}
if
(
po
->
standard
)
fputs
(
po
->
fieldSep
,
fout
);
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
char
*
s
=
PQfname
(
res
,
j
);
if
(
po
->
html3
)
{
fprintf
(
fout
,
"<th align=%s>%s</th>"
,
fieldNotNum
[
j
]
?
"left"
:
"right"
,
fieldNames
[
j
]);
}
else
{
int
n
=
strlen
(
s
);
if
(
n
>
fieldMax
[
j
])
fieldMax
[
j
]
=
n
;
if
(
po
->
standard
)
fprintf
(
fout
,
fieldNotNum
[
j
]
?
" %-*s "
:
" %*s "
,
fieldMax
[
j
],
s
);
else
fprintf
(
fout
,
fieldNotNum
[
j
]
?
"%-*s"
:
"%*s"
,
fieldMax
[
j
],
s
);
if
(
po
->
standard
||
(
j
+
1
)
<
nFields
)
fputs
(
po
->
fieldSep
,
fout
);
}
}
if
(
po
->
html3
)
fputs
(
"</tr>
\n
"
,
fout
);
else
fprintf
(
fout
,
"
\n
%s
\n
"
,
border
);
}
static
void
output_row
(
FILE
*
fout
,
PQprintOpt
*
po
,
const
int
nFields
,
char
*
fields
[],
unsigned
char
fieldNotNum
[],
int
fieldMax
[],
char
*
border
,
const
int
row_index
)
{
int
field_index
;
/* for loop index */
if
(
po
->
html3
)
fputs
(
"<tr>"
,
fout
);
else
if
(
po
->
standard
)
fputs
(
po
->
fieldSep
,
fout
);
for
(
field_index
=
0
;
field_index
<
nFields
;
field_index
++
)
{
char
*
p
=
fields
[
row_index
*
nFields
+
field_index
];
if
(
po
->
html3
)
fprintf
(
fout
,
"<td align=%s>%s</td>"
,
fieldNotNum
[
field_index
]
?
"left"
:
"right"
,
p
?
p
:
""
);
else
{
fprintf
(
fout
,
fieldNotNum
[
field_index
]
?
(
po
->
standard
?
" %-*s "
:
"%-*s"
)
:
(
po
->
standard
?
" %*s "
:
"%*s"
),
fieldMax
[
field_index
],
p
?
p
:
""
);
if
(
po
->
standard
||
field_index
+
1
<
nFields
)
fputs
(
po
->
fieldSep
,
fout
);
}
if
(
p
)
free
(
p
);
}
if
(
po
->
html3
)
fputs
(
"</tr>"
,
fout
);
else
if
(
po
->
standard
)
fprintf
(
fout
,
"
\n
%s"
,
border
);
fputc
(
'\n'
,
fout
);
}
/*
* PQprint()
*
* new PQprintTuples routine (proff@suburbia.net)
* Format results of a query for printing.
*
* PQprintOpt is a typedef (structure) that containes
* various flags and options. consult libpq-fe.h for
* details
*
* Obsoletes PQprintTuples.
*/
void
...
...
@@ -875,7 +1069,7 @@ PQprint(FILE *fout,
nFields
=
PQnfields
(
res
);
if
(
nFields
>
0
)
{
/* only print
tuple
s with at least 1 field. */
if
(
nFields
>
0
)
{
/* only print
row
s with at least 1 field. */
int
i
,
j
;
int
nTups
;
int
*
fieldMax
=
NULL
;
/* in case we don't use them */
...
...
@@ -892,34 +1086,30 @@ PQprint(FILE *fout,
char
buf
[
8192
*
2
+
1
];
nTups
=
PQntuples
(
res
);
if
(
!
(
fieldNames
=
(
char
**
)
calloc
(
nFields
,
sizeof
(
char
*
))))
{
if
(
!
(
fieldNames
=
(
char
**
)
calloc
(
nFields
,
sizeof
(
char
*
))))
{
perror
(
"calloc"
);
exit
(
1
);
}
if
(
!
(
fieldNotNum
=
(
unsigned
char
*
)
calloc
(
nFields
,
1
)))
{
if
(
!
(
fieldNotNum
=
(
unsigned
char
*
)
calloc
(
nFields
,
1
)))
{
perror
(
"calloc"
);
exit
(
1
);
}
if
(
!
(
fieldMax
=
(
int
*
)
calloc
(
nFields
,
sizeof
(
int
))))
{
if
(
!
(
fieldMax
=
(
int
*
)
calloc
(
nFields
,
sizeof
(
int
))))
{
perror
(
"calloc"
);
exit
(
1
);
}
for
(
numFieldName
=
0
;
po
->
fieldName
&&
po
->
fieldName
[
numFieldName
];
numFieldName
++
)
for
(
numFieldName
=
0
;
po
->
fieldName
&&
po
->
fieldName
[
numFieldName
];
numFieldName
++
)
;
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
int
len
;
char
*
s
=
(
j
<
numFieldName
&&
po
->
fieldName
[
j
][
0
])
?
po
->
fieldName
[
j
]
:
PQfname
(
res
,
j
);
char
*
s
=
(
j
<
numFieldName
&&
po
->
fieldName
[
j
][
0
])
?
po
->
fieldName
[
j
]
:
PQfname
(
res
,
j
);
fieldNames
[
j
]
=
s
;
len
=
s
?
strlen
(
s
)
:
0
;
len
=
s
?
strlen
(
s
)
:
0
;
fieldMax
[
j
]
=
len
;
/*
if (po->header && len<5)
len=5;
*/
len
+=
fs_len
;
if
(
len
>
fieldMaxLen
)
fieldMaxLen
=
len
;
...
...
@@ -932,14 +1122,12 @@ PQprint(FILE *fout,
fout
=
stdout
;
if
(
po
->
pager
&&
fout
==
stdout
&&
isatty
(
fileno
(
stdin
))
&&
isatty
(
fileno
(
stdout
)))
{
isatty
(
fileno
(
stdout
)))
{
/* try to pipe to the pager program if possible */
#ifdef TIOCGWINSZ
if
(
ioctl
(
fileno
(
stdout
),
TIOCGWINSZ
,
&
screen_size
)
==
-
1
||
screen_size
.
ws_col
==
0
||
screen_size
.
ws_row
==
0
)
{
screen_size
.
ws_row
==
0
)
{
#endif
screen_size
.
ws_row
=
24
;
screen_size
.
ws_col
=
80
;
...
...
@@ -959,8 +1147,7 @@ PQprint(FILE *fout,
(
po
->
header
!=
0
)
*
(
total_line_length
/
screen_size
.
ws_col
+
1
)
*
2
-
(
po
->
header
!=
0
)
*
2
/* row count and newline */
)))
{
)))
{
fout
=
popen
(
pagerenv
,
"w"
);
if
(
fout
)
{
usePipe
=
1
;
...
...
@@ -970,29 +1157,22 @@ PQprint(FILE *fout,
}
}
if
(
!
po
->
expanded
&&
(
po
->
align
||
po
->
html3
))
{
if
(
!
(
fields
=
(
char
**
)
calloc
(
nFields
*
(
nTups
+
1
),
sizeof
(
char
*
))))
{
if
(
!
po
->
expanded
&&
(
po
->
align
||
po
->
html3
))
{
if
(
!
(
fields
=
(
char
**
)
calloc
(
nFields
*
(
nTups
+
1
),
sizeof
(
char
*
))))
{
perror
(
"calloc"
);
exit
(
1
);
}
}
else
if
(
po
->
header
&&
!
po
->
html3
)
{
if
(
po
->
expanded
)
{
}
else
if
(
po
->
header
&&
!
po
->
html3
)
{
if
(
po
->
expanded
)
{
if
(
po
->
align
)
fprintf
(
fout
,
"%-*s%s Value
\n
"
,
fieldMaxLen
-
fs_len
,
"Field"
,
po
->
fieldSep
);
fprintf
(
fout
,
"%-*s%s Value
\n
"
,
fieldMaxLen
-
fs_len
,
"Field"
,
po
->
fieldSep
);
else
fprintf
(
fout
,
"%s%sValue
\n
"
,
"Field"
,
po
->
fieldSep
);
}
else
{
}
else
{
int
len
=
0
;
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
char
*
s
=
fieldNames
[
j
];
fputs
(
s
,
fout
);
len
+=
strlen
(
s
)
+
fs_len
;
...
...
@@ -1004,195 +1184,55 @@ PQprint(FILE *fout,
fputc
(
'\n'
,
fout
);
}
}
if
(
po
->
expanded
&&
po
->
html3
)
{
if
(
po
->
expanded
&&
po
->
html3
)
{
if
(
po
->
caption
)
fprintf
(
fout
,
"<centre><h2>%s</h2></centre>
\n
"
,
po
->
caption
);
else
fprintf
(
fout
,
"<centre><h2>Query retrieved %d tuples * %d fields</h2></centre>
\n
"
,
nTups
,
nFields
);
fprintf
(
fout
,
"<centre><h2>"
"Query retrieved %d rows * %d fields"
"</h2></centre>
\n
"
,
nTups
,
nFields
);
}
for
(
i
=
0
;
i
<
nTups
;
i
++
)
{
if
(
po
->
expanded
)
{
for
(
i
=
0
;
i
<
nTups
;
i
++
)
{
if
(
po
->
expanded
)
{
if
(
po
->
html3
)
fprintf
(
fout
,
"<table %s><caption align=high>%d</caption>
\n
"
,
po
->
tableOpt
?
po
->
tableOpt
:
""
,
i
);
fprintf
(
fout
,
"<table %s><caption align=high>%d</caption>
\n
"
,
po
->
tableOpt
?
po
->
tableOpt
:
""
,
i
);
else
fprintf
(
fout
,
"-- RECORD %d --
\n
"
,
i
);
}
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
char
*
pval
,
*
p
,
*
o
;
int
plen
;
if
((
plen
=
PQgetlength
(
res
,
i
,
j
))
<
1
||
!
(
pval
=
PQgetvalue
(
res
,
i
,
j
))
||
!*
pval
)
{
if
(
po
->
align
||
po
->
expanded
)
continue
;
goto
efield
;
}
for
(
p
=
pval
,
o
=
buf
;
*
p
;
*
(
o
++
)
=*
(
p
++
))
{
if
((
fs_len
==
1
&&
(
*
p
==*
(
po
->
fieldSep
)))
||
*
p
==
'\\'
)
*
(
o
++
)
=
'\\'
;
if
(
po
->
align
&&
(
*
pval
==
'E'
||
*
pval
==
'e'
||
!
((
*
p
>=
'0'
&&
*
p
<=
'9'
)
||
*
p
==
'.'
||
*
p
==
'E'
||
*
p
==
'e'
||
*
p
==
' '
||
*
p
==
'-'
)))
fieldNotNum
[
j
]
=
1
;
}
*
o
=
'\0'
;
if
(
!
po
->
expanded
&&
(
po
->
align
||
po
->
html3
))
{
int
n
=
strlen
(
buf
);
if
(
n
>
fieldMax
[
j
])
fieldMax
[
j
]
=
n
;
if
(
!
(
fields
[
i
*
nFields
+
j
]
=
(
char
*
)
malloc
(
n
+
1
)))
{
perror
(
"malloc"
);
exit
(
1
);
}
strcpy
(
fields
[
i
*
nFields
+
j
],
buf
);
}
else
{
if
(
po
->
expanded
)
{
if
(
po
->
html3
)
fprintf
(
fout
,
"<tr><td align=left><b>%s</b></td><td align=%s>%s</td></tr>
\n
"
,
fieldNames
[
j
],
fieldNotNum
[
j
]
?
"left"
:
"right"
,
buf
);
else
{
if
(
po
->
align
)
fprintf
(
fout
,
"%-*s%s %s
\n
"
,
fieldMaxLen
-
fs_len
,
fieldNames
[
j
],
po
->
fieldSep
,
buf
);
else
fprintf
(
fout
,
"%s%s%s
\n
"
,
fieldNames
[
j
],
po
->
fieldSep
,
buf
);
}
}
else
{
if
(
!
po
->
html3
)
{
fputs
(
buf
,
fout
);
efield:
if
((
j
+
1
)
<
nFields
)
fputs
(
po
->
fieldSep
,
fout
);
else
fputc
(
'\n'
,
fout
);
}
}
}
}
do_field
(
po
,
res
,
i
,
j
,
buf
,
fs_len
,
fields
,
nFields
,
fieldNames
,
fieldNotNum
,
fieldMax
,
fieldMaxLen
,
fout
);
if
(
po
->
html3
&&
po
->
expanded
)
fputs
(
"</table>
\n
"
,
fout
);
}
if
(
!
po
->
expanded
&&
(
po
->
align
||
po
->
html3
))
{
if
(
po
->
html3
)
{
if
(
po
->
header
)
{
if
(
!
po
->
expanded
&&
(
po
->
align
||
po
->
html3
))
{
if
(
po
->
html3
)
{
if
(
po
->
header
)
{
if
(
po
->
caption
)
fprintf
(
fout
,
"<table %s><caption align=high>%s</caption>
\n
"
,
po
->
tableOpt
?
po
->
tableOpt
:
""
,
po
->
caption
);
fprintf
(
fout
,
"<table %s><caption align=high>%s</caption>
\n
"
,
po
->
tableOpt
?
po
->
tableOpt
:
""
,
po
->
caption
);
else
fprintf
(
fout
,
"<table %s><caption align=high>Retrieved %d tuples * %d fields</caption>
\n
"
,
po
->
tableOpt
?
po
->
tableOpt
:
""
,
nTups
,
nFields
);
fprintf
(
fout
,
"<table %s><caption align=high>"
"Retrieved %d rows * %d fields"
"</caption>
\n
"
,
po
->
tableOpt
?
po
->
tableOpt
:
""
,
nTups
,
nFields
);
}
else
fprintf
(
fout
,
"<table %s>"
,
po
->
tableOpt
?
po
->
tableOpt
:
""
);
}
if
(
po
->
header
)
{
if
(
po
->
html3
)
fputs
(
"<tr>"
,
fout
);
else
{
int
tot
=
0
;
int
n
=
0
;
char
*
p
;
for
(;
n
<
nFields
;
n
++
)
tot
+=
fieldMax
[
n
]
+
fs_len
+
(
po
->
standard
?
2
:
0
);
if
(
po
->
standard
)
tot
+=
fs_len
*
2
+
2
;
if
(
!
(
p
=
border
=
malloc
(
tot
+
1
)))
{
perror
(
"malloc"
);
exit
(
1
);
}
if
(
po
->
standard
)
{
char
*
fs
=
po
->
fieldSep
;
while
(
*
fs
++
)
*
p
++=
'+'
;
}
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
int
len
;
for
(
len
=
fieldMax
[
j
]
+
(
po
->
standard
?
2
:
0
)
;
len
--
;
*
p
++=
'-'
);
if
(
po
->
standard
||
(
j
+
1
)
<
nFields
)
{
char
*
fs
=
po
->
fieldSep
;
while
(
*
fs
++
)
*
p
++=
'+'
;
}
}
*
p
=
'\0'
;
if
(
po
->
standard
)
fprintf
(
fout
,
"%s
\n
"
,
border
);
}
if
(
po
->
standard
)
fputs
(
po
->
fieldSep
,
fout
);
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
char
*
s
=
PQfname
(
res
,
j
);
if
(
po
->
html3
)
{
fprintf
(
fout
,
"<th align=%s>%s</th>"
,
fieldNotNum
[
j
]
?
"left"
:
"right"
,
fieldNames
[
j
]);
}
else
{
int
n
=
strlen
(
s
);
if
(
n
>
fieldMax
[
j
])
fieldMax
[
j
]
=
n
;
if
(
po
->
standard
)
fprintf
(
fout
,
fieldNotNum
[
j
]
?
" %-*s "
:
" %*s "
,
fieldMax
[
j
],
s
);
else
fprintf
(
fout
,
fieldNotNum
[
j
]
?
"%-*s"
:
"%*s"
,
fieldMax
[
j
],
s
);
if
(
po
->
standard
||
(
j
+
1
)
<
nFields
)
fputs
(
po
->
fieldSep
,
fout
);
}
}
if
(
po
->
html3
)
fputs
(
"</tr>
\n
"
,
fout
);
else
fprintf
(
fout
,
"
\n
%s
\n
"
,
border
);
}
do_header
(
fout
,
po
,
nFields
,
fieldMax
,
fieldNames
,
fieldNotNum
,
fs_len
,
border
,
res
);
for
(
i
=
0
;
i
<
nTups
;
i
++
)
{
if
(
po
->
html3
)
fputs
(
"<tr>"
,
fout
);
else
if
(
po
->
standard
)
fputs
(
po
->
fieldSep
,
fout
);
for
(
j
=
0
;
j
<
nFields
;
j
++
)
{
char
*
p
=
fields
[
i
*
nFields
+
j
];
if
(
po
->
html3
)
fprintf
(
fout
,
"<td align=%s>%s</td>"
,
fieldNotNum
[
j
]
?
"left"
:
"right"
,
p
?
p
:
""
);
else
{
fprintf
(
fout
,
fieldNotNum
[
j
]
?
(
po
->
standard
?
" %-*s "
:
"%-*s"
)
:
(
po
->
standard
?
" %*s "
:
"%*s"
),
fieldMax
[
j
],
p
?
p
:
""
);
if
(
po
->
standard
||
(
j
+
1
)
<
nFields
)
fputs
(
po
->
fieldSep
,
fout
);
}
if
(
p
)
free
(
p
);
}
if
(
po
->
html3
)
fputs
(
"</tr>"
,
fout
);
else
if
(
po
->
standard
)
fprintf
(
fout
,
"
\n
%s"
,
border
);
fputc
(
'\n'
,
fout
);
}
output_row
(
fout
,
po
,
nFields
,
fields
,
fieldNotNum
,
fieldMax
,
border
,
i
);
free
(
fields
);
}
if
(
po
->
header
&&
!
po
->
html3
)
...
...
@@ -1201,8 +1241,7 @@ efield:
free
(
fieldMax
);
free
(
fieldNotNum
);
free
(
fieldNames
);
if
(
usePipe
)
{
if
(
usePipe
)
{
pclose
(
fout
);
signal
(
SIGPIPE
,
SIG_DFL
);
}
...
...
@@ -1303,9 +1342,11 @@ PQfn(PGconn *conn,
return
makeEmptyPGresult
(
conn
,
PGRES_FATAL_ERROR
);
case
'N'
:
/* print notice and go back to processing return values */
if
(
pqGets
(
conn
->
errorMessage
,
ERROR_MSG_LENGTH
,
pfin
,
pfdebug
)
==
1
)
{
if
(
pqGets
(
conn
->
errorMessage
,
ERROR_MSG_LENGTH
,
pfin
,
pfdebug
)
==
1
)
{
sprintf
(
conn
->
errorMessage
,
"Notice return detected from backend, but error message cannot be read"
);
"Notice return detected from backend, but message "
"cannot be read"
);
}
else
fprintf
(
stderr
,
"%s
\n
"
,
conn
->
errorMessage
);
/* keep iterating */
...
...
@@ -1472,7 +1513,7 @@ const char* PQoidStatus(PGresult *res) {
/*
PQgetvalue:
return the attribute value of field 'field_num' of
tuple
'tup_num'
row
'tup_num'
If res is binary, then the value returned is NOT a null-terminated
ASCII string, but the binary representation in the server's native
...
...
@@ -1491,7 +1532,8 @@ PQgetvalue(PGresult *res, int tup_num, int field_num)
if
(
tup_num
>
(
res
->
ntups
-
1
)
||
field_num
>
(
res
->
numAttributes
-
1
))
{
fprintf
(
stderr
,
"PQgetvalue: ERROR! field %d(of %d) of tuple %d(of %d) is not available"
,
"PQgetvalue: ERROR! field %d(of %d) of row %d(of %d) "
"is not available"
,
field_num
,
res
->
numAttributes
-
1
,
tup_num
,
res
->
ntups
);
}
...
...
@@ -1514,7 +1556,8 @@ PQgetlength(PGresult *res, int tup_num, int field_num)
if
(
tup_num
>
(
res
->
ntups
-
1
)
||
field_num
>
(
res
->
numAttributes
-
1
))
{
fprintf
(
stderr
,
"PQgetlength: ERROR! field %d(of %d) of tuple %d(of %d) is not available"
,
"PQgetlength: ERROR! field %d(of %d) of row %d(of %d) "
"is not available"
,
field_num
,
res
->
numAttributes
-
1
,
tup_num
,
res
->
ntups
);
}
...
...
@@ -1538,7 +1581,8 @@ PQgetisnull(PGresult *res, int tup_num, int field_num)
if
(
tup_num
>
(
res
->
ntups
-
1
)
||
field_num
>
(
res
->
numAttributes
-
1
))
{
fprintf
(
stderr
,
"PQgetisnull: ERROR! field %d(of %d) of tuple %d(of %d) is not available"
,
"PQgetisnull: ERROR! field %d(of %d) of row %d(of %d) "
"is not available"
,
field_num
,
res
->
numAttributes
-
1
,
tup_num
,
res
->
ntups
);
}
...
...
@@ -1547,5 +1591,3 @@ PQgetisnull(PGresult *res, int tup_num, int field_num)
else
return
0
;
}
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