Skip to content

Commit 6d4a351

Browse files
author
Michael Meskes
committed
Applied patch by Boszormenyi Zoltan <zb@cybertec.at> to add sqlda support to
ecpg in both native and compatiblity mode.
1 parent af322a8 commit 6d4a351

32 files changed

+4024
-37
lines changed

src/interfaces/ecpg/ecpglib/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.65 2010/01/02 16:58:11 momjian Exp $
8+
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.66 2010/01/05 16:38:23 meskes Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -24,7 +24,7 @@ override CFLAGS += $(PTHREAD_CFLAGS)
2424
# Need to recompile any libpgport object files
2525
LIBS := $(filter-out -lpgport, $(LIBS))
2626

27-
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
27+
OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
2828
connect.o misc.o path.o pgstrcasecmp.o \
2929
$(filter snprintf.o strlcpy.o, $(LIBOBJS))
3030

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 223 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.87 2009/09/03 10:24:48 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.88 2010/01/05 16:38:23 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -25,6 +25,8 @@
2525
#include "ecpgerrno.h"
2626
#include "extern.h"
2727
#include "sqlca.h"
28+
#include "sqlda-native.h"
29+
#include "sqlda-compat.h"
2830
#include "sql3types.h"
2931
#include "pgtypes_numeric.h"
3032
#include "pgtypes_date.h"
@@ -1033,6 +1035,7 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
10331035
break;
10341036

10351037
case ECPGt_descriptor:
1038+
case ECPGt_sqlda:
10361039
break;
10371040

