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
bb373089
Commit
bb373089
authored
Mar 16, 2003
by
Michael Meskes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Forgot some files...
parent
a4f25b6a
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
51 additions
and
3392 deletions
+51
-3392
src/interfaces/ecpg/include/pgtypes_error.h
src/interfaces/ecpg/include/pgtypes_error.h
+3
-0
src/interfaces/ecpg/include/pgtypes_numeric.h
src/interfaces/ecpg/include/pgtypes_numeric.h
+48
-0
src/interfaces/ecpg/lib/Makefile
src/interfaces/ecpg/lib/Makefile
+0
-47
src/interfaces/ecpg/lib/connect.c
src/interfaces/ecpg/lib/connect.c
+0
-495
src/interfaces/ecpg/lib/data.c
src/interfaces/ecpg/lib/data.c
+0
-398
src/interfaces/ecpg/lib/descriptor.c
src/interfaces/ecpg/lib/descriptor.c
+0
-449
src/interfaces/ecpg/lib/error.c
src/interfaces/ecpg/lib/error.c
+0
-198
src/interfaces/ecpg/lib/execute.c
src/interfaces/ecpg/lib/execute.c
+0
-1143
src/interfaces/ecpg/lib/extern.h
src/interfaces/ecpg/lib/extern.h
+0
-102
src/interfaces/ecpg/lib/memory.c
src/interfaces/ecpg/lib/memory.c
+0
-95
src/interfaces/ecpg/lib/misc.c
src/interfaces/ecpg/lib/misc.c
+0
-149
src/interfaces/ecpg/lib/pg_type.h
src/interfaces/ecpg/lib/pg_type.h
+0
-73
src/interfaces/ecpg/lib/prepare.c
src/interfaces/ecpg/lib/prepare.c
+0
-155
src/interfaces/ecpg/lib/typename.c
src/interfaces/ecpg/lib/typename.c
+0
-88
No files found.
src/interfaces/ecpg/include/pgtypes_error.h
0 → 100644
View file @
bb373089
#define PGTYPES_OVERFLOW 201
#define PGTYPES_BAD_NUMERIC 202
#define PGTYPES_DIVIDE_ZERO 203
src/interfaces/ecpg/include/pgtypes_numeric.h
0 → 100644
View file @
bb373089
#ifndef PGTYPES_NUMERIC
#define PGTYPES_NUMERIC
typedef
unsigned
char
NumericDigit
;
typedef
struct
NumericVar
{
int
ndigits
;
/* number of digits in digits[] - can be 0! */
int
weight
;
/* weight of first digit */
int
rscale
;
/* result scale */
int
dscale
;
/* display scale */
int
sign
;
/* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
NumericDigit
*
buf
;
/* start of alloc'd space for digits[] */
NumericDigit
*
digits
;
/* decimal digits */
}
NumericVar
;
NumericVar
*
PGTYPESnew
(
void
);
void
PGTYPESnumeric_free
(
NumericVar
*
);
NumericVar
*
PGTYPESnumeric_aton
(
char
*
,
char
**
);
char
*
PGTYPESnumeric_ntoa
(
NumericVar
*
);
int
PGTYPESnumeric_add
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_sub
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_mul
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_div
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_cmp
(
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_iton
(
signed
int
,
NumericVar
*
);
int
PGTYPESnumeric_lton
(
signed
long
int
,
NumericVar
*
);
int
PGTYPESnumeric_copy
(
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_dton
(
double
,
NumericVar
*
);
int
PGTYPESnumeric_ntod
(
NumericVar
*
,
double
*
);
int
PGTYPESnumeric_ntoi
(
NumericVar
*
,
int
*
);
int
PGTYPESnumeric_ntol
(
NumericVar
*
,
long
*
);
int
decadd
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
deccmp
(
NumericVar
*
,
NumericVar
*
);
void
deccopy
(
NumericVar
*
,
NumericVar
*
);
int
deccvasc
(
char
*
,
int
,
NumericVar
*
);
int
deccvdbl
(
double
,
NumericVar
*
);
int
deccvint
(
int
,
NumericVar
*
);
int
deccvlong
(
long
,
NumericVar
*
);
int
decdiv
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
decmul
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
decsub
(
NumericVar
*
,
NumericVar
*
,
NumericVar
*
);
int
dectoasc
(
NumericVar
*
,
char
*
,
int
,
int
);
int
dectodbl
(
NumericVar
*
,
double
*
);
int
dectoint
(
NumericVar
*
,
int
*
);
int
dectolong
(
NumericVar
*
,
long
*
);
#endif
/* PGTYPES_NUMERIC */
src/interfaces/ecpg/lib/Makefile
deleted
100644 → 0
View file @
a4f25b6a
#-------------------------------------------------------------------------
#
# Makefile for ecpg library
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile,v 1.19 2003/02/13 13:11:52 meskes Exp $
#
#-------------------------------------------------------------------------
subdir
=
src/interfaces/ecpg/lib
top_builddir
=
../../../..
include
$(top_builddir)/src/Makefile.global
NAME
=
ecpg
SO_MAJOR_VERSION
=
3
SO_MINOR_VERSION
=
4.2
override CPPFLAGS
:
= -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS)
OBJS
=
execute.o typename.o descriptor.o data.o error.o prepare.o memory.o
\
connect.o misc.o
SHLIB_LINK
=
$(libpq)
all
:
all-lib
# Shared library stuff
include
$(top_srcdir)/src/Makefile.shlib
install
:
all installdirs install-lib
installdirs
:
$(mkinstalldirs)
$(DESTDIR)$(libdir)
uninstall
:
uninstall-lib
clean distclean maintainer-clean
:
clean-lib
rm
-f
$(OBJS)
depend dep
:
$(CC)
-MM
$(CFLAGS)
*
.c
>
depend
ifeq
(depend,$(wildcard depend))
include
depend
endif
src/interfaces/ecpg/lib/connect.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.20 2003/02/13 13:11:52 meskes Exp $ */
#include "postgres_fe.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
static
struct
connection
*
all_connections
=
NULL
,
*
actual_connection
=
NULL
;
struct
connection
*
ECPGget_connection
(
const
char
*
connection_name
)
{
struct
connection
*
con
=
all_connections
;
if
(
connection_name
==
NULL
||
strcmp
(
connection_name
,
"CURRENT"
)
==
0
)
return
actual_connection
;
for
(;
con
&&
strcmp
(
connection_name
,
con
->
name
)
!=
0
;
con
=
con
->
next
);
if
(
con
)
return
con
;
else
return
NULL
;
}
static
void
ecpg_finish
(
struct
connection
*
act
)
{
if
(
act
!=
NULL
)
{
struct
ECPGtype_information_cache
*
cache
,
*
ptr
;
ECPGlog
(
"ecpg_finish: finishing %s.
\n
"
,
act
->
name
);
PQfinish
(
act
->
connection
);
/* remove act from the list */
if
(
act
==
all_connections
)
all_connections
=
act
->
next
;
else
{
struct
connection
*
con
;
for
(
con
=
all_connections
;
con
->
next
&&
con
->
next
!=
act
;
con
=
con
->
next
);
if
(
con
->
next
)
con
->
next
=
act
->
next
;
}
if
(
actual_connection
==
act
)
actual_connection
=
all_connections
;
for
(
cache
=
act
->
cache_head
;
cache
;
ptr
=
cache
,
cache
=
cache
->
next
,
ECPGfree
(
ptr
));
ECPGfree
(
act
->
name
);
ECPGfree
(
act
);
}
else
ECPGlog
(
"ecpg_finish: called an extra time.
\n
"
);
}
bool
ECPGsetcommit
(
int
lineno
,
const
char
*
mode
,
const
char
*
connection_name
)
{
struct
connection
*
con
=
ECPGget_connection
(
connection_name
);
PGresult
*
results
;
if
(
!
ECPGinit
(
con
,
connection_name
,
lineno
))
return
(
false
);
ECPGlog
(
"ECPGsetcommit line %d action = %s connection = %s
\n
"
,
lineno
,
mode
,
con
->
name
);
if
(
con
->
autocommit
==
true
&&
strncmp
(
mode
,
"off"
,
strlen
(
"off"
))
==
0
)
{
if
(
con
->
committed
)
{
if
((
results
=
PQexec
(
con
->
connection
,
"begin transaction"
))
==
NULL
)
{
ECPGraise
(
lineno
,
ECPG_TRANS
,
NULL
);
return
false
;
}
PQclear
(
results
);
con
->
committed
=
false
;
}
con
->
autocommit
=
false
;
}
else
if
(
con
->
autocommit
==
false
&&
strncmp
(
mode
,
"on"
,
strlen
(
"on"
))
==
0
)
{
if
(
!
con
->
committed
)
{
if
((
results
=
PQexec
(
con
->
connection
,
"commit"
))
==
NULL
)
{
ECPGraise
(
lineno
,
ECPG_TRANS
,
NULL
);
return
false
;
}
PQclear
(
results
);
con
->
committed
=
true
;
}
con
->
autocommit
=
true
;
}
return
true
;
}
bool
ECPGsetconn
(
int
lineno
,
const
char
*
connection_name
)
{
struct
connection
*
con
=
ECPGget_connection
(
connection_name
);
if
(
!
ECPGinit
(
con
,
connection_name
,
lineno
))
return
(
false
);
actual_connection
=
con
;
return
true
;
}
static
void
ECPGnoticeProcessor_raise
(
int
code
,
const
char
*
message
)
{
sqlca
.
sqlcode
=
code
;
strncpy
(
sqlca
.
sqlerrm
.
sqlerrmc
,
message
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
));
sqlca
.
sqlerrm
.
sqlerrmc
[
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
)
-
1
]
=
0
;
sqlca
.
sqlerrm
.
sqlerrml
=
strlen
(
sqlca
.
sqlerrm
.
sqlerrmc
);
/* remove trailing newline */
if
(
sqlca
.
sqlerrm
.
sqlerrml
&&
sqlca
.
sqlerrm
.
sqlerrmc
[
sqlca
.
sqlerrm
.
sqlerrml
-
1
]
==
'\n'
)
{
sqlca
.
sqlerrm
.
sqlerrmc
[
sqlca
.
sqlerrm
.
sqlerrml
-
1
]
=
0
;
sqlca
.
sqlerrm
.
sqlerrml
--
;
}
ECPGlog
(
"raising sqlcode %d
\n
"
,
code
);
}
/*
* I know this is a mess, but we can't redesign the backend
*/
static
void
ECPGnoticeProcessor
(
void
*
arg
,
const
char
*
message
)
{
/* these notices raise an error */
if
(
strncmp
(
message
,
"WARNING: "
,
9
))
{
ECPGlog
(
"ECPGnoticeProcessor: strange warning '%s'
\n
"
,
message
);
ECPGnoticeProcessor_raise
(
ECPG_WARNING_UNRECOGNIZED
,
message
);
return
;
}
message
+=
8
;
while
(
*
message
==
' '
)
message
++
;
ECPGlog
(
"WARNING: %s"
,
message
);
/* WARNING: (transaction aborted): queries ignored until END */
/*
* WARNING: current transaction is aborted, queries ignored until end
* of transaction block
*/
if
(
strstr
(
message
,
"queries ignored"
)
&&
strstr
(
message
,
"transaction"
)
&&
strstr
(
message
,
"aborted"
))
{
ECPGnoticeProcessor_raise
(
ECPG_WARNING_QUERY_IGNORED
,
message
);
return
;
}
/* WARNING: PerformPortalClose: portal "*" not found */
if
((
!
strncmp
(
message
,
"PerformPortalClose: portal"
,
26
)
||
!
strncmp
(
message
,
"PerformPortalFetch: portal"
,
26
))
&&
strstr
(
message
+
26
,
"not found"
))
{
ECPGnoticeProcessor_raise
(
ECPG_WARNING_UNKNOWN_PORTAL
,
message
);
return
;
}
/* WARNING: BEGIN: already a transaction in progress */
if
(
!
strncmp
(
message
,
"BEGIN: already a transaction in progress"
,
40
))
{
ECPGnoticeProcessor_raise
(
ECPG_WARNING_IN_TRANSACTION
,
message
);
return
;
}
/* WARNING: AbortTransaction and not in in-progress state */
/* WARNING: COMMIT: no transaction in progress */
/* WARNING: ROLLBACK: no transaction in progress */
if
(
!
strncmp
(
message
,
"AbortTransaction and not in in-progress state"
,
45
)
||
!
strncmp
(
message
,
"COMMIT: no transaction in progress"
,
34
)
||
!
strncmp
(
message
,
"ROLLBACK: no transaction in progress"
,
36
))
{
ECPGnoticeProcessor_raise
(
ECPG_WARNING_NO_TRANSACTION
,
message
);
return
;
}
/* WARNING: BlankPortalAssignName: portal * already exists */
if
(
!
strncmp
(
message
,
"BlankPortalAssignName: portal"
,
29
)
&&
strstr
(
message
+
29
,
"already exists"
))
{
ECPGnoticeProcessor_raise
(
ECPG_WARNING_PORTAL_EXISTS
,
message
);
return
;
}
/* these are harmless - do nothing */
/*
* WARNING: CREATE TABLE / PRIMARY KEY will create implicit index '*'
* for table '*'
*/
/*
* WARNING: ALTER TABLE ... ADD CONSTRAINT will create implicit
* trigger(s) for FOREIGN KEY check(s)
*/
/*
* WARNING: CREATE TABLE will create implicit sequence '*' for SERIAL
* column '*.*'
*/
/*
* WARNING: CREATE TABLE will create implicit trigger(s) for FOREIGN
* KEY check(s)
*/
if
((
!
strncmp
(
message
,
"CREATE TABLE"
,
12
)
||
!
strncmp
(
message
,
"ALTER TABLE"
,
11
))
&&
strstr
(
message
+
11
,
"will create implicit"
))
return
;
/* WARNING: QUERY PLAN: */
if
(
!
strncmp
(
message
,
"QUERY PLAN:"
,
11
))
/* do we really see these? */
return
;
/*
* WARNING: DROP TABLE implicitly drops referential integrity trigger
* from table "*"
*/
if
(
!
strncmp
(
message
,
"DROP TABLE implicitly drops"
,
27
))
return
;
/*
* WARNING: Caution: DROP INDEX cannot be rolled back, so don't abort
* now
*/
if
(
strstr
(
message
,
"cannot be rolled back"
))
return
;
/* these and other unmentioned should set sqlca.sqlwarn[2] */
/* WARNING: The ':' operator is deprecated. Use exp(x) instead. */
/* WARNING: Rel *: Uninitialized page 0 - fixing */
/* WARNING: PortalHeapMemoryFree: * not in alloc set! */
/* WARNING: Too old parent tuple found - can't continue vc_repair_frag */
/* WARNING: identifier "*" will be truncated to "*" */
/* WARNING: InvalidateSharedInvalid: cache state reset */
/* WARNING: RegisterSharedInvalid: SI buffer overflow */
sqlca
.
sqlwarn
[
2
]
=
'W'
;
sqlca
.
sqlwarn
[
0
]
=
'W'
;
}
/* this contains some quick hacks, needs to be cleaned up, but it works */
bool
ECPGconnect
(
int
lineno
,
const
char
*
name
,
const
char
*
user
,
const
char
*
passwd
,
const
char
*
connection_name
,
int
autocommit
)
{
struct
connection
*
this
;
char
*
dbname
=
strdup
(
name
),
*
host
=
NULL
,
*
tmp
,
*
port
=
NULL
,
*
realname
=
NULL
,
*
options
=
NULL
;
ECPGinit_sqlca
();
if
((
this
=
(
struct
connection
*
)
ECPGalloc
(
sizeof
(
struct
connection
),
lineno
))
==
NULL
)
return
false
;
if
(
dbname
==
NULL
&&
connection_name
==
NULL
)
connection_name
=
"DEFAULT"
;
/* get the detail information out of dbname */
if
(
strchr
(
dbname
,
'@'
)
!=
NULL
)
{
/* old style: dbname[@server][:port] */
tmp
=
strrchr
(
dbname
,
':'
);
if
(
tmp
!=
NULL
)
/* port number given */
{
port
=
strdup
(
tmp
+
1
);
*
tmp
=
'\0'
;
}
tmp
=
strrchr
(
dbname
,
'@'
);
if
(
tmp
!=
NULL
)
/* host name given */
{
host
=
strdup
(
tmp
+
1
);
*
tmp
=
'\0'
;
}
realname
=
strdup
(
dbname
);
}
else
if
(
strncmp
(
dbname
,
"tcp:"
,
4
)
==
0
||
strncmp
(
dbname
,
"unix:"
,
5
)
==
0
)
{
int
offset
=
0
;
/*
* only allow protocols tcp and unix
*/
if
(
strncmp
(
dbname
,
"tcp:"
,
4
)
==
0
)
offset
=
4
;
else
if
(
strncmp
(
dbname
,
"unix:"
,
5
)
==
0
)
offset
=
5
;
if
(
strncmp
(
dbname
+
offset
,
"postgresql://"
,
strlen
(
"postgresql://"
))
==
0
)
{
/*------
* new style:
* <tcp|unix>:postgresql://server[:port|:/unixsocket/path:]
* [/db name][?options]
*------
*/
offset
+=
strlen
(
"postgresql://"
);
tmp
=
strrchr
(
dbname
+
offset
,
'?'
);
if
(
tmp
!=
NULL
)
/* options given */
{
options
=
strdup
(
tmp
+
1
);
*
tmp
=
'\0'
;
}
tmp
=
strrchr
(
dbname
+
offset
,
'/'
);
if
(
tmp
!=
NULL
)
/* database name given */
{
realname
=
strdup
(
tmp
+
1
);
*
tmp
=
'\0'
;
}
tmp
=
strrchr
(
dbname
+
offset
,
':'
);
if
(
tmp
!=
NULL
)
/* port number or Unix socket path given */
{
char
*
tmp2
;
*
tmp
=
'\0'
;
if
((
tmp2
=
strchr
(
tmp
+
1
,
':'
))
!=
NULL
)
{
*
tmp2
=
'\0'
;
host
=
strdup
(
tmp
+
1
);
if
(
strncmp
(
dbname
,
"unix:"
,
5
)
!=
0
)
{
ECPGlog
(
"connect: socketname %s given for TCP connection in line %d
\n
"
,
host
,
lineno
);
ECPGraise
(
lineno
,
ECPG_CONNECT
,
realname
?
realname
:
"<DEFAULT>"
);
if
(
host
)
ECPGfree
(
host
);
if
(
port
)
ECPGfree
(
port
);
if
(
options
)
ECPGfree
(
options
);
if
(
realname
)
ECPGfree
(
realname
);
if
(
dbname
)
ECPGfree
(
dbname
);
return
false
;
}
}
else
port
=
strdup
(
tmp
+
1
);
}
if
(
strncmp
(
dbname
,
"unix:"
,
5
)
==
0
)
{
if
(
strcmp
(
dbname
+
offset
,
"localhost"
)
!=
0
&&
strcmp
(
dbname
+
offset
,
"127.0.0.1"
)
!=
0
)
{
ECPGlog
(
"connect: non-localhost access via sockets in line %d
\n
"
,
lineno
);
ECPGraise
(
lineno
,
ECPG_CONNECT
,
realname
?
realname
:
"<DEFAULT>"
);
if
(
host
)
ECPGfree
(
host
);
if
(
port
)
ECPGfree
(
port
);
if
(
options
)
ECPGfree
(
options
);
if
(
realname
)
ECPGfree
(
realname
);
if
(
dbname
)
ECPGfree
(
dbname
);
return
false
;
}
}
else
host
=
strdup
(
dbname
+
offset
);
}
else
realname
=
strdup
(
dbname
);
}
else
realname
=
strdup
(
dbname
);
/* add connection to our list */
if
(
connection_name
!=
NULL
)
this
->
name
=
ECPGstrdup
(
connection_name
,
lineno
);
else
this
->
name
=
ECPGstrdup
(
realname
,
lineno
);
this
->
cache_head
=
NULL
;
if
(
all_connections
==
NULL
)
this
->
next
=
NULL
;
else
this
->
next
=
all_connections
;
actual_connection
=
all_connections
=
this
;
ECPGlog
(
"ECPGconnect: opening database %s on %s port %s %s%s%s%s
\n
"
,
realname
?
realname
:
"<DEFAULT>"
,
host
?
host
:
"<DEFAULT>"
,
port
?
port
:
"<DEFAULT>"
,
options
?
"with options "
:
""
,
options
?
options
:
""
,
user
?
"for user "
:
""
,
user
?
user
:
""
);
this
->
connection
=
PQsetdbLogin
(
host
,
port
,
options
,
NULL
,
realname
,
user
,
passwd
);
if
(
PQstatus
(
this
->
connection
)
==
CONNECTION_BAD
)
{
const
char
*
errmsg
=
PQerrorMessage
(
this
->
connection
);
char
*
db
=
realname
?
realname
:
"<DEFAULT>"
;
set_backend_err
(
errmsg
,
lineno
);
ecpg_finish
(
this
);
ECPGlog
(
"connect: could not open database %s on %s port %s %s%s%s%s in line %d
\n\t
%s
\n
"
,
db
,
host
?
host
:
"<DEFAULT>"
,
port
?
port
:
"<DEFAULT>"
,
options
?
"with options "
:
""
,
options
?
options
:
""
,
user
?
"for user "
:
""
,
user
?
user
:
""
,
lineno
,
errmsg
);
ECPGraise
(
lineno
,
ECPG_CONNECT
,
db
);
if
(
host
)
ECPGfree
(
host
);
if
(
port
)
ECPGfree
(
port
);
if
(
options
)
ECPGfree
(
options
);
if
(
realname
)
ECPGfree
(
realname
);
if
(
dbname
)
ECPGfree
(
dbname
);
return
false
;
}
if
(
host
)
ECPGfree
(
host
);
if
(
port
)
ECPGfree
(
port
);
if
(
options
)
ECPGfree
(
options
);
if
(
realname
)
ECPGfree
(
realname
);
if
(
dbname
)
ECPGfree
(
dbname
);
this
->
committed
=
true
;
this
->
autocommit
=
autocommit
;
PQsetNoticeProcessor
(
this
->
connection
,
&
ECPGnoticeProcessor
,
(
void
*
)
this
);
return
true
;
}
bool
ECPGdisconnect
(
int
lineno
,
const
char
*
connection_name
)
{
struct
connection
*
con
;
if
(
strcmp
(
connection_name
,
"ALL"
)
==
0
)
{
ECPGinit_sqlca
();
for
(
con
=
all_connections
;
con
;)
{
struct
connection
*
f
=
con
;
con
=
con
->
next
;
ecpg_finish
(
f
);
}
}
else
{
con
=
ECPGget_connection
(
connection_name
);
if
(
!
ECPGinit
(
con
,
connection_name
,
lineno
))
return
(
false
);
else
ecpg_finish
(
con
);
}
return
true
;
}
src/interfaces/ecpg/lib/data.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/data.c,v 1.24 2002/09/04 20:31:46 momjian Exp $ */
#include "postgres_fe.h"
#include <stdlib.h>
#include <string.h>
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
bool
ECPGget_data
(
const
PGresult
*
results
,
int
act_tuple
,
int
act_field
,
int
lineno
,
enum
ECPGttype
type
,
enum
ECPGttype
ind_type
,
char
*
var
,
char
*
ind
,
long
varcharsize
,
long
offset
,
long
ind_offset
,
bool
isarray
)
{
char
*
pval
=
(
char
*
)
PQgetvalue
(
results
,
act_tuple
,
act_field
);
ECPGlog
(
"ECPGget_data line %d: RESULT: %s offset: %ld
\n
"
,
lineno
,
pval
?
pval
:
""
,
offset
);
/* pval is a pointer to the value */
/* let's check is it really is an array if it should be one */
if
(
isarray
)
{
if
(
*
pval
!=
'{'
)
{
ECPGraise
(
lineno
,
ECPG_DATA_NOT_ARRAY
,
NULL
);
return
(
false
);
}
switch
(
type
)
{
case
ECPGt_char
:
case
ECPGt_unsigned_char
:
case
ECPGt_varchar
:
break
;
default:
pval
++
;
break
;
}
}
/* We will have to decode the value */
/*
* check for null value and set indicator accordingly
*/
switch
(
ind_type
)
{
case
ECPGt_short
:
case
ECPGt_unsigned_short
:
/* ((short *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
*
((
short
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
-
PQgetisnull
(
results
,
act_tuple
,
act_field
);
break
;
case
ECPGt_int
:
case
ECPGt_unsigned_int
:
/* ((int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
*
((
int
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
-
PQgetisnull
(
results
,
act_tuple
,
act_field
);
break
;
case
ECPGt_long
:
case
ECPGt_unsigned_long
:
/* ((long *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
*
((
long
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
-
PQgetisnull
(
results
,
act_tuple
,
act_field
);
break
;
#ifdef HAVE_LONG_LONG_INT_64
case
ECPGt_long_long
:
case
ECPGt_unsigned_long_long
:
/* ((long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
*
((
long
long
int
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
-
PQgetisnull
(
results
,
act_tuple
,
act_field
);
break
;
/* case ECPGt_unsigned_long_long:
((unsigned long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
break;*/
#endif
/* HAVE_LONG_LONG_INT_64 */
case
ECPGt_NO_INDICATOR
:
if
(
PQgetisnull
(
results
,
act_tuple
,
act_field
))
{
ECPGraise
(
lineno
,
ECPG_MISSING_INDICATOR
,
NULL
);
return
(
false
);
}
break
;
default:
ECPGraise
(
lineno
,
ECPG_UNSUPPORTED
,
ECPGtype_name
(
ind_type
));
return
(
false
);
break
;
}
do
{
switch
(
type
)
{
long
res
;
unsigned
long
ures
;
double
dres
;
char
*
scan_length
;
case
ECPGt_short
:
case
ECPGt_int
:
case
ECPGt_long
:
if
(
pval
)
{
res
=
strtol
(
pval
,
&
scan_length
,
10
);
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_INT_FORMAT
,
pval
);
return
(
false
);
}
}
else
res
=
0L
;
switch
(
type
)
{
case
ECPGt_short
:
/* ((short *) var)[act_tuple] = (short) res;*/
*
((
short
*
)
(
var
+
offset
*
act_tuple
))
=
(
short
)
res
;
break
;
case
ECPGt_int
:
/* ((int *) var)[act_tuple] = (int) res;*/
*
((
int
*
)
(
var
+
offset
*
act_tuple
))
=
(
int
)
res
;
break
;
case
ECPGt_long
:
/* ((long *) var)[act_tuple] = res;*/
*
((
long
*
)
(
var
+
offset
*
act_tuple
))
=
(
long
)
res
;
break
;
default:
/* Cannot happen */
break
;
}
break
;
case
ECPGt_unsigned_short
:
case
ECPGt_unsigned_int
:
case
ECPGt_unsigned_long
:
if
(
pval
)
{
ures
=
strtoul
(
pval
,
&
scan_length
,
10
);
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_UINT_FORMAT
,
pval
);
return
(
false
);
}
}
else
ures
=
0L
;
switch
(
type
)
{
case
ECPGt_unsigned_short
:
/* ((unsigned short *) var)[act_tuple] = (unsigned short) ures;*/
*
((
unsigned
short
*
)
(
var
+
offset
*
act_tuple
))
=
(
unsigned
short
)
ures
;
break
;
case
ECPGt_unsigned_int
:
/* ((unsigned int *) var)[act_tuple] = (unsigned int) ures;*/
*
((
unsigned
int
*
)
(
var
+
offset
*
act_tuple
))
=
(
unsigned
int
)
ures
;
break
;
case
ECPGt_unsigned_long
:
/* ((unsigned long *) var)[act_tuple] = ures;*/
*
((
unsigned
long
*
)
(
var
+
offset
*
act_tuple
))
=
(
unsigned
long
)
ures
;
break
;
default:
/* Cannot happen */
break
;
}
break
;
#ifdef HAVE_LONG_LONG_INT_64
#ifdef HAVE_STRTOLL
case
ECPGt_long_long
:
if
(
pval
)
{
/* ((long long int *) var)[act_tuple] = strtoll(pval, &scan_length, 10);*/
*
((
long
long
int
*
)
(
var
+
offset
*
act_tuple
))
=
strtoll
(
pval
,
&
scan_length
,
10
);
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_INT_FORMAT
,
pval
);
return
(
false
);
}
}
else
/* ((long long int *) var)[act_tuple] = (long long) 0;*/
*
((
long
long
int
*
)
(
var
+
offset
*
act_tuple
))
=
(
long
long
)
0
;
break
;
#endif
/* HAVE_STRTOLL */
#ifdef HAVE_STRTOULL
case
ECPGt_unsigned_long_long
:
if
(
pval
)
{
/* ((unsigned long long int *) var)[act_tuple] = strtoull(pval, &scan_length, 10);*/
*
((
unsigned
long
long
int
*
)
(
var
+
offset
*
act_tuple
))
=
strtoull
(
pval
,
&
scan_length
,
10
);
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_UINT_FORMAT
,
pval
);
return
(
false
);
}
}
else
/* ((unsigned long long int *) var)[act_tuple] = (long long) 0;*/
*
((
unsigned
long
long
int
*
)
(
var
+
offset
*
act_tuple
))
=
(
long
long
)
0
;
break
;
#endif
/* HAVE_STRTOULL */
#endif
/* HAVE_LONG_LONG_INT_64 */
case
ECPGt_float
:
case
ECPGt_double
:
if
(
pval
)
{
if
(
isarray
&&
*
pval
==
'"'
)
dres
=
strtod
(
pval
+
1
,
&
scan_length
);
else
dres
=
strtod
(
pval
,
&
scan_length
);
if
(
isarray
&&
*
scan_length
==
'"'
)
scan_length
++
;
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_FLOAT_FORMAT
,
pval
);
return
(
false
);
}
}
else
dres
=
0
.
0
;
switch
(
type
)
{
case
ECPGt_float
:
/* ((float *) var)[act_tuple] = dres;*/
*
((
float
*
)
(
var
+
offset
*
act_tuple
))
=
dres
;
break
;
case
ECPGt_double
:
/* ((double *) var)[act_tuple] = dres;*/
*
((
double
*
)
(
var
+
offset
*
act_tuple
))
=
dres
;
break
;
default:
/* Cannot happen */
break
;
}
break
;
case
ECPGt_bool
:
if
(
pval
)
{
if
(
pval
[
0
]
==
'f'
&&
pval
[
1
]
==
'\0'
)
{
if
(
offset
==
sizeof
(
char
))
/* ((char *) var)[act_tuple] = false;*/
*
((
char
*
)
(
var
+
offset
*
act_tuple
))
=
false
;
else
if
(
offset
==
sizeof
(
int
))
/* ((int *) var)[act_tuple] = false;*/
*
((
int
*
)
(
var
+
offset
*
act_tuple
))
=
false
;
else
ECPGraise
(
lineno
,
ECPG_CONVERT_BOOL
,
"different size"
);
break
;
}
else
if
(
pval
[
0
]
==
't'
&&
pval
[
1
]
==
'\0'
)
{
if
(
offset
==
sizeof
(
char
))
/* ((char *) var)[act_tuple] = true;*/
*
((
char
*
)
(
var
+
offset
*
act_tuple
))
=
true
;
else
if
(
offset
==
sizeof
(
int
))
/* ((int *) var)[act_tuple] = true;*/
*
((
int
*
)
(
var
+
offset
*
act_tuple
))
=
true
;
else
ECPGraise
(
lineno
,
ECPG_CONVERT_BOOL
,
"different size"
);
break
;
}
else
if
(
pval
[
0
]
==
'\0'
&&
PQgetisnull
(
results
,
act_tuple
,
act_field
))
{
/* NULL is valid */
break
;
}
}
ECPGraise
(
lineno
,
ECPG_CONVERT_BOOL
,
pval
);
return
(
false
);
break
;
case
ECPGt_char
:
case
ECPGt_unsigned_char
:
{
strncpy
((
char
*
)
((
long
)
var
+
offset
*
act_tuple
),
pval
,
varcharsize
);
if
(
varcharsize
&&
varcharsize
<
strlen
(
pval
))
{
/* truncation */
switch
(
ind_type
)
{
case
ECPGt_short
:
case
ECPGt_unsigned_short
:
/* ((short *) ind)[act_tuple] = strlen(pval);*/
*
((
short
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
strlen
(
pval
);
break
;
case
ECPGt_int
:
case
ECPGt_unsigned_int
:
/* ((int *) ind)[act_tuple] = strlen(pval);*/
*
((
int
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
strlen
(
pval
);
break
;
case
ECPGt_long
:
case
ECPGt_unsigned_long
:
/* ((long *) ind)[act_tuple] = strlen(pval);*/
*
((
long
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
strlen
(
pval
);
break
;
#ifdef HAVE_LONG_LONG_INT_64
case
ECPGt_long_long
:
case
ECPGt_unsigned_long_long
:
*
((
long
long
int
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
strlen
(
pval
);
break
;
#endif
/* HAVE_LONG_LONG_INT_64 */
default:
break
;
}
sqlca
.
sqlwarn
[
0
]
=
sqlca
.
sqlwarn
[
1
]
=
'W'
;
}
}
break
;
case
ECPGt_varchar
:
{
struct
ECPGgeneric_varchar
*
variable
=
(
struct
ECPGgeneric_varchar
*
)
((
long
)
var
+
offset
*
act_tuple
);
variable
->
len
=
strlen
(
pval
);
if
(
varcharsize
==
0
)
strncpy
(
variable
->
arr
,
pval
,
variable
->
len
);
else
strncpy
(
variable
->
arr
,
pval
,
varcharsize
);
if
(
varcharsize
>
0
&&
variable
->
len
>
varcharsize
)
{
/* truncation */
switch
(
ind_type
)
{
case
ECPGt_short
:
case
ECPGt_unsigned_short
:
/* ((short *) ind)[act_tuple] = variable->len;*/
*
((
short
*
)
(
ind
+
offset
*
act_tuple
))
=
variable
->
len
;
break
;
case
ECPGt_int
:
case
ECPGt_unsigned_int
:
/* ((int *) ind)[act_tuple] = variable->len;*/
*
((
int
*
)
(
ind
+
offset
*
act_tuple
))
=
variable
->
len
;
break
;
case
ECPGt_long
:
case
ECPGt_unsigned_long
:
/* ((long *) ind)[act_tuple] = variable->len;*/
*
((
long
*
)
(
ind
+
offset
*
act_tuple
))
=
variable
->
len
;
break
;
#ifdef HAVE_LONG_LONG_INT_64
case
ECPGt_long_long
:
case
ECPGt_unsigned_long_long
:
*
((
long
long
int
*
)
(
ind
+
ind_offset
*
act_tuple
))
=
variable
->
len
;
break
;
#endif
/* HAVE_LONG_LONG_INT_64 */
default:
break
;
}
sqlca
.
sqlwarn
[
0
]
=
sqlca
.
sqlwarn
[
1
]
=
'W'
;
variable
->
len
=
varcharsize
;
}
}
break
;
default:
ECPGraise
(
lineno
,
ECPG_UNSUPPORTED
,
ECPGtype_name
(
type
));
return
(
false
);
break
;
}
if
(
isarray
)
{
bool
string
=
false
;
/* set array to next entry */
++
act_tuple
;
/* set pval to the next entry */
for
(;
string
||
(
*
pval
!=
','
&&
*
pval
!=
'}'
);
++
pval
)
if
(
*
pval
==
'"'
)
string
=
string
?
false
:
true
;
if
(
*
pval
==
','
)
++
pval
;
}
}
while
(
isarray
&&
*
pval
!=
'}'
);
return
(
true
);
}
src/interfaces/ecpg/lib/descriptor.c
deleted
100644 → 0
View file @
a4f25b6a
/* dynamic SQL support routines
*
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/descriptor.c,v 1.23 2002/09/04 20:31:46 momjian Exp $
*/
#include "postgres_fe.h"
#include "pg_type.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
#include "sql3types.h"
struct
descriptor
*
all_descriptors
=
NULL
;
/* old internal convenience function that might go away later */
static
PGresult
*
ECPGresultByDescriptor
(
int
line
,
const
char
*
name
)
{
PGresult
**
resultpp
=
ECPGdescriptor_lvalue
(
line
,
name
);
if
(
resultpp
)
return
*
resultpp
;
return
NULL
;
}
static
unsigned
int
ECPGDynamicType_DDT
(
Oid
type
)
{
switch
(
type
)
{
case
DATEOID
:
return
SQL3_DDT_DATE
;
case
TIMEOID
:
return
SQL3_DDT_TIME
;
case
TIMESTAMPOID
:
return
SQL3_DDT_TIMESTAMP
;
case
TIMESTAMPTZOID
:
return
SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE
;
case
TIMETZOID
:
return
SQL3_DDT_TIME_WITH_TIME_ZONE
;
default:
return
SQL3_DDT_ILLEGAL
;
}
}
bool
ECPGget_desc_header
(
int
lineno
,
char
*
desc_name
,
int
*
count
)
{
PGresult
*
ECPGresult
;
ECPGinit_sqlca
();
ECPGresult
=
ECPGresultByDescriptor
(
lineno
,
desc_name
);
if
(
!
ECPGresult
)
return
false
;
*
count
=
PQnfields
(
ECPGresult
);
sqlca
.
sqlerrd
[
2
]
=
1
;
ECPGlog
(
"ECPGget_desc_header: found %d attributes.
\n
"
,
*
count
);
return
true
;
}
static
bool
get_int_item
(
int
lineno
,
void
*
var
,
enum
ECPGttype
vartype
,
int
value
)
{
switch
(
vartype
)
{
case
ECPGt_short
:
*
(
short
*
)
var
=
(
short
)
value
;
break
;
case
ECPGt_int
:
*
(
int
*
)
var
=
(
int
)
value
;
break
;
case
ECPGt_long
:
*
(
long
*
)
var
=
(
long
)
value
;
break
;
case
ECPGt_unsigned_short
:
*
(
unsigned
short
*
)
var
=
(
unsigned
short
)
value
;
break
;
case
ECPGt_unsigned_int
:
*
(
unsigned
int
*
)
var
=
(
unsigned
int
)
value
;
break
;
case
ECPGt_unsigned_long
:
*
(
unsigned
long
*
)
var
=
(
unsigned
long
)
value
;
break
;
#ifdef HAVE_LONG_LONG_INT_64
case
ECPGt_long_long
:
*
(
long
long
int
*
)
var
=
(
long
long
int
)
value
;
break
;
case
ECPGt_unsigned_long_long
:
*
(
unsigned
long
long
int
*
)
var
=
(
unsigned
long
long
int
)
value
;
break
;
#endif
/* HAVE_LONG_LONG_INT_64 */
case
ECPGt_float
:
*
(
float
*
)
var
=
(
float
)
value
;
break
;
case
ECPGt_double
:
*
(
double
*
)
var
=
(
double
)
value
;
break
;
default:
ECPGraise
(
lineno
,
ECPG_VAR_NOT_NUMERIC
,
NULL
);
return
(
false
);
}
return
(
true
);
}
static
bool
get_char_item
(
int
lineno
,
void
*
var
,
enum
ECPGttype
vartype
,
char
*
value
,
int
varcharsize
)
{
switch
(
vartype
)
{
case
ECPGt_char
:
case
ECPGt_unsigned_char
:
strncpy
((
char
*
)
var
,
value
,
varcharsize
);
break
;
case
ECPGt_varchar
:
{
struct
ECPGgeneric_varchar
*
variable
=
(
struct
ECPGgeneric_varchar
*
)
var
;
if
(
varcharsize
==
0
)
strncpy
(
variable
->
arr
,
value
,
strlen
(
value
));
else
strncpy
(
variable
->
arr
,
value
,
varcharsize
);
variable
->
len
=
strlen
(
value
);
if
(
varcharsize
>
0
&&
variable
->
len
>
varcharsize
)
variable
->
len
=
varcharsize
;
}
break
;
default:
ECPGraise
(
lineno
,
ECPG_VAR_NOT_CHAR
,
NULL
);
return
(
false
);
}
return
(
true
);
}
bool
ECPGget_desc
(
int
lineno
,
char
*
desc_name
,
int
index
,...)
{
va_list
args
;
PGresult
*
ECPGresult
;
enum
ECPGdtype
type
;
int
ntuples
,
act_tuple
;
struct
variable
data_var
;
va_start
(
args
,
index
);
ECPGinit_sqlca
();
ECPGresult
=
ECPGresultByDescriptor
(
lineno
,
desc_name
);
if
(
!
ECPGresult
)
return
(
false
);
ntuples
=
PQntuples
(
ECPGresult
);
if
(
ntuples
<
1
)
{
ECPGraise
(
lineno
,
ECPG_NOT_FOUND
,
NULL
);
return
(
false
);
}
if
(
index
<
1
||
index
>
PQnfields
(
ECPGresult
))
{
ECPGraise
(
lineno
,
ECPG_INVALID_DESCRIPTOR_INDEX
,
NULL
);
return
(
false
);
}
ECPGlog
(
"ECPGget_desc: reading items for tuple %d
\n
"
,
index
);
--
index
;
type
=
va_arg
(
args
,
enum
ECPGdtype
);
memset
(
&
data_var
,
0
,
sizeof
data_var
);
data_var
.
type
=
ECPGt_EORT
;
data_var
.
ind_type
=
ECPGt_NO_INDICATOR
;
while
(
type
!=
ECPGd_EODT
)
{
char
type_str
[
20
];
long
varcharsize
;
long
offset
;
long
arrsize
;
enum
ECPGttype
vartype
;
void
*
var
;
vartype
=
va_arg
(
args
,
enum
ECPGttype
);
var
=
va_arg
(
args
,
void
*
);
varcharsize
=
va_arg
(
args
,
long
);
arrsize
=
va_arg
(
args
,
long
);
offset
=
va_arg
(
args
,
long
);
switch
(
type
)
{
case
(
ECPGd_indicator
):
data_var
.
ind_type
=
vartype
;
data_var
.
ind_pointer
=
var
;
data_var
.
ind_varcharsize
=
varcharsize
;
data_var
.
ind_arrsize
=
arrsize
;
data_var
.
ind_offset
=
offset
;
if
(
data_var
.
ind_arrsize
==
0
||
data_var
.
ind_varcharsize
==
0
)
data_var
.
ind_value
=
*
((
void
**
)
(
data_var
.
ind_pointer
));
else
data_var
.
ind_value
=
data_var
.
ind_pointer
;
break
;
case
ECPGd_data
:
data_var
.
type
=
vartype
;
data_var
.
pointer
=
var
;
data_var
.
varcharsize
=
varcharsize
;
data_var
.
arrsize
=
arrsize
;
data_var
.
offset
=
offset
;
if
(
data_var
.
arrsize
==
0
||
data_var
.
varcharsize
==
0
)
data_var
.
value
=
*
((
void
**
)
(
data_var
.
pointer
));
else
data_var
.
value
=
data_var
.
pointer
;
break
;
case
ECPGd_name
:
if
(
!
get_char_item
(
lineno
,
var
,
vartype
,
PQfname
(
ECPGresult
,
index
),
varcharsize
))
return
(
false
);
ECPGlog
(
"ECPGget_desc: NAME = %s
\n
"
,
PQfname
(
ECPGresult
,
index
));
break
;
case
ECPGd_nullable
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
1
))
return
(
false
);
break
;
case
ECPGd_key_member
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
0
))
return
(
false
);
break
;
case
ECPGd_scale
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
(
PQfmod
(
ECPGresult
,
index
)
-
VARHDRSZ
)
&
0xffff
))
return
(
false
);
ECPGlog
(
"ECPGget_desc: SCALE = %d
\n
"
,
(
PQfmod
(
ECPGresult
,
index
)
-
VARHDRSZ
)
&
0xffff
);
break
;
case
ECPGd_precision
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
PQfmod
(
ECPGresult
,
index
)
>>
16
))
return
(
false
);
ECPGlog
(
"ECPGget_desc: PRECISION = %d
\n
"
,
PQfmod
(
ECPGresult
,
index
)
>>
16
);
break
;
case
ECPGd_octet
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
PQfsize
(
ECPGresult
,
index
)))
return
(
false
);
ECPGlog
(
"ECPGget_desc: OCTET_LENGTH = %d
\n
"
,
PQfsize
(
ECPGresult
,
index
));
break
;
case
ECPGd_length
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
PQfmod
(
ECPGresult
,
index
)
-
VARHDRSZ
))
return
(
false
);
ECPGlog
(
"ECPGget_desc: LENGTH = %d
\n
"
,
PQfmod
(
ECPGresult
,
index
)
-
VARHDRSZ
);
break
;
case
ECPGd_type
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
ECPGDynamicType
(
PQftype
(
ECPGresult
,
index
))))
return
(
false
);
ECPGlog
(
"ECPGget_desc: TYPE = %d
\n
"
,
ECPGDynamicType
(
PQftype
(
ECPGresult
,
index
)));
break
;
case
ECPGd_di_code
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
ECPGDynamicType_DDT
(
PQftype
(
ECPGresult
,
index
))))
return
(
false
);
ECPGlog
(
"ECPGget_desc: TYPE = %d
\n
"
,
ECPGDynamicType_DDT
(
PQftype
(
ECPGresult
,
index
)));
break
;
case
ECPGd_cardinality
:
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
PQntuples
(
ECPGresult
)))
return
(
false
);
ECPGlog
(
"ECPGget_desc: CARDINALITY = %d
\n
"
,
PQntuples
(
ECPGresult
));
break
;
case
ECPGd_ret_length
:
case
ECPGd_ret_octet
:
/*
* this is like ECPGstore_result
*/
if
(
arrsize
>
0
&&
ntuples
>
arrsize
)
{
ECPGlog
(
"ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d
\n
"
,
lineno
,
ntuples
,
arrsize
);
ECPGraise
(
lineno
,
ECPG_TOO_MANY_MATCHES
,
NULL
);
return
false
;
}
/* allocate storage if needed */
if
(
arrsize
==
0
&&
var
!=
NULL
&&
*
(
void
**
)
var
==
NULL
)
{
void
*
mem
=
(
void
*
)
ECPGalloc
(
offset
*
ntuples
,
lineno
);
*
(
void
**
)
var
=
mem
;
ECPGadd_mem
(
mem
,
lineno
);
var
=
mem
;
}
for
(
act_tuple
=
0
;
act_tuple
<
ntuples
;
act_tuple
++
)
{
if
(
!
get_int_item
(
lineno
,
var
,
vartype
,
PQgetlength
(
ECPGresult
,
act_tuple
,
index
)))
return
(
false
);
var
=
(
char
*
)
var
+
offset
;
ECPGlog
(
"ECPGget_desc: RETURNED[%d] = %d
\n
"
,
act_tuple
,
PQgetlength
(
ECPGresult
,
act_tuple
,
index
));
}
break
;
default:
snprintf
(
type_str
,
sizeof
(
type_str
),
"%d"
,
type
);
ECPGraise
(
lineno
,
ECPG_UNKNOWN_DESCRIPTOR_ITEM
,
type_str
);
return
(
false
);
}
type
=
va_arg
(
args
,
enum
ECPGdtype
);
}
if
(
data_var
.
type
!=
ECPGt_EORT
)
{
struct
statement
stmt
;
char
*
oldlocale
;
/* Make sure we do NOT honor the locale for numeric input */
/* since the database gives the standard decimal point */
oldlocale
=
strdup
(
setlocale
(
LC_NUMERIC
,
NULL
));
setlocale
(
LC_NUMERIC
,
"C"
);
memset
(
&
stmt
,
0
,
sizeof
stmt
);
stmt
.
lineno
=
lineno
;
/* desparate try to guess something sensible */
stmt
.
connection
=
ECPGget_connection
(
NULL
);
ECPGstore_result
(
ECPGresult
,
index
,
&
stmt
,
&
data_var
);
setlocale
(
LC_NUMERIC
,
oldlocale
);
ECPGfree
(
oldlocale
);
}
else
if
(
data_var
.
ind_type
!=
ECPGt_NO_INDICATOR
)
{
/*
* this is like ECPGstore_result but since we don't have a data
* variable at hand, we can't call it
*/
if
(
data_var
.
ind_arrsize
>
0
&&
ntuples
>
data_var
.
ind_arrsize
)
{
ECPGlog
(
"ECPGget_desc line %d: Incorrect number of matches (indicator): %d don't fit into array of %d
\n
"
,
lineno
,
ntuples
,
data_var
.
ind_arrsize
);
ECPGraise
(
lineno
,
ECPG_TOO_MANY_MATCHES
,
NULL
);
return
false
;
}
/* allocate storage if needed */
if
(
data_var
.
ind_arrsize
==
0
&&
data_var
.
ind_pointer
!=
NULL
&&
data_var
.
ind_value
==
NULL
)
{
void
*
mem
=
(
void
*
)
ECPGalloc
(
data_var
.
ind_offset
*
ntuples
,
lineno
);
*
(
void
**
)
data_var
.
ind_pointer
=
mem
;
ECPGadd_mem
(
mem
,
lineno
);
data_var
.
ind_value
=
mem
;
}
for
(
act_tuple
=
0
;
act_tuple
<
ntuples
;
act_tuple
++
)
{
if
(
!
get_int_item
(
lineno
,
data_var
.
ind_value
,
data_var
.
ind_type
,
-
PQgetisnull
(
ECPGresult
,
act_tuple
,
index
)))
return
(
false
);
data_var
.
ind_value
=
(
char
*
)
data_var
.
ind_value
+
data_var
.
ind_offset
;
ECPGlog
(
"ECPGget_desc: INDICATOR[%d] = %d
\n
"
,
act_tuple
,
-
PQgetisnull
(
ECPGresult
,
act_tuple
,
index
));
}
}
sqlca
.
sqlerrd
[
2
]
=
ntuples
;
return
(
true
);
}
bool
ECPGdeallocate_desc
(
int
line
,
const
char
*
name
)
{
struct
descriptor
*
i
;
struct
descriptor
**
lastptr
=
&
all_descriptors
;
ECPGinit_sqlca
();
for
(
i
=
all_descriptors
;
i
;
lastptr
=
&
i
->
next
,
i
=
i
->
next
)
{
if
(
!
strcmp
(
name
,
i
->
name
))
{
*
lastptr
=
i
->
next
;
ECPGfree
(
i
->
name
);
PQclear
(
i
->
result
);
ECPGfree
(
i
);
return
true
;
}
}
ECPGraise
(
line
,
ECPG_UNKNOWN_DESCRIPTOR
,
name
);
return
false
;
}
bool
ECPGallocate_desc
(
int
line
,
const
char
*
name
)
{
struct
descriptor
*
new
;
ECPGinit_sqlca
();
new
=
(
struct
descriptor
*
)
ECPGalloc
(
sizeof
(
struct
descriptor
),
line
);
if
(
!
new
)
return
false
;
new
->
next
=
all_descriptors
;
new
->
name
=
ECPGalloc
(
strlen
(
name
)
+
1
,
line
);
if
(
!
new
->
name
)
{
ECPGfree
(
new
);
return
false
;
}
new
->
result
=
PQmakeEmptyPGresult
(
NULL
,
0
);
if
(
!
new
->
result
)
{
ECPGfree
(
new
->
name
);
ECPGfree
(
new
);
ECPGraise
(
line
,
ECPG_OUT_OF_MEMORY
,
NULL
);
return
false
;
}
strcpy
(
new
->
name
,
name
);
all_descriptors
=
new
;
return
true
;
}
PGresult
**
ECPGdescriptor_lvalue
(
int
line
,
const
char
*
descriptor
)
{
struct
descriptor
*
i
;
for
(
i
=
all_descriptors
;
i
!=
NULL
;
i
=
i
->
next
)
{
if
(
!
strcmp
(
descriptor
,
i
->
name
))
return
&
i
->
result
;
}
ECPGraise
(
line
,
ECPG_UNKNOWN_DESCRIPTOR
,
(
char
*
)
descriptor
);
return
NULL
;
}
src/interfaces/ecpg/lib/error.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/error.c,v 1.19 2003/02/14 13:17:13 meskes Exp $ */
#include "postgres_fe.h"
#include <stdio.h>
#include "ecpgerrno.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "extern.h"
#include "sqlca.h"
/* This should hold the back-end error message from
* the last back-end operation. */
static
char
*
ECPGerr
;
void
ECPGraise
(
int
line
,
int
code
,
const
char
*
str
)
{
sqlca
.
sqlcode
=
code
;
switch
(
code
)
{
case
ECPG_NOT_FOUND
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"No data found in line %d."
,
line
);
break
;
case
ECPG_OUT_OF_MEMORY
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Out of memory in line %d."
,
line
);
break
;
case
ECPG_UNSUPPORTED
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Unsupported type %s in line %d."
,
str
,
line
);
break
;
case
ECPG_TOO_MANY_ARGUMENTS
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Too many arguments in line %d."
,
line
);
break
;
case
ECPG_TOO_FEW_ARGUMENTS
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Too few arguments in line %d."
,
line
);
break
;
case
ECPG_INT_FORMAT
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Not correctly formatted int type: %s line %d."
,
str
,
line
);
break
;
case
ECPG_UINT_FORMAT
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Not correctly formatted unsigned type: %s in line %d."
,
str
,
line
);
break
;
case
ECPG_FLOAT_FORMAT
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Not correctly formatted floating-point type: %s in line %d."
,
str
,
line
);
break
;
case
ECPG_CONVERT_BOOL
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Unable to convert %s to bool on line %d."
,
str
,
line
);
break
;
case
ECPG_EMPTY
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Empty query in line %d."
,
line
);
break
;
case
ECPG_MISSING_INDICATOR
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"NULL value without indicator in line %d."
,
line
);
break
;
case
ECPG_NO_ARRAY
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Variable is not an array in line %d."
,
line
);
break
;
case
ECPG_DATA_NOT_ARRAY
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Data read from backend is not an array in line %d."
,
line
);
break
;
case
ECPG_ARRAY_INSERT
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Trying to insert an array of variables in line %d."
,
line
);
break
;
case
ECPG_NO_CONN
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"No such connection %s in line %d."
,
str
,
line
);
break
;
case
ECPG_NOT_CONN
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Not connected to '%s' in line %d."
,
str
,
line
);
break
;
case
ECPG_INVALID_STMT
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Invalid statement name %s in line %d."
,
str
,
line
);
break
;
case
ECPG_UNKNOWN_DESCRIPTOR
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Descriptor %s not found in line %d."
,
str
,
line
);
break
;
case
ECPG_INVALID_DESCRIPTOR_INDEX
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Descriptor index out of range in line %d."
,
line
);
break
;
case
ECPG_UNKNOWN_DESCRIPTOR_ITEM
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Unknown descriptor item %s in line %d."
,
str
,
line
);
break
;
case
ECPG_VAR_NOT_NUMERIC
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Variable is not a numeric type in line %d."
,
line
);
break
;
case
ECPG_VAR_NOT_CHAR
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Variable is not a character type in line %d."
,
line
);
break
;
case
ECPG_PGSQL
:
{
int
slen
=
strlen
(
str
);
/* strip trailing newline */
if
(
slen
>
0
&&
str
[
slen
-
1
]
==
'\n'
)
slen
--
;
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"'%.*s' in line %d."
,
slen
,
str
,
line
);
break
;
}
case
ECPG_TRANS
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Error in transaction processing in line %d."
,
line
);
break
;
case
ECPG_CONNECT
:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"Could not connect to database %s in line %d."
,
str
,
line
);
break
;
default:
snprintf
(
sqlca
.
sqlerrm
.
sqlerrmc
,
sizeof
(
sqlca
.
sqlerrm
.
sqlerrmc
),
"SQL error #%d in line %d."
,
code
,
line
);
break
;
}
sqlca
.
sqlerrm
.
sqlerrml
=
strlen
(
sqlca
.
sqlerrm
.
sqlerrmc
);
ECPGlog
(
"raising sqlcode %d in line %d, '%s'.
\n
"
,
code
,
line
,
sqlca
.
sqlerrm
.
sqlerrmc
);
/* free all memory we have allocated for the user */
ECPGfree_auto_mem
();
}
/* Set the error message string from the backend */
void
set_backend_err
(
const
char
*
err
,
int
lineno
)
{
if
(
ECPGerr
)
ECPGfree
(
ECPGerr
);
if
(
!
err
)
{
ECPGerr
=
NULL
;
return
;
}
ECPGerr
=
ECPGstrdup
(
err
,
lineno
);
}
/* Retrieve the error message from the backend. */
char
*
ECPGerrmsg
(
void
)
{
return
ECPGerr
;
}
/* print out an error message */
void
sqlprint
(
void
)
{
sqlca
.
sqlerrm
.
sqlerrmc
[
sqlca
.
sqlerrm
.
sqlerrml
]
=
'\0'
;
fprintf
(
stderr
,
"sql error %s
\n
"
,
sqlca
.
sqlerrm
.
sqlerrmc
);
}
src/interfaces/ecpg/lib/execute.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.41 2003/02/13 13:11:52 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
* All the tidieous messing around with tuples is supposed to be hidden
* by this function.
*/
/* Author: Linus Tolke
(actually most if the code is "borrowed" from the distribution and just
slightly modified)
*/
/* Taken over as part of PostgreSQL by Michael Meskes <meskes@postgresql.org>
on Feb. 5th, 1998 */
#include "postgres_fe.h"
#include <stdio.h>
#include <locale.h>
#include "pg_type.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
#include "sql3types.h"
/* variables visible to the programs */
struct
sqlca
sqlca
=
{
{
'S'
,
'Q'
,
'L'
,
'C'
,
'A'
,
' '
,
' '
,
' '
},
sizeof
(
struct
sqlca
),
0
,
{
0
,
{
0
}
},
{
'N'
,
'O'
,
'T'
,
' '
,
'S'
,
'E'
,
'T'
,
' '
},
{
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}
};
/* This function returns a newly malloced string that has the \
in the argument quoted with \ and the ' quoted with ' as SQL92 says.
*/
static
char
*
quote_postgres
(
char
*
arg
,
int
lineno
)
{
char
*
res
=
(
char
*
)
ECPGalloc
(
2
*
strlen
(
arg
)
+
3
,
lineno
);
int
i
,
ri
=
0
;
if
(
!
res
)
return
(
res
);
res
[
ri
++
]
=
'\''
;
for
(
i
=
0
;
arg
[
i
];
i
++
,
ri
++
)
{
switch
(
arg
[
i
])
{
case
'\''
:
res
[
ri
++
]
=
'\''
;
break
;
case
'\\'
:
res
[
ri
++
]
=
'\\'
;
break
;
default:
;
}
res
[
ri
]
=
arg
[
i
];
}
res
[
ri
++
]
=
'\''
;
res
[
ri
]
=
'\0'
;
return
res
;
}
/*
* create a list of variables
* The variables are listed with input variables preceding outputvariables
* The end of each group is marked by an end marker.
* per variable we list:
* type - as defined in ecpgtype.h
* value - where to store the data
* varcharsize - length of string in case we have a stringvariable, else 0
* arraysize - 0 for pointer (we don't know the size of the array),
* 1 for simple variable, size for arrays
* offset - offset between ith and (i+1)th entry in an array,
* normally that means sizeof(type)
* ind_type - type of indicator variable
* ind_value - pointer to indicator variable
* ind_varcharsize - empty
* ind_arraysize - arraysize of indicator array
* ind_offset - indicator offset
*/
static
bool
create_statement
(
int
lineno
,
struct
connection
*
connection
,
struct
statement
**
stmt
,
char
*
query
,
va_list
ap
)
{
struct
variable
**
list
=
&
((
*
stmt
)
->
inlist
);
enum
ECPGttype
type
;
if
(
!
(
*
stmt
=
(
struct
statement
*
)
ECPGalloc
(
sizeof
(
struct
statement
),
lineno
)))
return
false
;
(
*
stmt
)
->
command
=
query
;
(
*
stmt
)
->
connection
=
connection
;
(
*
stmt
)
->
lineno
=
lineno
;
list
=
&
((
*
stmt
)
->
inlist
);
type
=
va_arg
(
ap
,
enum
ECPGttype
);
while
(
type
!=
ECPGt_EORT
)
{
if
(
type
==
ECPGt_EOIT
)
list
=
&
((
*
stmt
)
->
outlist
);
else
{
struct
variable
*
var
,
*
ptr
;
if
(
!
(
var
=
(
struct
variable
*
)
ECPGalloc
(
sizeof
(
struct
variable
),
lineno
)))
return
false
;
var
->
type
=
type
;
var
->
pointer
=
va_arg
(
ap
,
char
*
);
/* if variable is NULL, the statement hasn't been prepared */
if
(
var
->
pointer
==
NULL
)
{
ECPGraise
(
lineno
,
ECPG_INVALID_STMT
,
NULL
);
ECPGfree
(
var
);
return
false
;
}
var
->
varcharsize
=
va_arg
(
ap
,
long
);
var
->
arrsize
=
va_arg
(
ap
,
long
);
var
->
offset
=
va_arg
(
ap
,
long
);
if
(
var
->
arrsize
==
0
||
var
->
varcharsize
==
0
)
var
->
value
=
*
((
char
**
)
(
var
->
pointer
));
else
var
->
value
=
var
->
pointer
;
var
->
ind_type
=
va_arg
(
ap
,
enum
ECPGttype
);
var
->
ind_pointer
=
va_arg
(
ap
,
char
*
);
var
->
ind_varcharsize
=
va_arg
(
ap
,
long
);
var
->
ind_arrsize
=
va_arg
(
ap
,
long
);
var
->
ind_offset
=
va_arg
(
ap
,
long
);
var
->
next
=
NULL
;
if
(
var
->
ind_type
!=
ECPGt_NO_INDICATOR
&&
(
var
->
ind_arrsize
==
0
||
var
->
ind_varcharsize
==
0
))
var
->
ind_value
=
*
((
char
**
)
(
var
->
ind_pointer
));
else
var
->
ind_value
=
var
->
ind_pointer
;
for
(
ptr
=
*
list
;
ptr
&&
ptr
->
next
;
ptr
=
ptr
->
next
);
if
(
ptr
==
NULL
)
*
list
=
var
;
else
ptr
->
next
=
var
;
}
type
=
va_arg
(
ap
,
enum
ECPGttype
);
}
return
(
true
);
}
static
void
free_variable
(
struct
variable
*
var
)
{
struct
variable
*
var_next
;
if
(
var
==
(
struct
variable
*
)
NULL
)
return
;
var_next
=
var
->
next
;
ECPGfree
(
var
);
while
(
var_next
)
{
var
=
var_next
;
var_next
=
var
->
next
;
ECPGfree
(
var
);
}
}
static
void
free_statement
(
struct
statement
*
stmt
)
{
if
(
stmt
==
(
struct
statement
*
)
NULL
)
return
;
free_variable
(
stmt
->
inlist
);
free_variable
(
stmt
->
outlist
);
ECPGfree
(
stmt
);
}
static
char
*
next_insert
(
char
*
text
)
{
char
*
ptr
=
text
;
bool
string
=
false
;
for
(;
*
ptr
!=
'\0'
&&
(
*
ptr
!=
'?'
||
string
);
ptr
++
)
{
if
(
*
ptr
==
'\\'
)
/* escape character */
ptr
++
;
else
if
(
*
ptr
==
'\''
)
string
=
string
?
false
:
true
;
}
return
(
*
ptr
==
'\0'
)
?
NULL
:
ptr
;
}
/*
* push a value on the cache
*/
static
void
ECPGtypeinfocache_push
(
struct
ECPGtype_information_cache
**
cache
,
int
oid
,
bool
isarray
,
int
lineno
)
{
struct
ECPGtype_information_cache
*
new_entry
=
(
struct
ECPGtype_information_cache
*
)
ECPGalloc
(
sizeof
(
struct
ECPGtype_information_cache
),
lineno
);
new_entry
->
oid
=
oid
;
new_entry
->
isarray
=
isarray
;
new_entry
->
next
=
*
cache
;
*
cache
=
new_entry
;
}
static
bool
ECPGis_type_an_array
(
int
type
,
const
struct
statement
*
stmt
,
const
struct
variable
*
var
)
{
char
*
array_query
;
int
isarray
=
0
;
PGresult
*
query
;
struct
ECPGtype_information_cache
*
cache_entry
;
if
((
stmt
->
connection
->
cache_head
)
==
NULL
)
{
/*
* Text like types are not an array for ecpg, but postgres counts
* them as an array. This define reminds you to not 'correct'
* these values.
*/
#define not_an_array_in_ecpg false
/* populate cache with well known types to speed things up */
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
BOOLOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
BYTEAOID
,
not_an_array_in_ecpg
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
CHAROID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
NAMEOID
,
not_an_array_in_ecpg
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
INT8OID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
INT2OID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
INT2VECTOROID
,
true
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
INT4OID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
REGPROCOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
TEXTOID
,
not_an_array_in_ecpg
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
OIDOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
TIDOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
XIDOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
CIDOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
OIDVECTOROID
,
true
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
POINTOID
,
true
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
LSEGOID
,
true
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
PATHOID
,
not_an_array_in_ecpg
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
BOXOID
,
true
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
POLYGONOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
LINEOID
,
true
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
FLOAT4OID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
FLOAT8OID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
ABSTIMEOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
RELTIMEOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
TINTERVALOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
UNKNOWNOID
,
not_an_array_in_ecpg
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
CIRCLEOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
CASHOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
INETOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
CIDROID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
BPCHAROID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
VARCHAROID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
DATEOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
TIMEOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
TIMESTAMPOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
TIMESTAMPTZOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
INTERVALOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
TIMETZOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
ZPBITOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
VARBITOID
,
false
,
stmt
->
lineno
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
NUMERICOID
,
false
,
stmt
->
lineno
);
}
for
(
cache_entry
=
(
stmt
->
connection
->
cache_head
);
cache_entry
!=
NULL
;
cache_entry
=
cache_entry
->
next
)
{
if
(
cache_entry
->
oid
==
type
)
return
cache_entry
->
isarray
;
}
array_query
=
(
char
*
)
ECPGalloc
(
strlen
(
"select typelem from pg_type where oid="
)
+
11
,
stmt
->
lineno
);
sprintf
(
array_query
,
"select typelem from pg_type where oid=%d"
,
type
);
query
=
PQexec
(
stmt
->
connection
->
connection
,
array_query
);
ECPGfree
(
array_query
);
if
(
PQresultStatus
(
query
)
==
PGRES_TUPLES_OK
)
{
isarray
=
atol
((
char
*
)
PQgetvalue
(
query
,
0
,
0
));
if
(
ECPGDynamicType
(
type
)
==
SQL3_CHARACTER
||
ECPGDynamicType
(
type
)
==
SQL3_CHARACTER_VARYING
)
{
/*
* arrays of character strings are not yet implemented
*/
isarray
=
false
;
}
ECPGlog
(
"ECPGexecute line %d: TYPE database: %d C: %d array: %s
\n
"
,
stmt
->
lineno
,
type
,
var
->
type
,
isarray
?
"yes"
:
"no"
);
ECPGtypeinfocache_push
(
&
(
stmt
->
connection
->
cache_head
),
type
,
isarray
,
stmt
->
lineno
);
}
PQclear
(
query
);
return
isarray
;
}
bool
ECPGstore_result
(
const
PGresult
*
results
,
int
act_field
,
const
struct
statement
*
stmt
,
struct
variable
*
var
)
{
int
isarray
,
act_tuple
,
ntuples
=
PQntuples
(
results
);
bool
status
=
true
;
isarray
=
ECPGis_type_an_array
(
PQftype
(
results
,
act_field
),
stmt
,
var
);
if
(
!
isarray
)
{
/*
* if we don't have enough space, we cannot read all tuples
*/
if
((
var
->
arrsize
>
0
&&
ntuples
>
var
->
arrsize
)
||
(
var
->
ind_arrsize
>
0
&&
ntuples
>
var
->
ind_arrsize
))
{
ECPGlog
(
"ECPGexecute line %d: Incorrect number of matches: %d don't fit into array of %d
\n
"
,
stmt
->
lineno
,
ntuples
,
var
->
arrsize
);
ECPGraise
(
stmt
->
lineno
,
ECPG_TOO_MANY_MATCHES
,
NULL
);
return
false
;
}
}
else
{
/*
* since we read an array, the variable has to be an array too
*/
if
(
var
->
arrsize
==
0
)
{
ECPGraise
(
stmt
->
lineno
,
ECPG_NO_ARRAY
,
NULL
);
return
false
;
}
}
/*
* allocate memory for NULL pointers
*/
if
((
var
->
arrsize
==
0
||
var
->
varcharsize
==
0
)
&&
var
->
value
==
NULL
)
{
int
len
=
0
;
switch
(
var
->
type
)
{
case
ECPGt_char
:
case
ECPGt_unsigned_char
:
if
(
!
var
->
varcharsize
&&
!
var
->
arrsize
)
{
/* special mode for handling char**foo=0 */
for
(
act_tuple
=
0
;
act_tuple
<
ntuples
;
act_tuple
++
)
len
+=
strlen
(
PQgetvalue
(
results
,
act_tuple
,
act_field
))
+
1
;
len
*=
var
->
offset
;
/* should be 1, but YMNK */
len
+=
(
ntuples
+
1
)
*
sizeof
(
char
*
);
ECPGlog
(
"ECPGstore_result: line %d: allocating %d bytes for %d tuples (char**=0)"
,
stmt
->
lineno
,
len
,
ntuples
);
}
else
{
var
->
varcharsize
=
0
;
/* check strlen for each tuple */
for
(
act_tuple
=
0
;
act_tuple
<
ntuples
;
act_tuple
++
)
{
int
len
=
strlen
(
PQgetvalue
(
results
,
act_tuple
,
act_field
))
+
1
;
if
(
len
>
var
->
varcharsize
)
var
->
varcharsize
=
len
;
}
var
->
offset
*=
var
->
varcharsize
;
len
=
var
->
offset
*
ntuples
;
}
break
;
case
ECPGt_varchar
:
len
=
ntuples
*
(
var
->
varcharsize
+
sizeof
(
int
));
break
;
default:
len
=
var
->
offset
*
ntuples
;
break
;
}
var
->
value
=
(
char
*
)
ECPGalloc
(
len
,
stmt
->
lineno
);
*
((
char
**
)
var
->
pointer
)
=
var
->
value
;
ECPGadd_mem
(
var
->
value
,
stmt
->
lineno
);
}
/* allocate indicator variable if needed */
if
((
var
->
ind_arrsize
==
0
||
var
->
ind_varcharsize
==
0
)
&&
var
->
ind_value
==
NULL
&&
var
->
ind_pointer
!=
NULL
)
{
int
len
=
var
->
ind_offset
*
ntuples
;
var
->
ind_value
=
(
char
*
)
ECPGalloc
(
len
,
stmt
->
lineno
);
*
((
char
**
)
var
->
ind_pointer
)
=
var
->
ind_value
;
ECPGadd_mem
(
var
->
ind_value
,
stmt
->
lineno
);
}
/* fill the variable with the tuple(s) */
if
(
!
var
->
varcharsize
&&
!
var
->
arrsize
&&
(
var
->
type
==
ECPGt_char
||
var
->
type
==
ECPGt_unsigned_char
))
{
/* special mode for handling char**foo=0 */
/* filling the array of (char*)s */
char
**
current_string
=
(
char
**
)
var
->
value
;
/* storing the data (after the last array element) */
char
*
current_data_location
=
(
char
*
)
&
current_string
[
ntuples
+
1
];
for
(
act_tuple
=
0
;
act_tuple
<
ntuples
&&
status
;
act_tuple
++
)
{
int
len
=
strlen
(
PQgetvalue
(
results
,
act_tuple
,
act_field
))
+
1
;
if
(
!
ECPGget_data
(
results
,
act_tuple
,
act_field
,
stmt
->
lineno
,
var
->
type
,
var
->
ind_type
,
current_data_location
,
var
->
ind_value
,
len
,
0
,
0
,
isarray
))
status
=
false
;
else
{
*
current_string
=
current_data_location
;
current_data_location
+=
len
;
current_string
++
;
}
}
/* terminate the list */
*
current_string
=
NULL
;
}
else
{
for
(
act_tuple
=
0
;
act_tuple
<
ntuples
&&
status
;
act_tuple
++
)
{
if
(
!
ECPGget_data
(
results
,
act_tuple
,
act_field
,
stmt
->
lineno
,
var
->
type
,
var
->
ind_type
,
var
->
value
,
var
->
ind_value
,
var
->
varcharsize
,
var
->
offset
,
var
->
ind_offset
,
isarray
))
status
=
false
;
}
}
return
status
;
}
static
bool
ECPGstore_input
(
const
struct
statement
*
stmt
,
const
struct
variable
*
var
,
const
char
**
tobeinserted_p
,
bool
*
malloced_p
)
{
char
*
mallocedval
=
NULL
;
char
*
newcopy
=
NULL
;
/*
* arrays are not possible unless the attribute is an array too FIXME:
* we do not know if the attribute is an array here
*/
/* if (var->arrsize > 1 && ...)
{
ECPGraise(stmt->lineno, ECPG_ARRAY_INSERT, NULL);
return false;
}*/
/*
* Some special treatment is needed for records since we want their
* contents to arrive in a comma-separated list on insert (I think).
*/
*
malloced_p
=
false
;
*
tobeinserted_p
=
""
;
/* check for null value and set input buffer accordingly */
switch
(
var
->
ind_type
)
{
case
ECPGt_short
:
case
ECPGt_unsigned_short
:
if
(
*
(
short
*
)
var
->
ind_value
<
0
)
*
tobeinserted_p
=
"null"
;
break
;
case
ECPGt_int
:
case
ECPGt_unsigned_int
:
if
(
*
(
int
*
)
var
->
ind_value
<
0
)
*
tobeinserted_p
=
"null"
;
break
;
case
ECPGt_long
:
case
ECPGt_unsigned_long
:
if
(
*
(
long
*
)
var
->
ind_value
<
0L
)
*
tobeinserted_p
=
"null"
;
break
;
#ifdef HAVE_LONG_LONG_INT_64
case
ECPGt_long_long
:
case
ECPGt_unsigned_long_long
:
if
(
*
(
long
long
int
*
)
var
->
ind_value
<
(
long
long
)
0
)
*
tobeinserted_p
=
"null"
;
break
;
#endif
/* HAVE_LONG_LONG_INT_64 */
default:
break
;
}
if
(
**
tobeinserted_p
==
'\0'
)
{
switch
(
var
->
type
)
{
int
element
;
case
ECPGt_short
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
20
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%hd,"
,
((
short
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%hd"
,
*
((
short
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_int
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
20
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%d,"
,
((
int
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%d"
,
*
((
int
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_unsigned_short
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
20
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%hu,"
,
((
unsigned
short
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%hu"
,
*
((
unsigned
short
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_unsigned_int
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
20
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%u,"
,
((
unsigned
int
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%u"
,
*
((
unsigned
int
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_long
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
20
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%ld,"
,
((
long
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%ld"
,
*
((
long
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_unsigned_long
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
20
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%lu,"
,
((
unsigned
long
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%lu"
,
*
((
unsigned
long
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
#ifdef HAVE_LONG_LONG_INT_64
case
ECPGt_long_long
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
25
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%lld,"
,
((
long
long
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%lld"
,
*
((
long
long
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_unsigned_long_long
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
25
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%llu,"
,
((
unsigned
long
long
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%llu"
,
*
((
unsigned
long
long
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
#endif
/* HAVE_LONG_LONG_INT_64 */
case
ECPGt_float
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
21
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%.14g,"
,
((
float
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%.14g"
,
*
((
float
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_double
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
21
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%.14g,"
,
((
double
*
)
var
->
value
)[
element
]);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
sprintf
(
mallocedval
,
"%.14g"
,
*
((
double
*
)
var
->
value
));
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_bool
:
if
(
!
(
mallocedval
=
ECPGalloc
(
var
->
arrsize
*
2
,
stmt
->
lineno
)))
return
false
;
if
(
var
->
arrsize
>
1
)
{
strncpy
(
mallocedval
,
"'{"
,
sizeof
(
"'{"
));
if
(
var
->
offset
==
sizeof
(
char
))
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%c,"
,
(((
char
*
)
var
->
value
)[
element
])
?
't'
:
'f'
);
/*
* this is necessary since sizeof(C++'s
* bool)==sizeof(int)
*/
else
if
(
var
->
offset
==
sizeof
(
int
))
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
sprintf
(
mallocedval
+
strlen
(
mallocedval
),
"%c,"
,
(((
int
*
)
var
->
value
)[
element
])
?
't'
:
'f'
);
else
ECPGraise
(
stmt
->
lineno
,
ECPG_CONVERT_BOOL
,
"different size"
);
strncpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
,
sizeof
(
"}'"
));
}
else
{
if
(
var
->
offset
==
sizeof
(
char
))
sprintf
(
mallocedval
,
"'%c'"
,
(
*
((
char
*
)
var
->
value
))
?
't'
:
'f'
);
else
if
(
var
->
offset
==
sizeof
(
int
))
sprintf
(
mallocedval
,
"'%c'"
,
(
*
((
int
*
)
var
->
value
))
?
't'
:
'f'
);
else
ECPGraise
(
stmt
->
lineno
,
ECPG_CONVERT_BOOL
,
"different size"
);
}
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
break
;
case
ECPGt_char
:
case
ECPGt_unsigned_char
:
{
/* set slen to string length if type is char * */
int
slen
=
(
var
->
varcharsize
==
0
)
?
strlen
((
char
*
)
var
->
value
)
:
var
->
varcharsize
;
if
(
!
(
newcopy
=
ECPGalloc
(
slen
+
1
,
stmt
->
lineno
)))
return
false
;
strncpy
(
newcopy
,
(
char
*
)
var
->
value
,
slen
);
newcopy
[
slen
]
=
'\0'
;
mallocedval
=
quote_postgres
(
newcopy
,
stmt
->
lineno
);
if
(
!
mallocedval
)
return
false
;
ECPGfree
(
newcopy
);
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
}
break
;
case
ECPGt_char_variable
:
{
int
slen
=
strlen
((
char
*
)
var
->
value
);
if
(
!
(
mallocedval
=
ECPGalloc
(
slen
+
1
,
stmt
->
lineno
)))
return
false
;
strncpy
(
mallocedval
,
(
char
*
)
var
->
value
,
slen
);
mallocedval
[
slen
]
=
'\0'
;
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
}
break
;
case
ECPGt_varchar
:
{
struct
ECPGgeneric_varchar
*
variable
=
(
struct
ECPGgeneric_varchar
*
)
(
var
->
value
);
if
(
!
(
newcopy
=
(
char
*
)
ECPGalloc
(
variable
->
len
+
1
,
stmt
->
lineno
)))
return
false
;
strncpy
(
newcopy
,
variable
->
arr
,
variable
->
len
);
newcopy
[
variable
->
len
]
=
'\0'
;
mallocedval
=
quote_postgres
(
newcopy
,
stmt
->
lineno
);
if
(
!
mallocedval
)
return
false
;
ECPGfree
(
newcopy
);
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
}
break
;
default:
/* Not implemented yet */
ECPGraise
(
stmt
->
lineno
,
ECPG_UNSUPPORTED
,
(
char
*
)
ECPGtype_name
(
var
->
type
));
return
false
;
break
;
}
}
return
true
;
}
static
bool
ECPGexecute
(
struct
statement
*
stmt
)
{
bool
status
=
false
;
char
*
copiedquery
;
char
*
errmsg
,
*
cmdstat
;
PGresult
*
results
;
PGnotify
*
notify
;
struct
variable
*
var
;
copiedquery
=
ECPGstrdup
(
stmt
->
command
,
stmt
->
lineno
);
/*
* Now, if the type is one of the fill in types then we take the
* argument and enter that in the string at the first %s position.
* Then if there are any more fill in types we fill in at the next and
* so on.
*/
var
=
stmt
->
inlist
;
while
(
var
)
{
char
*
newcopy
=
NULL
;
const
char
*
tobeinserted
=
NULL
;
char
*
p
;
bool
malloced
=
FALSE
;
int
hostvarl
=
0
;
if
(
!
ECPGstore_input
(
stmt
,
var
,
&
tobeinserted
,
&
malloced
))
return
false
;
/*
* Now tobeinserted points to an area that is to be inserted at
* the first %s
*/
if
(
!
(
newcopy
=
(
char
*
)
ECPGalloc
(
strlen
(
copiedquery
)
+
strlen
(
tobeinserted
)
+
1
,
stmt
->
lineno
)))
return
false
;
strcpy
(
newcopy
,
copiedquery
);
if
((
p
=
next_insert
(
newcopy
+
hostvarl
))
==
NULL
)
{
/*
* We have an argument but we dont have the matched up string
* in the string
*/
ECPGraise
(
stmt
->
lineno
,
ECPG_TOO_MANY_ARGUMENTS
,
NULL
);
return
false
;
}
else
{
strcpy
(
p
,
tobeinserted
);
hostvarl
=
strlen
(
newcopy
);
/*
* The strange thing in the second argument is the rest of the
* string from the old string
*/
strcat
(
newcopy
,
copiedquery
+
(
p
-
newcopy
)
+
sizeof
(
"?"
)
-
1
/* don't count the '\0' */
);
}
/*
* Now everything is safely copied to the newcopy. Lets free the
* oldcopy and let the copiedquery get the var->value from the
* newcopy.
*/
if
(
malloced
)
{
ECPGfree
((
char
*
)
tobeinserted
);
tobeinserted
=
NULL
;
}
ECPGfree
(
copiedquery
);
copiedquery
=
newcopy
;
var
=
var
->
next
;
}
/* Check if there are unmatched things left. */
if
(
next_insert
(
copiedquery
)
!=
NULL
)
{
ECPGraise
(
stmt
->
lineno
,
ECPG_TOO_FEW_ARGUMENTS
,
NULL
);
return
false
;
}
/* Now the request is built. */
if
(
stmt
->
connection
->
committed
&&
!
stmt
->
connection
->
autocommit
)
{
if
((
results
=
PQexec
(
stmt
->
connection
->
connection
,
"begin transaction"
))
==
NULL
)
{
ECPGraise
(
stmt
->
lineno
,
ECPG_TRANS
,
NULL
);
return
false
;
}
PQclear
(
results
);
stmt
->
connection
->
committed
=
false
;
}
ECPGlog
(
"ECPGexecute line %d: QUERY: %s on connection %s
\n
"
,
stmt
->
lineno
,
copiedquery
,
stmt
->
connection
->
name
);
results
=
PQexec
(
stmt
->
connection
->
connection
,
copiedquery
);
ECPGfree
(
copiedquery
);
if
(
results
==
NULL
)
{
errmsg
=
PQerrorMessage
(
stmt
->
connection
->
connection
);
ECPGlog
(
"ECPGexecute line %d: error: %s"
,
stmt
->
lineno
,
errmsg
);
ECPGraise
(
stmt
->
lineno
,
ECPG_PGSQL
,
errmsg
);
set_backend_err
(
errmsg
,
stmt
->
lineno
);
}
else
/*
* note: since some of the following code is duplicated in
* descriptor.c it should go into a separate function
*/
{
bool
clear_result
=
TRUE
;
errmsg
=
PQresultErrorMessage
(
results
);
set_backend_err
(
errmsg
,
stmt
->
lineno
);
var
=
stmt
->
outlist
;
switch
(
PQresultStatus
(
results
))
{
int
nfields
,
ntuples
,
act_field
;
case
PGRES_TUPLES_OK
:
nfields
=
PQnfields
(
results
);
sqlca
.
sqlerrd
[
2
]
=
ntuples
=
PQntuples
(
results
);
status
=
true
;
if
(
ntuples
<
1
)
{
if
(
ntuples
)
ECPGlog
(
"ECPGexecute line %d: Incorrect number of matches: %d
\n
"
,
stmt
->
lineno
,
ntuples
);
ECPGraise
(
stmt
->
lineno
,
ECPG_NOT_FOUND
,
NULL
);
status
=
false
;
break
;
}
if
(
var
!=
NULL
&&
var
->
type
==
ECPGt_descriptor
)
{
PGresult
**
resultpp
=
ECPGdescriptor_lvalue
(
stmt
->
lineno
,
(
const
char
*
)
var
->
pointer
);
if
(
resultpp
==
NULL
)
status
=
false
;
else
{
if
(
*
resultpp
)
PQclear
(
*
resultpp
);
*
resultpp
=
results
;
clear_result
=
FALSE
;
ECPGlog
(
"ECPGexecute putting result (%d tuples) into descriptor '%s'
\n
"
,
PQntuples
(
results
),
(
const
char
*
)
var
->
pointer
);
}
var
=
var
->
next
;
}
else
for
(
act_field
=
0
;
act_field
<
nfields
&&
status
;
act_field
++
)
{
if
(
var
==
NULL
)
{
ECPGraise
(
stmt
->
lineno
,
ECPG_TOO_FEW_ARGUMENTS
,
NULL
);
return
(
false
);
}
status
=
ECPGstore_result
(
results
,
act_field
,
stmt
,
var
);
var
=
var
->
next
;
}
if
(
status
&&
var
!=
NULL
)
{
ECPGraise
(
stmt
->
lineno
,
ECPG_TOO_MANY_ARGUMENTS
,
NULL
);
status
=
false
;
}
break
;
case
PGRES_EMPTY_QUERY
:
/* do nothing */
ECPGraise
(
stmt
->
lineno
,
ECPG_EMPTY
,
NULL
);
break
;
case
PGRES_COMMAND_OK
:
status
=
true
;
cmdstat
=
PQcmdStatus
(
results
);
sqlca
.
sqlerrd
[
1
]
=
PQoidValue
(
results
);
sqlca
.
sqlerrd
[
2
]
=
atol
(
PQcmdTuples
(
results
));
ECPGlog
(
"ECPGexecute line %d Ok: %s
\n
"
,
stmt
->
lineno
,
cmdstat
);
if
(
!
sqlca
.
sqlerrd
[
2
]
&&
(
!
strncmp
(
cmdstat
,
"UPDATE"
,
6
)
||
!
strncmp
(
cmdstat
,
"INSERT"
,
6
)
||
!
strncmp
(
cmdstat
,
"DELETE"
,
6
)))
ECPGraise
(
stmt
->
lineno
,
ECPG_NOT_FOUND
,
NULL
);
break
;
case
PGRES_NONFATAL_ERROR
:
case
PGRES_FATAL_ERROR
:
case
PGRES_BAD_RESPONSE
:
ECPGlog
(
"ECPGexecute line %d: Error: %s"
,
stmt
->
lineno
,
errmsg
);
ECPGraise
(
stmt
->
lineno
,
ECPG_PGSQL
,
errmsg
);
status
=
false
;
break
;
case
PGRES_COPY_OUT
:
ECPGlog
(
"ECPGexecute line %d: Got PGRES_COPY_OUT ... tossing.
\n
"
,
stmt
->
lineno
);
PQendcopy
(
stmt
->
connection
->
connection
);
break
;
case
PGRES_COPY_IN
:
ECPGlog
(
"ECPGexecute line %d: Got PGRES_COPY_IN ... tossing.
\n
"
,
stmt
->
lineno
);
PQendcopy
(
stmt
->
connection
->
connection
);
break
;
default:
ECPGlog
(
"ECPGexecute line %d: Got something else, postgres error.
\n
"
,
stmt
->
lineno
);
ECPGraise
(
stmt
->
lineno
,
ECPG_PGSQL
,
errmsg
);
status
=
false
;
break
;
}
if
(
clear_result
)
PQclear
(
results
);
}
/* check for asynchronous returns */
notify
=
PQnotifies
(
stmt
->
connection
->
connection
);
if
(
notify
)
{
ECPGlog
(
"ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received
\n
"
,
stmt
->
lineno
,
notify
->
relname
,
notify
->
be_pid
);
ECPGfree
(
notify
);
}
return
status
;
}
bool
ECPGdo
(
int
lineno
,
const
char
*
connection_name
,
char
*
query
,...)
{
va_list
args
;
struct
statement
*
stmt
;
struct
connection
*
con
=
ECPGget_connection
(
connection_name
);
bool
status
;
char
*
oldlocale
;
/* Make sure we do NOT honor the locale for numeric input/output */
/* since the database wants the standard decimal point */
oldlocale
=
strdup
(
setlocale
(
LC_NUMERIC
,
NULL
));
setlocale
(
LC_NUMERIC
,
"C"
);
if
(
!
ECPGinit
(
con
,
connection_name
,
lineno
))
{
setlocale
(
LC_NUMERIC
,
oldlocale
);
ECPGfree
(
oldlocale
);
return
(
false
);
}
/* construct statement in our own structure */
va_start
(
args
,
query
);
if
(
create_statement
(
lineno
,
con
,
&
stmt
,
query
,
args
)
==
false
)
{
setlocale
(
LC_NUMERIC
,
oldlocale
);
ECPGfree
(
oldlocale
);
return
(
false
);
}
va_end
(
args
);
/* are we connected? */
if
(
con
==
NULL
||
con
->
connection
==
NULL
)
{
free_statement
(
stmt
);
ECPGraise
(
lineno
,
ECPG_NOT_CONN
,
(
con
)
?
con
->
name
:
"<empty>"
);
setlocale
(
LC_NUMERIC
,
oldlocale
);
ECPGfree
(
oldlocale
);
return
false
;
}
/* initialize auto_mem struct */
ECPGclear_auto_mem
();
status
=
ECPGexecute
(
stmt
);
free_statement
(
stmt
);
/* and reset locale value so our application is not affected */
setlocale
(
LC_NUMERIC
,
oldlocale
);
ECPGfree
(
oldlocale
);
return
(
status
);
}
/* old descriptor interface */
bool
ECPGdo_descriptor
(
int
line
,
const
char
*
connection
,
const
char
*
descriptor
,
const
char
*
query
)
{
return
ECPGdo
(
line
,
connection
,
(
char
*
)
query
,
ECPGt_EOIT
,
ECPGt_descriptor
,
descriptor
,
0L
,
0L
,
0L
,
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EORT
);
}
src/interfaces/ecpg/lib/extern.h
deleted
100644 → 0
View file @
a4f25b6a
#ifndef _ECPG_LIB_EXTERN_H
#define _ECPG_LIB_EXTERN_H
#include "postgres_fe.h"
#include "libpq-fe.h"
/* Here are some methods used by the lib. */
/* Stores the backend error message for client access */
void
set_backend_err
(
const
char
*
err
,
int
lineon
);
/* Store and retrieve the backend error message for client access */
void
set_backend_err
(
const
char
*
err
,
int
lineon
);
char
*
ECPGerrmsg
(
void
);
/* Returns a pointer to a string containing a simple type name. */
void
ECPGadd_mem
(
void
*
ptr
,
int
lineno
);
bool
ECPGget_data
(
const
PGresult
*
,
int
,
int
,
int
,
enum
ECPGttype
type
,
enum
ECPGttype
,
char
*
,
char
*
,
long
,
long
,
long
,
bool
);
struct
connection
*
ECPGget_connection
(
const
char
*
);
void
ECPGinit_sqlca
(
void
);
char
*
ECPGalloc
(
long
,
int
);
void
ECPGfree
(
void
*
);
bool
ECPGinit
(
const
struct
connection
*
,
const
char
*
,
const
int
);
char
*
ECPGstrdup
(
const
char
*
,
int
);
const
char
*
ECPGtype_name
(
enum
ECPGttype
);
unsigned
int
ECPGDynamicType
(
Oid
);
void
ECPGfree_auto_mem
(
void
);
void
ECPGclear_auto_mem
(
void
);
/* A generic varchar type. */
struct
ECPGgeneric_varchar
{
int
len
;
char
arr
[
1
];
};
/*
* type information cache
*/
struct
ECPGtype_information_cache
{
struct
ECPGtype_information_cache
*
next
;
int
oid
;
bool
isarray
;
};
/* structure to store one statement */
struct
statement
{
int
lineno
;
char
*
command
;
struct
connection
*
connection
;
struct
variable
*
inlist
;
struct
variable
*
outlist
;
};
/* structure to store connections */
struct
connection
{
char
*
name
;
PGconn
*
connection
;
bool
committed
;
int
autocommit
;
struct
ECPGtype_information_cache
*
cache_head
;
struct
connection
*
next
;
};
/* structure to store descriptors */
struct
descriptor
{
char
*
name
;
PGresult
*
result
;
struct
descriptor
*
next
;
};
struct
variable
{
enum
ECPGttype
type
;
void
*
value
;
void
*
pointer
;
long
varcharsize
;
long
arrsize
;
long
offset
;
enum
ECPGttype
ind_type
;
void
*
ind_value
;
void
*
ind_pointer
;
long
ind_varcharsize
;
long
ind_arrsize
;
long
ind_offset
;
struct
variable
*
next
;
};
PGresult
**
ECPGdescriptor_lvalue
(
int
line
,
const
char
*
descriptor
);
bool
ECPGstore_result
(
const
PGresult
*
results
,
int
act_field
,
const
struct
statement
*
stmt
,
struct
variable
*
var
);
#endif
/* _ECPG_LIB_EXTERN_H */
src/interfaces/ecpg/lib/memory.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/memory.c,v 1.9 2002/09/04 20:31:46 momjian Exp $ */
#include "postgres_fe.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
void
ECPGfree
(
void
*
ptr
)
{
free
(
ptr
);
}
char
*
ECPGalloc
(
long
size
,
int
lineno
)
{
char
*
new
=
(
char
*
)
calloc
(
1L
,
size
);
if
(
!
new
)
{
ECPGraise
(
lineno
,
ECPG_OUT_OF_MEMORY
,
NULL
);
return
NULL
;
}
memset
(
new
,
'\0'
,
size
);
return
(
new
);
}
char
*
ECPGstrdup
(
const
char
*
string
,
int
lineno
)
{
char
*
new
=
strdup
(
string
);
if
(
!
new
)
{
ECPGraise
(
lineno
,
ECPG_OUT_OF_MEMORY
,
NULL
);
return
NULL
;
}
return
(
new
);
}
/* keep a list of memory we allocated for the user */
static
struct
auto_mem
{
void
*
pointer
;
struct
auto_mem
*
next
;
}
*
auto_allocs
=
NULL
;
void
ECPGadd_mem
(
void
*
ptr
,
int
lineno
)
{
struct
auto_mem
*
am
=
(
struct
auto_mem
*
)
ECPGalloc
(
sizeof
(
struct
auto_mem
),
lineno
);
am
->
pointer
=
ptr
;
am
->
next
=
auto_allocs
;
auto_allocs
=
am
;
}
void
ECPGfree_auto_mem
(
void
)
{
struct
auto_mem
*
am
;
/* free all memory we have allocated for the user */
for
(
am
=
auto_allocs
;
am
;)
{
struct
auto_mem
*
act
=
am
;
am
=
am
->
next
;
ECPGfree
(
act
->
pointer
);
ECPGfree
(
act
);
}
auto_allocs
=
NULL
;
}
void
ECPGclear_auto_mem
(
void
)
{
struct
auto_mem
*
am
;
/* free just our own structure */
for
(
am
=
auto_allocs
;
am
;)
{
struct
auto_mem
*
act
=
am
;
am
=
am
->
next
;
ECPGfree
(
act
);
}
auto_allocs
=
NULL
;
}
src/interfaces/ecpg/lib/misc.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/misc.c,v 1.13 2002/09/04 20:31:46 momjian Exp $ */
#include "postgres_fe.h"
#include <unistd.h>
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
static
struct
sqlca
sqlca_init
=
{
{
'S'
,
'Q'
,
'L'
,
'C'
,
'A'
,
' '
,
' '
,
' '
},
sizeof
(
struct
sqlca
),
0
,
{
0
,
{
0
}
},
{
'N'
,
'O'
,
'T'
,
' '
,
'S'
,
'E'
,
'T'
,
' '
},
{
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}
};
static
int
simple_debug
=
0
;
static
FILE
*
debugstream
=
NULL
;
void
ECPGinit_sqlca
(
void
)
{
memcpy
((
char
*
)
&
sqlca
,
(
char
*
)
&
sqlca_init
,
sizeof
(
sqlca
));
}
bool
ECPGinit
(
const
struct
connection
*
con
,
const
char
*
connection_name
,
const
int
lineno
)
{
ECPGinit_sqlca
();
if
(
con
==
NULL
)
{
ECPGraise
(
lineno
,
ECPG_NO_CONN
,
connection_name
?
connection_name
:
"NULL"
);
return
(
false
);
}
return
(
true
);
}
bool
ECPGstatus
(
int
lineno
,
const
char
*
connection_name
)
{
struct
connection
*
con
=
ECPGget_connection
(
connection_name
);
if
(
!
ECPGinit
(
con
,
connection_name
,
lineno
))
return
(
false
);
/* are we connected? */
if
(
con
->
connection
==
NULL
)
{
ECPGraise
(
lineno
,
ECPG_NOT_CONN
,
con
->
name
);
return
false
;
}
return
(
true
);
}
bool
ECPGtrans
(
int
lineno
,
const
char
*
connection_name
,
const
char
*
transaction
)
{
PGresult
*
res
;
struct
connection
*
con
=
ECPGget_connection
(
connection_name
);
if
(
!
ECPGinit
(
con
,
connection_name
,
lineno
))
return
(
false
);
ECPGlog
(
"ECPGtrans line %d action = %s connection = %s
\n
"
,
lineno
,
transaction
,
con
->
name
);
/* if we have no connection we just simulate the command */
if
(
con
&&
con
->
connection
)
{
/*
* if we are not in autocommit mode, already have committed the
* transaction and get another commit, just ignore it
*/
if
(
!
con
->
committed
||
con
->
autocommit
)
{
if
((
res
=
PQexec
(
con
->
connection
,
transaction
))
==
NULL
)
{
ECPGraise
(
lineno
,
ECPG_TRANS
,
NULL
);
return
FALSE
;
}
PQclear
(
res
);
}
}
if
(
strcmp
(
transaction
,
"commit"
)
==
0
||
strcmp
(
transaction
,
"rollback"
)
==
0
)
{
con
->
committed
=
true
;
/* deallocate all prepared statements */
if
(
!
ECPGdeallocate_all
(
lineno
))
return
false
;
}
return
true
;
}
void
ECPGdebug
(
int
n
,
FILE
*
dbgs
)
{
simple_debug
=
n
;
debugstream
=
dbgs
;
ECPGlog
(
"ECPGdebug: set to %d
\n
"
,
simple_debug
);
}
void
ECPGlog
(
const
char
*
format
,...)
{
va_list
ap
;
if
(
simple_debug
)
{
char
*
f
=
(
char
*
)
malloc
(
strlen
(
format
)
+
100
);
if
(
!
f
)
return
;
sprintf
(
f
,
"[%d]: %s"
,
(
int
)
getpid
(),
format
);
va_start
(
ap
,
format
);
vfprintf
(
debugstream
,
f
,
ap
);
va_end
(
ap
);
ECPGfree
(
f
);
}
}
src/interfaces/ecpg/lib/pg_type.h
deleted
100644 → 0
View file @
a4f25b6a
/*-------------------------------------------------------------------------
*
* pg_type.h
* definition of the system "type" relation (pg_type)
* along with the relation's initial contents.
*
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_type.h,v 1.7 2002/06/20 20:29:53 momjian Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
* information from the DATA() statements.
*
*-------------------------------------------------------------------------
*/
#ifndef PG_TYPE_H
#define PG_TYPE_H
/* ----------------
* initial contents of pg_type
* ----------------
*/
/* keep the following ordered by OID so that later changes can be made easier*/
/* OIDS 1 - 99 */
#define BOOLOID 16
#define BYTEAOID 17
#define CHAROID 18
#define NAMEOID 19
#define INT8OID 20
#define INT2OID 21
#define INT2VECTOROID 22
#define INT4OID 23
#define REGPROCOID 24
#define TEXTOID 25
#define OIDOID 26
#define TIDOID 27
#define XIDOID 28
#define CIDOID 29
#define OIDVECTOROID 30
#define POINTOID 600
#define LSEGOID 601
#define PATHOID 602
#define BOXOID 603
#define POLYGONOID 604
#define LINEOID 628
#define FLOAT4OID 700
#define FLOAT8OID 701
#define ABSTIMEOID 702
#define RELTIMEOID 703
#define TINTERVALOID 704
#define UNKNOWNOID 705
#define CIRCLEOID 718
#define CASHOID 790
#define INETOID 869
#define CIDROID 650
#define BPCHAROID 1042
#define VARCHAROID 1043
#define DATEOID 1082
#define TIMEOID 1083
#define TIMESTAMPOID 1114
#define TIMESTAMPTZOID 1184
#define INTERVALOID 1186
#define TIMETZOID 1266
#define ZPBITOID 1560
#define VARBITOID 1562
#define NUMERICOID 1700
#endif
/* PG_TYPE_H */
src/interfaces/ecpg/lib/prepare.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/prepare.c,v 1.12 2001/12/23 12:17:41 meskes Exp $ */
#include "postgres_fe.h"
#include <ctype.h>
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
static
struct
prepared_statement
{
char
*
name
;
struct
statement
*
stmt
;
struct
prepared_statement
*
next
;
}
*
prep_stmts
=
NULL
;
static
bool
isvarchar
(
unsigned
char
c
)
{
if
(
isalnum
(
c
))
return
true
;
if
(
c
==
'_'
||
c
==
'>'
||
c
==
'-'
||
c
==
'.'
)
return
true
;
if
(
c
>=
128
)
return
true
;
return
(
false
);
}
static
void
replace_variables
(
char
*
text
)
{
char
*
ptr
=
text
;
bool
string
=
false
;
for
(;
*
ptr
!=
'\0'
;
ptr
++
)
{
if
(
*
ptr
==
'\''
)
string
=
string
?
false
:
true
;
if
(
!
string
&&
*
ptr
==
':'
)
{
*
ptr
=
'?'
;
for
(
++
ptr
;
*
ptr
&&
isvarchar
(
*
ptr
);
ptr
++
)
*
ptr
=
' '
;
}
}
}
/* handle the EXEC SQL PREPARE statement */
bool
ECPGprepare
(
int
lineno
,
char
*
name
,
char
*
variable
)
{
struct
statement
*
stmt
;
struct
prepared_statement
*
this
;
/* check if we already have prepared this statement */
for
(
this
=
prep_stmts
;
this
!=
NULL
&&
strcmp
(
this
->
name
,
name
)
!=
0
;
this
=
this
->
next
);
if
(
this
)
{
bool
b
=
ECPGdeallocate
(
lineno
,
name
);
if
(
!
b
)
return
false
;
}
this
=
(
struct
prepared_statement
*
)
ECPGalloc
(
sizeof
(
struct
prepared_statement
),
lineno
);
if
(
!
this
)
return
false
;
stmt
=
(
struct
statement
*
)
ECPGalloc
(
sizeof
(
struct
statement
),
lineno
);
if
(
!
stmt
)
{
ECPGfree
(
this
);
return
false
;
}
/* create statement */
stmt
->
lineno
=
lineno
;
stmt
->
connection
=
NULL
;
stmt
->
command
=
ECPGstrdup
(
variable
,
lineno
);
stmt
->
inlist
=
stmt
->
outlist
=
NULL
;
/* if we have C variables in our statment replace them with '?' */
replace_variables
(
stmt
->
command
);
/* add prepared statement to our list */
this
->
name
=
ECPGstrdup
(
name
,
lineno
);
this
->
stmt
=
stmt
;
if
(
prep_stmts
==
NULL
)
this
->
next
=
NULL
;
else
this
->
next
=
prep_stmts
;
prep_stmts
=
this
;
return
true
;
}
/* handle the EXEC SQL DEALLOCATE PREPARE statement */
bool
ECPGdeallocate
(
int
lineno
,
char
*
name
)
{
struct
prepared_statement
*
this
,
*
prev
;
/* check if we really have prepared this statement */
for
(
this
=
prep_stmts
,
prev
=
NULL
;
this
!=
NULL
&&
strcmp
(
this
->
name
,
name
)
!=
0
;
prev
=
this
,
this
=
this
->
next
);
if
(
this
)
{
/* okay, free all the resources */
ECPGfree
(
this
->
name
);
ECPGfree
(
this
->
stmt
->
command
);
ECPGfree
(
this
->
stmt
);
if
(
prev
!=
NULL
)
prev
->
next
=
this
->
next
;
else
prep_stmts
=
this
->
next
;
ECPGfree
(
this
);
return
true
;
}
ECPGraise
(
lineno
,
ECPG_INVALID_STMT
,
name
);
return
false
;
}
bool
ECPGdeallocate_all
(
int
lineno
)
{
/* deallocate all prepared statements */
while
(
prep_stmts
!=
NULL
)
{
bool
b
=
ECPGdeallocate
(
lineno
,
prep_stmts
->
name
);
if
(
!
b
)
return
false
;
}
return
true
;
}
/* return the prepared statement */
char
*
ECPGprepared_statement
(
char
*
name
)
{
struct
prepared_statement
*
this
;
for
(
this
=
prep_stmts
;
this
!=
NULL
&&
strcmp
(
this
->
name
,
name
)
!=
0
;
this
=
this
->
next
);
return
(
this
)
?
this
->
stmt
->
command
:
NULL
;
}
src/interfaces/ecpg/lib/typename.c
deleted
100644 → 0
View file @
a4f25b6a
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/typename.c,v 1.21 2001/10/28 06:26:11 momjian Exp $ */
#include "postgres_fe.h"
#include <stdlib.h>
#include "ecpgtype.h"
#include "ecpglib.h"
#include "extern.h"
#include "sql3types.h"
#include "pg_type.h"
/*
* This function is used to generate the correct type names.
*/
const
char
*
ECPGtype_name
(
enum
ECPGttype
typ
)
{
switch
(
typ
)
{
case
ECPGt_char
:
return
"char"
;
case
ECPGt_unsigned_char
:
return
"unsigned char"
;
case
ECPGt_short
:
return
"short"
;
case
ECPGt_unsigned_short
:
return
"unsigned short"
;
case
ECPGt_int
:
return
"int"
;
case
ECPGt_unsigned_int
:
return
"unsigned int"
;
case
ECPGt_long
:
return
"long"
;
case
ECPGt_unsigned_long
:
return
"unsigned long"
;
case
ECPGt_long_long
:
return
"long long"
;
case
ECPGt_unsigned_long_long
:
return
"unsigned long long"
;
case
ECPGt_float
:
return
"float"
;
case
ECPGt_double
:
return
"double"
;
case
ECPGt_bool
:
return
"bool"
;
case
ECPGt_varchar
:
return
"varchar"
;
case
ECPGt_char_variable
:
return
"char"
;
default:
abort
();
}
return
NULL
;
}
unsigned
int
ECPGDynamicType
(
Oid
type
)
{
switch
(
type
)
{
case
BOOLOID
:
return
SQL3_BOOLEAN
;
/* bool */
case
INT2OID
:
return
SQL3_SMALLINT
;
/* int2 */
case
INT4OID
:
return
SQL3_INTEGER
;
/* int4 */
case
TEXTOID
:
return
SQL3_CHARACTER
;
/* text */
case
FLOAT4OID
:
return
SQL3_REAL
;
/* float4 */
case
FLOAT8OID
:
return
SQL3_DOUBLE_PRECISION
;
/* float8 */
case
BPCHAROID
:
return
SQL3_CHARACTER
;
/* bpchar */
case
VARCHAROID
:
return
SQL3_CHARACTER_VARYING
;
/* varchar */
case
DATEOID
:
return
SQL3_DATE_TIME_TIMESTAMP
;
/* date */
case
TIMEOID
:
return
SQL3_DATE_TIME_TIMESTAMP
;
/* time */
case
TIMESTAMPOID
:
return
SQL3_DATE_TIME_TIMESTAMP
;
/* datetime */
case
NUMERICOID
:
return
SQL3_NUMERIC
;
/* numeric */
default:
return
-
type
;
}
}
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