Skip to content

Commit 5a19781

Browse files
author
Michael Meskes
committed
*** empty log message ***
1 parent ad3db67 commit 5a19781

File tree

19 files changed

+450
-419
lines changed

19 files changed

+450
-419
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,5 +852,10 @@ Thu Mar 2 17:42:16 CET 2000
852852
Fri Mar 3 10:47:06 CET 2000
853853

854854
- Fixed handling of double quote in C code.
855+
856+
Tue Mar 7 10:58:21 CET 2000
857+
858+
- More cleanup in ecpglib.
859+
- Fixed ecpg.c not not free variable list twice.
855860
- Set library version to 3.1.0.
856861
- Set ecpg version to 2.7.0.

src/interfaces/ecpg/include/ecpglib.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ extern "C"
2424
/* print an error message */
2525
void sqlprint(void);
2626

27-
#ifdef LIBPQ_FE_H
28-
bool ECPGsetdb(PGconn *);
29-
#endif
30-
31-
/* Here are some methods used by the lib. */
32-
/* Returns a pointer to a string containing a simple type name. */
33-
bool get_data(PGresult *, int, int, int, enum ECPGttype type,
34-
enum ECPGttype, void *, void *, long, long, bool);
35-
char *ecpg_alloc(long, int);
36-
char *ecpg_strdup(const char *, int);
37-
const char *ECPGtype_name(enum ECPGttype);
38-
unsigned int ECPGDynamicType(Oid);
39-
40-
/* and some vars */
41-
extern struct auto_mem *auto_allocs;
42-
4327
/* define this for simplicity as well as compatibility */
4428

4529
#define SQLCODE sqlca.sqlcode
@@ -59,5 +43,3 @@ extern "C"
5943
}
6044

6145
#endif
62-
63-
#include <ecpgerrno.h>

src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,6 @@ extern "C"
7373

7474
#define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_varchar2)
7575

76-
/* A generic varchar type. */
77-
struct ECPGgeneric_varchar
78-
{
79-
int len;
80-
char arr[1];
81-
};
82-
83-
/* keep a list of memory we allocated for the user */
84-
struct auto_mem
85-
{
86-
void *pointer;
87-
struct auto_mem *next;
88-
};
89-
90-
/* structure to store one statement */
91-
struct statement
92-
{
93-
int lineno;
94-
char *command;
95-
struct connection *connection;
96-
struct variable *inlist;
97-
struct variable *outlist;
98-
};
99-
100-
101-
/* define this for simplicity as well as compatibility */
102-
10376
#ifdef __cplusplus
10477
}
10578

src/interfaces/ecpg/lib/Makefile.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Copyright (c) 1994, Regents of the University of California
77
#
88
# IDENTIFICATION
9-
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.61 2000/02/25 11:11:15 meskes Exp $
9+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.62 2000/03/07 15:10:52 meskes Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

@@ -23,7 +23,8 @@ ifdef KRBVERS
2323
CFLAGS+= $(KRBFLAGS)
2424
endif
2525

26-
OBJS= ecpglib.o typename.o descriptor.o data.o error.o prepare.o memory.o
26+
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
27+
connect.o misc.o
2728

2829
SHLIB_LINK= -L../../libpq -lpq
2930

