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
c6cf2182
Commit
c6cf2182
authored
Jul 31, 1996
by
Marc G. Fournier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
already exists in the contrib directory
parent
3881cbd2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
0 additions
and
348 deletions
+0
-348
src/extend/pginsert/Makefile
src/extend/pginsert/Makefile
+0
-19
src/extend/pginsert/halt.c
src/extend/pginsert/halt.c
+0
-58
src/extend/pginsert/halt.h
src/extend/pginsert/halt.h
+0
-7
src/extend/pginsert/pginsert.c
src/extend/pginsert/pginsert.c
+0
-98
src/extend/pginsert/pginterface.c
src/extend/pginsert/pginterface.c
+0
-154
src/extend/pginsert/pginterface.h
src/extend/pginsert/pginterface.h
+0
-12
No files found.
src/extend/pginsert/Makefile
deleted
100644 → 0
View file @
3881cbd2
#
# Makefile
#
#
TARGET
=
pginsert
CFLAGS
=
-g
-Wall
-I
/u/postgres95/include
LIBS
=
-L
/u/postgres95/lib
-lpq
$(TARGET)
:
pginsert.o pginterface.o halt.o
$(CC)
-o
$(TARGET)
$(XFLAGS)
$(CFLAGS)
\
pginsert.o pginterface.o halt.o
$(LIBS)
clean
:
rm
-f
*
.o
$(TARGET)
log core
install
:
make clean
make
CFLAGS
=
-O
install
-s
-o
bin
-g
bin
$(TARGET)
/usr/local/bin
src/extend/pginsert/halt.c
deleted
100644 → 0
View file @
3881cbd2
/*
**
** halt.c
**
** This is used to print out error messages and exit
*/
#include <varargs.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
/*-------------------------------------------------------------------------
**
** halt - print error message, and call clean up routine or exit
**
**------------------------------------------------------------------------*/
/*VARARGS*/
void
halt
(
va_alist
)
va_dcl
{
va_list
arg_ptr
;
char
*
format
,
*
pstr
;
void
(
*
sig_func
)();
va_start
(
arg_ptr
);
format
=
va_arg
(
arg_ptr
,
char
*
);
if
(
strncmp
(
format
,
"PERROR"
,
6
)
!=
0
)
vfprintf
(
stderr
,
format
,
arg_ptr
);
else
{
for
(
pstr
=
format
+
6
;
*
pstr
==
' '
||
*
pstr
==
':'
;
pstr
++
)
;
vfprintf
(
stderr
,
pstr
,
arg_ptr
);
perror
(
""
);
}
va_end
(
arg_ptr
);
fflush
(
stderr
);
/* call one clean up function if defined */
if
(
(
sig_func
=
signal
(
SIGTERM
,
SIG_DFL
))
!=
SIG_DFL
&&
sig_func
!=
SIG_IGN
)
(
*
sig_func
)(
0
);
else
if
(
(
sig_func
=
signal
(
SIGHUP
,
SIG_DFL
))
!=
SIG_DFL
&&
sig_func
!=
SIG_IGN
)
(
*
sig_func
)(
0
);
else
if
(
(
sig_func
=
signal
(
SIGINT
,
SIG_DFL
))
!=
SIG_DFL
&&
sig_func
!=
SIG_IGN
)
(
*
sig_func
)(
0
);
else
if
(
(
sig_func
=
signal
(
SIGQUIT
,
SIG_DFL
))
!=
SIG_DFL
&&
sig_func
!=
SIG_IGN
)
(
*
sig_func
)(
0
);
exit
(
1
);
}
src/extend/pginsert/halt.h
deleted
100644 → 0
View file @
3881cbd2
/*
** halt.h
**
*/
void
halt
();
src/extend/pginsert/pginsert.c
deleted
100644 → 0
View file @
3881cbd2
/*
* insert.c
*
*/
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <halt.h>
#include <libpq-fe.h>
#include "pginterface.h"
int
main
(
int
argc
,
char
**
argv
)
{
char
query
[
4000
];
int
row
=
1
;
int
aint
;
float
afloat
;
double
adouble
;
char
achar
[
11
],
achar16
[
17
],
abpchar
[
11
],
avarchar
[
51
],
atext
[
51
];
time_t
aabstime
;
if
(
argc
!=
2
)
halt
(
"Usage: %s database
\n
"
,
argv
[
0
]);
connectdb
(
argv
[
1
],
NULL
,
NULL
,
NULL
,
NULL
);
skip_query_errors
=
1
;
doquery
(
"DROP TABLE testfetch"
);
skip_query_errors
=
0
;
doquery
(
"\
CREATE TABLE testfetch( \
aint int4, \
afloat float4, \
adouble float8, \
achar char, \
achar16 char16, \
abpchar char(10), \
avarchar varchar(50), \
atext text, \
aabstime abstime) \
"
);
while
(
1
)
{
sprintf
(
query
,
"INSERT INTO testfetch VALUES ( \
%d, \
2322.12, \
'923121.0323'::float8, \
'A', \
'Betty', \
'Charley', \
'Doug', \
'Ernie', \
'now' )"
,
row
);
doquery
(
query
);
doquery
(
"BEGIN WORK"
);
doquery
(
"DECLARE c_testfetch BINARY CURSOR FOR \
SELECT * FROM testfetch"
);
doquery
(
"FETCH ALL IN c_testfetch"
);
while
(
fetch
(
&
aint
,
&
afloat
,
&
adouble
,
achar
,
achar16
,
abpchar
,
avarchar
,
atext
,
&
aabstime
)
!=
END_OF_TUPLES
)
printf
(
"int %d
\n
float %f
\n
double %f
\n
char %s
\n
char16 %s
\n
\
bpchar %s
\n
varchar %s
\n
text %s
\n
abstime %s"
,
aint
,
afloat
,
adouble
,
achar
,
achar16
,
abpchar
,
avarchar
,
atext
,
ctime
(
&
aabstime
));
doquery
(
"CLOSE c_testfetch"
);
doquery
(
"COMMIT WORK"
);
printf
(
"--- %-d rows inserted so far
\n
"
,
row
);
row
++
;
}
disconnectdb
();
return
0
;
}
src/extend/pginsert/pginterface.c
deleted
100644 → 0
View file @
3881cbd2
/*
* pginterface.c
*
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include <halt.h>
#include <libpq-fe.h>
#include "pginterface.h"
static
void
sig_disconnect
();
static
void
set_signals
();
#define NUL '\0'
/* GLOBAL VARIABLES */
static
PGconn
*
conn
;
static
PGresult
*
res
=
NULL
;
int
skip_query_errors
=
0
;
/* LOCAL VARIABLES */
static
sigset_t
block_sigs
,
unblock_sigs
;
static
int
tuple
;
/*
**
** connectdb - returns PGconn structure
**
*/
PGconn
*
connectdb
(
char
*
dbName
,
char
*
pghost
,
char
*
pgport
,
char
*
pgoptions
,
char
*
pgtty
)
{
/* make a connection to the database */
conn
=
PQsetdb
(
pghost
,
pgport
,
pgoptions
,
pgtty
,
dbName
);
if
(
PQstatus
(
conn
)
==
CONNECTION_BAD
)
halt
(
"Connection to database '%s' failed.
\n
%s
\n
"
,
dbName
,
PQerrorMessage
(
conn
));
set_signals
();
return
conn
;
}
/*
**
** disconnectdb
**
*/
void
disconnectdb
()
{
PQfinish
(
conn
);
}
/*
**
** doquery - returns PGresult structure
**
*/
PGresult
*
doquery
(
char
*
query
)
{
if
(
res
!=
NULL
)
PQclear
(
res
);
sigprocmask
(
SIG_SETMASK
,
&
block_sigs
,
NULL
);
res
=
PQexec
(
conn
,
query
);
sigprocmask
(
SIG_SETMASK
,
&
unblock_sigs
,
NULL
);
if
(
skip_query_errors
==
0
&&
(
res
==
NULL
||
PQresultStatus
(
res
)
==
PGRES_BAD_RESPONSE
||
PQresultStatus
(
res
)
==
PGRES_NONFATAL_ERROR
||
PQresultStatus
(
res
)
==
PGRES_FATAL_ERROR
))
{
if
(
res
!=
NULL
)
fprintf
(
stderr
,
"query error: %s
\n
"
,
PQcmdStatus
(
res
));
else
fprintf
(
stderr
,
"connection error: %s
\n
"
,
PQerrorMessage
(
conn
));
PQfinish
(
conn
);
halt
(
"failed request: %s
\n
"
,
query
);
}
tuple
=
0
;
return
res
;
}
/*
**
** fetch - returns tuple number (starts at 0), or the value END_OF_TUPLES
** NULL pointers are skipped
**
*/
int
fetch
(
void
*
param
,
...)
{
va_list
ap
;
int
arg
,
num_args
;
num_args
=
PQnfields
(
res
);
if
(
tuple
>=
PQntuples
(
res
))
return
END_OF_TUPLES
;
va_start
(
ap
,
param
);
for
(
arg
=
0
;
arg
<
num_args
;
arg
++
)
{
if
(
param
!=
NULL
)
{
if
(
PQfsize
(
res
,
arg
)
==
-
1
)
{
memcpy
(
param
,
PQgetvalue
(
res
,
tuple
,
arg
),
PQgetlength
(
res
,
tuple
,
arg
));
((
char
*
)
param
)[
PQgetlength
(
res
,
tuple
,
arg
)]
=
NUL
;
}
else
memcpy
(
param
,
PQgetvalue
(
res
,
tuple
,
arg
),
PQfsize
(
res
,
arg
));
}
param
=
va_arg
(
ap
,
char
*
);
}
va_end
(
ap
);
return
tuple
++
;
}
/*
**
** sig_disconnect
**
*/
static
void
sig_disconnect
()
{
fprintf
(
stderr
,
"exiting...
\n
"
);
PQfinish
(
conn
);
exit
(
1
);
}
/*
**
** set_signals
**
*/
static
void
set_signals
()
{
sigemptyset
(
&
block_sigs
);
sigemptyset
(
&
unblock_sigs
);
sigaddset
(
&
block_sigs
,
SIGTERM
);
sigaddset
(
&
block_sigs
,
SIGHUP
);
sigaddset
(
&
block_sigs
,
SIGINT
);
/* sigaddset(&block_sigs,SIGQUIT); no block */
sigprocmask
(
SIG_SETMASK
,
&
unblock_sigs
,
NULL
);
signal
(
SIGTERM
,
sig_disconnect
);
signal
(
SIGHUP
,
sig_disconnect
);
signal
(
SIGINT
,
sig_disconnect
);
signal
(
SIGQUIT
,
sig_disconnect
);
}
src/extend/pginsert/pginterface.h
deleted
100644 → 0
View file @
3881cbd2
/*
* pglib.h
*
*/
PGresult
*
doquery
(
char
*
query
);
PGconn
*
connectdb
();
void
disconnectdb
();
int
fetch
(
void
*
param
,
...);
int
skip_query_errors
;
#define END_OF_TUPLES (-1)
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