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
a5d46425
Commit
a5d46425
authored
Sep 11, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update pginterface for 6.4. add manual page.
parent
4da5714c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
23 deletions
+119
-23
contrib/pginterface/README
contrib/pginterface/README
+5
-5
contrib/pginterface/pginterface.3
contrib/pginterface/pginterface.3
+71
-0
contrib/pginterface/pginterface.c
contrib/pginterface/pginterface.c
+43
-18
No files found.
contrib/pginterface/README
View file @
a5d46425
...
...
@@ -16,14 +16,14 @@ have a global variable that allows you to disable the error checking I
have added to the doquery() routine.
I have added a function called fetch(), which allows you to pass
pointers as parameters, and on return the variables are filled with
the
data from the binary cursor you opened. These binary cursors are not
useful
if you are running the query engine on a system with a different
pointers as parameters, and on return the variables are filled with
data
from the binary cursor you opened. These binary cursors are not useful
if you are running the query engine on a system with a different
architecture than the database server. If you pass a NULL pointer, the
column is skipped, and you can use libpq to handle it as you wish.
There are two functions, get_result() and set_result
, that allow you to
handle multiple result sets at the same time.
There are two functions, get_result() and set_result
(), that allow you
to
handle multiple result sets at the same time.
There is a reset_fetch() that starts the fetch back at the beginning.
...
...
contrib/pginterface/pginterface.3
0 → 100644
View file @
a5d46425
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/contrib/pginterface/Attic/pginterface.3,v 1.1 1998/09/11 05:14:08 momjian Exp $
.TH PGINTERFACE INTRO 08/08/98 PostgreSQL PostgreSQL
.SH DESCRIPTION
Pginterface allows you to cleanly interface to the libpq library,
more like a 4gl SQL interface.
.PP
It consists of set of simplified C functions that encapsulate the
functionality of libpq.
The functions are:
.nf
PGresult *doquery(char *query);
PGconn *connectdb();
void disconnectdb();
int fetch(void *param,...);
int fetchwithnulls(void *param,...);
void reset_fetch();
void on_error_continue();
void on_error_stop();
PGresult *get_result();
void set_result(PGresult *newres);
void unset_result(PGresult *oldres);
.fi
.PP
Many functions return a structure or value, so you can do more work
with the result if required.
.PP
You basically connect to the database with
.BR connectdb ,
issue your query with
.BR doquery ,
fetch the results with
.BR fetch ,
and finish with
.BR disconnectdb .
.PP
For
.IR select
queries,
.BR fetch
allows you to pass pointers as parameters, and on return the variables
are filled with data from the binary cursor you opened. These binary
cursors can not be used if you are running the
.BR pginterface
client on a system with a different architecture than the database
server. If you pass a NULL pointer parameter, the column is skipped.
.BR fetchwithnulls
allows you to retieve the
.IR null
status of the field by passing an
.IR int*
after each result pointer, which returns true or false if the field is null.
You can always use libpq functions on the PGresult pointer returned by
.BR doquery .
.BR reset_fetch
starts the fetch back at the beginning.
.PP
.BR get_result ,
.BR set_result ,
and
.BR unset_result
allow you to handle multiple result sets at the same time.
.PP
There are a variety of demonstration programs in the
.BR pginterface
source directory.
contrib/pginterface/pginterface.c
View file @
a5d46425
...
...
@@ -13,6 +13,14 @@
#define NUL '\0'
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/* GLOBAL VARIABLES */
static
PGconn
*
conn
;
static
PGresult
*
res
=
NULL
;
...
...
@@ -22,8 +30,8 @@ static PGresult *res = NULL;
static
int
on_error_state
=
ON_ERROR_STOP
;
static
in_result_block
=
false
;
static
was_get_unset_result
=
false
;
static
in_result_block
=
FALSE
;
static
was_get_unset_result
=
FALSE
;
/* LOCAL VARIABLES */
static
int
tuple
;
...
...
@@ -67,10 +75,10 @@ disconnectdb()
PGresult
*
doquery
(
char
*
query
)
{
if
(
res
!=
NULL
&&
in_result_block
==
false
&&
was_get_unset_result
==
false
)
if
(
res
!=
NULL
&&
in_result_block
==
FALSE
&&
was_get_unset_result
==
FALSE
)
PQclear
(
res
);
was_get_unset_result
=
false
;
was_get_unset_result
=
FALSE
;
res
=
PQexec
(
conn
,
query
);
if
(
on_error_state
==
ON_ERROR_STOP
&&
...
...
@@ -131,7 +139,7 @@ fetch(void *param,...)
**
** fetchwithnulls - returns tuple number (starts at 0),
** or the value END_OF_TUPLES
** Returns
true or false
into null indicator variables
** Returns
TRUE or FALSE
into null indicator variables
** NULL pointers are skipped
*/
int
...
...
@@ -200,9 +208,14 @@ on_error_continue()
*/
PGresult
*
get_result
()
{
was_get_unset_result
=
true
;
char
*
cmdstatus
=
PQcmdStatus
(
res
);
was_get_unset_result
=
TRUE
;
/* we have to store the fetch location somewhere */
memcpy
(
&
res
->
cmdStatus
[
CMDSTATUS_LEN
-
sizeof
(
tuple
)],
&
tuple
,
sizeof
(
tuple
));
cmdstatus
[
0
]
=
NUL
;
memcpy
(
&
cmdstatus
[
1
],
&
tuple
,
sizeof
(
tuple
));
return
res
;
}
...
...
@@ -213,18 +226,27 @@ PGresult *get_result()
*/
void
set_result
(
PGresult
*
newres
)
{
char
*
cmdstatus
=
PQcmdStatus
(
res
);
if
(
newres
==
NULL
)
halt
(
"set_result called with null result pointer
\n
"
);
if
(
res
!=
NULL
&&
was_get_unset_result
==
false
)
if
(
in_result_block
==
false
)
if
(
res
!=
NULL
&&
was_get_unset_result
==
FALSE
)
if
(
in_result_block
==
FALSE
)
PQclear
(
res
);
else
memcpy
(
&
res
->
cmdStatus
[
CMDSTATUS_LEN
-
sizeof
(
tuple
)],
&
tuple
,
sizeof
(
tuple
));
in_result_block
=
true
;
was_get_unset_result
=
false
;
memcpy
(
&
tuple
,
&
newres
->
cmdStatus
[
CMDSTATUS_LEN
-
sizeof
(
tuple
)],
sizeof
(
tuple
));
{
cmdstatus
[
0
]
=
NUL
;
memcpy
(
&
cmdstatus
[
1
],
&
tuple
,
sizeof
(
tuple
));
}
in_result_block
=
TRUE
;
was_get_unset_result
=
FALSE
;
cmdstatus
=
PQcmdStatus
(
newres
);
memcpy
(
&
tuple
,
&
cmdstatus
[
1
],
sizeof
(
tuple
));
res
=
newres
;
}
...
...
@@ -236,15 +258,18 @@ void set_result(PGresult *newres)
*/
void
unset_result
(
PGresult
*
oldres
)
{
char
*
cmdstatus
=
PQcmdStatus
(
oldres
);
if
(
oldres
==
NULL
)
halt
(
"unset_result called with null result pointer
\n
"
);
if
(
in_result_block
==
false
)
if
(
in_result_block
==
FALSE
)
halt
(
"Unset of result without being set.
\n
"
);
was_get_unset_result
=
true
;
memcpy
(
&
oldres
->
cmdStatus
[
CMDSTATUS_LEN
-
sizeof
(
tuple
)],
&
tuple
,
sizeof
(
tuple
));
in_result_block
=
false
;
was_get_unset_result
=
TRUE
;
cmdstatus
[
0
]
=
NUL
;
memcpy
(
&
cmdstatus
[
1
],
&
tuple
,
sizeof
(
tuple
));
in_result_block
=
FALSE
;
}
/*
...
...
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