Skip to content

Commit 635a0b9

Browse files
author
Michael Meskes
committed
- Finished major rewrite to use new protocol version
- Really prepare statements - Added more regression tests - Added auto-prepare mode - Use '$n' for positional variables, '?' is still possible via ecpg option - Cleaned up the sources a little bit
1 parent b83bd31 commit 635a0b9

File tree

123 files changed

+4140
-1514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+4140
-1514
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,5 +2215,15 @@ Tue, 12 Jun 2007 09:46:03 +0200
22152215
Wed, 25 Jul 2007 15:34:54 +0200
22162216

22172217
- Synced parser.
2218-
- Set ecpg library version to 5.3.
2219-
- Set ecpg version to 4.3.1.
2218+
2219+
Tue, 14 Aug 2007 11:46:51 +0200
2220+
2221+
- Finished major rewrite to use new protocol version.
2222+
- Really prepare statements.
2223+
- Added more regression tests.
2224+
- Added auto-prepare mode.
2225+
- Use '$n' for positional variables, '?' is still possible via ecpg
2226+
option.
2227+
- Cleaned up the sources a little bit.
2228+
- Set ecpg library version to 6.0.
2229+
- Set ecpg version to 4.4.

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.48 2006/10/04 00:30:11 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.49 2007/08/14 10:01:52 meskes Exp $ */
22

33
#include <stdlib.h>
44
#include <string.h>
@@ -202,10 +202,11 @@ deccvasc(char *cp, int len, decimal *np)
202202
}
203203
else
204204
{
205-
if (PGTYPESnumeric_to_decimal(result, np) != 0)
206-
ret = ECPG_INFORMIX_NUM_OVERFLOW;
205+
int i = PGTYPESnumeric_to_decimal(result, np);
207206

208207
free(result);
208+
if (i != 0)
209+
ret = ECPG_INFORMIX_NUM_OVERFLOW;
209210
}
210211
}
211212

src/interfaces/ecpg/ecpglib/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.46 2007/01/20 17:16:17 petere Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.47 2007/08/14 10:01:52 meskes Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -13,8 +13,8 @@ top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

1515
NAME= ecpg
16-
SO_MAJOR_VERSION= 5
17-
SO_MINOR_VERSION= 3
16+
SO_MAJOR_VERSION= 6
17+
SO_MINOR_VERSION= 0
1818
DLTYPE= library
1919

2020
override CPPFLAGS := -DFRONTEND \

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.41 2007/03/29 12:02:24 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.42 2007/08/14 10:01:52 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -185,11 +185,9 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
185185
{
186186
if (con->committed)
187187
{
188-
if ((results = PQexec(con->connection, "begin transaction")) == NULL)
189-
{
190-
ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
188+
results = PQexec(con->connection, "begin transaction");
189+
if (!ECPGcheck_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
191190
return false;
192-
}
193191
PQclear(results);
194192
con->committed = false;
195193
}
@@ -199,11 +197,9 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
199197
{
200198
if (!con->committed)
201199
{
202-
if ((results = PQexec(con->connection, "commit")) == NULL)
203-
{
204-
ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
200+
results = PQexec(con->connection, "commit");
201+
if (!ECPGcheck_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
205202
return false;
206-
}
207203
PQclear(results);
208204
con->committed = true;
209205
}
@@ -249,7 +245,7 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
249245
if (strncmp(sqlstate, "00", 2) == 0)
250246
return;
251247

252-
ECPGlog("%s", message);
248+
ECPGlog("ECPGnoticeReceiver %s\n", message);
253249

254250
/* map to SQLCODE for backward compatibility */
255251
if (strcmp(sqlstate, ECPG_SQLSTATE_INVALID_CURSOR_NAME) == 0)

src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* dynamic SQL support routines
22
*
3-
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.22 2007/06/11 11:52:08 meskes Exp $
3+
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.23 2007/08/14 10:01:52 meskes Exp $
44
*/
55

66
#define POSTGRES_ECPG_INTERNAL
@@ -495,6 +495,8 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
495495
if (!desc_item)
496496
return false;
497497
desc_item->num = index;
498+
if (desc->count < index)
499+
desc->count = index;
498500
desc_item->next = desc->items;
499501
desc->items = desc_item;
500502
}
@@ -508,7 +510,6 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
508510
{
509511
enum ECPGdtype itemtype;
510512
const char *tobeinserted = NULL;
511-
bool malloced;
512513

513514
itemtype = va_arg(args, enum ECPGdtype);
514515

@@ -542,11 +543,12 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
542543
{
543544
case ECPGd_data:
544545
{
545-
if (!ECPGstore_input(lineno, true, var, &tobeinserted, &malloced, false))
546+
if (!ECPGstore_input(lineno, true, var, &tobeinserted, false))
546547
{
547548
ECPGfree(var);
548549
return false;
549550
}
551+
550552
ECPGfree(desc_item->data); /* free() takes care of a potential NULL value */
551553
desc_item->data = (char *) tobeinserted;
552554
tobeinserted = NULL;
@@ -583,13 +585,7 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
583585
return false;
584586
}
585587
}
586-
587-
/*
588-
* if (itemtype == ECPGd_data) { free(desc_item->data);
589-
* desc_item->data = NULL; }
590-
*/
591-
}
592-
while (true);
588+
} while (true);
593589
ECPGfree(var);
594590

595591
return true;
@@ -598,18 +594,18 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
598594
bool
599595
ECPGdeallocate_desc(int line, const char *name)
600596
{
601-
struct descriptor *i;
597+
struct descriptor *desc;
602598
struct descriptor **lastptr = &all_descriptors;
603599
struct sqlca_t *sqlca = ECPGget_sqlca();
604600

605601
ECPGinit_sqlca(sqlca);
606-
for (i = all_descriptors; i; lastptr = &i->next, i = i->next)
602+
for (desc = all_descriptors; desc; lastptr = &desc->next, desc = desc->next)
607603
{
608-
if (!strcmp(name, i->name))
604+
if (!strcmp(name, desc->name))
609605
{
610606
struct descriptor_item *desc_item;
611607

612-
for (desc_item = i->items; desc_item;)
608+
for (desc_item = desc->items; desc_item;)
613609
{
614610
struct descriptor_item *di;
615611

@@ -619,10 +615,10 @@ ECPGdeallocate_desc(int line, const char *name)
619615
ECPGfree(di);
620616
}
621617

622-
*lastptr = i->next;
623-
ECPGfree(i->name);
624-
PQclear(i->result);
625-
ECPGfree(i);
618+
*lastptr = desc->next;
619+
ECPGfree(desc->name);
620+
PQclear(desc->result);
621+
ECPGfree(desc);
626622
return true;
627623
}
628624
}

src/interfaces/ecpg/ecpglib/error.c

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.16 2007/05/31 15:13:05 petere Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.17 2007/08/14 10:01:52 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -9,7 +9,6 @@
99
#include "extern.h"
1010
#include "sqlca.h"
1111

12-
1312
void
1413
ECPGraise(int line, int code, const char *sqlstate, const char *str)
1514
{
@@ -196,6 +195,59 @@ ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat)
196195
ECPGfree_auto_mem();
197196
}
198197

198+
/* filter out all error codes */
199+
bool
200+
ECPGcheck_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
201+
{
202+
if (results == NULL)
203+
{
204+
ECPGlog("ECPGcheck_PQresult line %d: error: %s", lineno, PQerrorMessage(connection));
205+
ECPGraise_backend(lineno, NULL, connection, compat);
206+
return (false);
207+
}
208+
209+
switch (PQresultStatus(results))
210+
{
211+
212+
case PGRES_TUPLES_OK:
213+
return (true);
214+
break;
215+
case PGRES_EMPTY_QUERY:
216+
/* do nothing */
217+
ECPGraise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
218+
PQclear(results);
219+
return (false);
220+
break;
221+
case PGRES_COMMAND_OK:
222+
return (true);
223+
break;
224+
case PGRES_NONFATAL_ERROR:
225+
case PGRES_FATAL_ERROR:
226+
case PGRES_BAD_RESPONSE:
227+
ECPGlog("ECPGcheck_PQresult line %d: Error: %s", lineno, PQresultErrorMessage(results));
228+
ECPGraise_backend(lineno, results, connection, compat);
229+
PQclear(results);
230+
return (false);
231+
break;
232+
case PGRES_COPY_OUT:
233+
return(true);
234+
break;
235+
case PGRES_COPY_IN:
236+
ECPGlog("ECPGcheck_PQresult line %d: Got PGRES_COPY_IN ... tossing.\n", lineno);
237+
PQendcopy(connection);
238+
PQclear(results);
239+
return(false);
240+
break;
241+
default:
242+
ECPGlog("ECPGcheck_PQresult line %d: Got something else, postgres error.\n",
243+
lineno);
244+
ECPGraise_backend(lineno, results, connection, compat);
245+
PQclear(results);
246+
return(false);
247+
break;
248+
}
249+
}
250+
199251
/* print out an error message */
200252
void
201253
sqlprint(void)

0 commit comments

Comments
 (0)