src/interfaces/ecpg/lib/connect.c

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#include <ecpgtype.h>
2+
#include <ecpglib.h>
3+
#include <ecpgerrno.h>
4+
#include "extern.h"
5+
#include <sqlca.h>
6+
7+
static struct connection *all_connections = NULL, *actual_connection = NULL;
8+
9+
struct connection *
10+
get_connection(const char *connection_name)
11+
{
12+
struct connection *con = all_connections;
13+
14+
if (connection_name == NULL || strcmp(connection_name, "CURRENT") == 0)
15+
return actual_connection;
16+
17+
for (; con && strcmp(connection_name, con->name) != 0; con = con->next);
18+
if (con)
19+
return con;
20+
else
21+
return NULL;
22+
}
23+
24+
static void
25+
ecpg_finish(struct connection * act)
26+
{
27+
if (act != NULL)
28+
{
29+
ECPGlog("ecpg_finish: finishing %s.\n", act->name);
30+
PQfinish(act->connection);
31+
32+
/* remove act from the list */
33+
if (act == all_connections)
34+
all_connections = act->next;
35+
else
36+
{
37+
struct connection *con;
38+
39+
for (con = all_connections; con->next && con->next != act; con = con->next);
40+
if (con->next)
41+
con->next = act->next;
42+
}
43+
44+
if (actual_connection == act)
45+
actual_connection = all_connections;
46+
47+
free(act->name);
48+
free(act);
49+
}
50+
else
51+
ECPGlog("ecpg_finish: called an extra time.\n");
52+
}
53+
54+
bool
55+
ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
56+
{
57+
struct connection *con = get_connection(connection_name);
58+
PGresult *results;
59+
60+
if (!ecpg_init(con, connection_name, lineno))
61+
return(false);
62+
63+
ECPGlog("ECPGsetcommit line %d action = %s connection = %s\n", lineno, mode, con->name);
64+
65+
if (con->autocommit == true && strncmp(mode, "off", strlen("off")) == 0)
66+
{
67+
if (con->committed)
68+
{
69+
if ((results = PQexec(con->connection, "begin transaction")) == NULL)
70+
{
71+
ECPGraise(lineno, ECPG_TRANS, NULL);
72+
return false;
73+
}
74+
PQclear(results);
75+
con->committed = false;
76+
}
77+
con->autocommit = false;
78+
}
79+
else if (con->autocommit == false && strncmp(mode, "on", strlen("on")) == 0)
80+
{
81+
if (!con->committed)
82+
{
83+
if ((results = PQexec(con->connection, "commit")) == NULL)
84+
{
85+
ECPGraise(lineno, ECPG_TRANS, NULL);
86+
return false;
87+
}
88+
PQclear(results);
89+
con->committed = true;
90+
}
91+
con->autocommit = true;
92+
}
93+
94+
return true;
95+
}
96+
97+
bool
98+
ECPGsetconn(int lineno, const char *connection_name)
99+
{
100+
struct connection *con = get_connection(connection_name);
101+
102+
if (!ecpg_init(con, connection_name, lineno))
103+
return(false);
104+
105+
actual_connection = con;
106+
return true;
107+
}
108+
109+
bool
110+
ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd, const char *connection_name, int autocommit)
111+
{
112+
struct connection *this;
113+
114+
init_sqlca();
115+
116+
if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL)
117+
return false;
118+
119+
if (dbname == NULL && connection_name == NULL)
120+
connection_name = "DEFAULT";
121+
122+
/* add connection to our list */
123+
if (connection_name != NULL)
124+
this->name = ecpg_strdup(connection_name, lineno);
125+
else
126+
this->name = ecpg_strdup(dbname, lineno);
127+
128+
if (all_connections == NULL)
129+
this->next = NULL;
130+
else
131+
this->next = all_connections;
132+
133+
actual_connection = all_connections = this;
134+
135+
ECPGlog("ECPGconnect: opening database %s %s%s\n", dbname ? dbname : "<DEFAULT>", user ? "for user " : "", user ? user : "");
136+
137+
this->connection = PQsetdbLogin(NULL, NULL, NULL, NULL, dbname, user, passwd);
138+
139+
if (PQstatus(this->connection) == CONNECTION_BAD)
140+
{
141+
ecpg_finish(this);
142+
ECPGlog("connect: could not open database %s %s%s in line %d\n", dbname ? dbname : "<DEFAULT>", user ? "for user " : "", user ? user : "", lineno);
143+
ECPGraise(lineno, ECPG_CONNECT, dbname ? dbname : "<DEFAULT>");
144+
return false;
145+
}
146+
147+
this->committed = true;
148+
this->autocommit = autocommit;
149+
150+
return true;
151+
}
152+
153+
bool
154+
ECPGdisconnect(int lineno, const char *connection_name)
155+
{
156+
struct connection *con;
157+
158+
if (strcmp(connection_name, "ALL") == 0)
159+
{
160+
init_sqlca();
161+
for (con = all_connections; con;)
162+
{
163+
struct connection *f = con;
164+
165+
con = con->next;
166+
ecpg_finish(f);
167+
}
168+
}
169+
else
170+
{
171+
con = get_connection(connection_name);
172+
173+
if (!ecpg_init(con, connection_name, lineno))
174+
return(false);
175+
else
176+
ecpg_finish(con);
177+
}
178+
179+
return true;
180+
}

src/interfaces/ecpg/lib/data.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include <stdlib.h>
22

3-
#include <libpq/pqcomm.h>
43
#include <ecpgtype.h>
54
#include <ecpglib.h>
5+
#include <ecpgerrno.h>
6+
#include "extern.h"
67
#include <sqlca.h>
78

89
bool

src/interfaces/ecpg/lib/descriptor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <ecpgtype.h>
22
#include <ecpglib.h>
3-
3+
#include <ecpgerrno.h>
4+
#include "extern.h"
45
#include <sql3types.h>
56

67
struct descriptor

src/interfaces/ecpg/lib/error.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#include <ecpgerrno.h>
44
#include <ecpgtype.h>
55
#include <ecpglib.h>
6+
#include "extern.h"
67
#include <sqlca.h>
78

89
void
910
ECPGraise(int line, int code, const char *str)
1011
{
11-
struct auto_mem *am;
12-
1312
sqlca.sqlcode = code;
1413
switch (code)
1514
{
@@ -142,14 +141,7 @@ ECPGraise(int line, int code, const char *str)
142141
sqlca.sqlerrm.sqlerrml = strlen(sqlca.sqlerrm.sqlerrmc);
143142

144143
/* free all memory we have allocated for the user */
145-
for (am = auto_allocs; am;)
146-
{
147-
struct auto_mem *act = am;
148-
149-
am = am->next;
150-
free(act->pointer);
151-
free(act);
152-
}
144+
free_auto_mem();
153145
}
154146

155147
/* print out an error message */

0 commit comments

Comments
 (0)