10381041
default:
@@ -1172,6 +1175,120 @@ ecpg_execute(struct statement * stmt)
11721175
if (desc->count == desc_counter)
11731176
desc_counter = 0;
11741177
}
1178+
else if (var->type == ECPGt_sqlda)
1179+
{
1180+
if (INFORMIX_MODE(stmt->compat))
1181+
{
1182+
struct sqlda_compat *sqlda = *(struct sqlda_compat **)var->pointer;
1183+
struct variable desc_inlist;
1184+
int i;
1185+
1186+
if (sqlda == NULL)
1187+
return false;
1188+
1189+
desc_counter++;
1190+
for (i = 0; i < sqlda->sqld; i++)
1191+
{
1192+
if (i + 1 == desc_counter)
1193+
{
1194+
desc_inlist.type = sqlda->sqlvar[i].sqltype;
1195+
desc_inlist.value = sqlda->sqlvar[i].sqldata;
1196+
desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
1197+
switch (desc_inlist.type)
1198+
{
1199+
case ECPGt_char:
1200+
case ECPGt_varchar:
1201+
desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
1202+
break;
1203+
default:
1204+
desc_inlist.varcharsize = 0;
1205+
break;
1206+
}
1207+
desc_inlist.arrsize = 1;
1208+
desc_inlist.offset = 0;
1209+
if (sqlda->sqlvar[i].sqlind)
1210+
{
1211+
desc_inlist.ind_type = ECPGt_short;
1212+
/* ECPG expects indicator value < 0 */
1213+
if (*(sqlda->sqlvar[i].sqlind))
1214+
*(sqlda->sqlvar[i].sqlind) = -1;
1215+
desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
1216+
desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
1217+
desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1218+
desc_inlist.ind_offset = 0;
1219+
}
1220+
else
1221+
{
1222+
desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1223+
desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1224+
desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1225+
}
1226+
if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1227+
return false;
1228+
1229+
break;
1230+
}
1231+
}
1232+
if (sqlda->sqld == desc_counter)
1233+
desc_counter = 0;
1234+
}
1235+
else
1236+
{
1237+
struct sqlda_struct *sqlda = *(struct sqlda_struct **)var->pointer;
1238+
struct variable desc_inlist;
1239+
int i;
1240+
1241+
if (sqlda == NULL)
1242+
return false;
1243+
1244+
desc_counter++;
1245+
for (i = 0; i < sqlda->sqln; i++)
1246+
{
1247+
if (i + 1 == desc_counter)
1248+
{
1249+
desc_inlist.type = sqlda->sqlvar[i].sqltype;
1250+
desc_inlist.value = sqlda->sqlvar[i].sqldata;
1251+
desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
1252+
switch (desc_inlist.type)
1253+
{
1254+
case ECPGt_char:
1255+
case ECPGt_varchar:
1256+
desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
1257+
break;
1258+
default:
1259+
desc_inlist.varcharsize = 0;
1260+
break;
1261+
}
1262+
desc_inlist.arrsize = 1;
1263+
desc_inlist.offset = 0;
1264+
if (sqlda->sqlvar[i].sqlind)
1265+
{
1266+
desc_inlist.ind_type = ECPGt_short;
1267+
/* ECPG expects indicator value < 0 */
1268+
if (*(sqlda->sqlvar[i].sqlind))
1269+
*(sqlda->sqlvar[i].sqlind) = -1;
1270+
desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
1271+
desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
1272+
desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1273+
desc_inlist.ind_offset = 0;
1274+
}
1275+
else
1276+
{
1277+
desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1278+
desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1279+
desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1280+
}
1281+
if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1282+
return false;
1283+
1284+
break;
1285+
}
1286+
}
1287+
if (sqlda->sqln == desc_counter)
1288+
desc_counter = 0;
1289+
}
1290+
1291+
}
11751292
else
11761293
{
11771294
if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))
@@ -1353,6 +1470,111 @@ ecpg_execute(struct statement * stmt)
13531470
}
13541471
var = var->next;
13551472
}
1473+
else if (var != NULL && var->type == ECPGt_sqlda)
1474+
{
1475+
if (INFORMIX_MODE(stmt->compat))
1476+
{
1477+
struct sqlda_compat **_sqlda = (struct sqlda_compat **)var->pointer;
1478+
struct sqlda_compat *sqlda = *_sqlda;
1479+
struct sqlda_compat *sqlda_new;
1480+
int i;
1481+
1482+
/* If we are passed in a previously existing sqlda (chain) then free it. */
1483+
while (sqlda)
1484+
{
1485+
sqlda_new = sqlda->desc_next;
1486+
free(sqlda);
1487+
sqlda = sqlda_new;
1488+
}
1489+
*_sqlda = sqlda = sqlda_new = NULL;
1490+
for (i = ntuples - 1; i >= 0; i--)
1491+
{
1492+
/* Build a new sqlda structure. Note that only fetching 1 record is supported */
1493+
sqlda_new = ecpg_build_compat_sqlda(stmt->lineno, results, i, stmt->compat);
1494+
1495+
if (!sqlda_new)
1496+
{
1497+
/* cleanup all SQLDAs we created up */
1498+
while (sqlda)
1499+
{
1500+
sqlda_new = sqlda->desc_next;
1501+
free(sqlda);
1502+
sqlda = sqlda_new;
1503+
}
1504+
*_sqlda = NULL;
1505+
1506+
ecpg_log("ecpg_execute on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1507+
status = false;
1508+
break;
1509+
}
1510+
else
1511+
{
1512+
ecpg_log("ecpg_execute on line %d: new sqlda was built\n", stmt->lineno);
1513+
1514+
*_sqlda = sqlda_new;
1515+
1516+
ecpg_set_compat_sqlda(stmt->lineno, _sqlda, results, i, stmt->compat);
1517+
ecpg_log("ecpg_execute on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1518+
stmt->lineno, PQnfields(results));
1519+
1520+
sqlda_new->desc_next = sqlda;
1521+
sqlda = sqlda_new;
1522+
}
1523+
}
1524+
}
1525+
else
1526+
{
1527+
struct sqlda_struct **_sqlda = (struct sqlda_struct **)var->pointer;
1528+
struct sqlda_struct *sqlda = *_sqlda;
1529+
struct sqlda_struct *sqlda_new;
1530+
int i;
1531+
1532+
/* If we are passed in a previously existing sqlda (chain) then free it. */
1533+
while (sqlda)
1534+
{
1535+
sqlda_new = sqlda->desc_next;
1536+
free(sqlda);
1537+
sqlda = sqlda_new;
1538+
}
1539+
*_sqlda = sqlda = sqlda_new = NULL;
1540+
for (i = ntuples - 1; i >= 0; i--)
1541+
{
1542+
/* Build a new sqlda structure. Note that only fetching 1 record is supported */
1543+
sqlda_new = ecpg_build_native_sqlda(stmt->lineno, results, i, stmt->compat);
1544+
1545+
if (!sqlda_new)
1546+
{
1547+
/* cleanup all SQLDAs we created up */
1548+
while (sqlda)
1549+
{
1550+
sqlda_new = sqlda->desc_next;
1551+
free(sqlda);
1552+
sqlda = sqlda_new;
1553+
}
1554+
*_sqlda = NULL;
1555+
1556+
ecpg_log("ecpg_execute on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1557+
status = false;
1558+
break;
1559+
}
1560+
else
1561+
{
1562+
ecpg_log("ecpg_execute on line %d: new sqlda was built\n", stmt->lineno);
1563+
1564+
*_sqlda = sqlda_new;
1565+
1566+
ecpg_set_native_sqlda(stmt->lineno, _sqlda, results, i, stmt->compat);
1567+
ecpg_log("ecpg_execute on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1568+
stmt->lineno, PQnfields(results));
1569+
1570+
sqlda_new->desc_next = sqlda;
1571+
sqlda = sqlda_new;
1572+
}
1573+
}
1574+
}
1575+
1576+
var = var->next;
1577+
}
13561578
else
13571579
for (act_field = 0; act_field < nfields && status; act_field++)
13581580
{

src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.35 2009/05/20 16:13:18 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.36 2010/01/05 16:38:23 meskes Exp $ */
22

33
#ifndef _ECPG_LIB_EXTERN_H
44
#define _ECPG_LIB_EXTERN_H
55

66
#include "postgres_fe.h"
77
#include "libpq-fe.h"
88
#include "sqlca.h"
9+
#include "sqlda-native.h"
10+
#include "sqlda-compat.h"
911
#include "ecpg_config.h"
1012
#ifndef CHAR_BIT
1113
#include <limits.h>
@@ -129,6 +131,7 @@ bool ecpg_init(const struct connection *, const char *, const int);
129131
char *ecpg_strdup(const char *, int);
130132
const char *ecpg_type_name(enum ECPGttype);
131133
int ecpg_dynamic_type(Oid);
134+
int sqlda_dynamic_type(Oid, enum COMPAT_MODE);
132135
void ecpg_free_auto_mem(void);
133136
void ecpg_clear_auto_mem(void);
134137

@@ -149,6 +152,11 @@ void ecpg_log(const char *format,...);
149152
bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
150153
void ecpg_init_sqlca(struct sqlca_t * sqlca);
151154

155+
struct sqlda_compat *ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE);
156+
void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE);
157+
struct sqlda_struct *ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE);
158+
void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE);
159+
152160
/* SQLSTATE values generated or processed by ecpglib (intentionally
153161
* not exported -- users should refer to the codes directly) */
154162

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy