Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d34af4

Browse files
author
Michael Meskes
committed
Added STRING datatype for Informix compatibility mode. This work is
based on a patch send in by Böszörményi Zoltán <[email protected]>.
1 parent 06f1f53 commit 5d34af4

File tree

17 files changed

+206
-144
lines changed

17 files changed

+206
-144
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,12 @@ Mon, 02 Feb 2009 16:34:53 +0100
24122412
- Fixed auto allocation for binary data types.
24132413
- Set pgtypes library version to 3.1.
24142414
- Set compat library version to 3.1.
2415-
- Set ecpg library version to 6.2.
2415+
- Set ecpg library version to 6.1.
24162416
- Set ecpg version to 4.5.
24172417

2418+
Fri, 07 Aug 2009 10:41:28 +0200
2419+
2420+
- Added STRING datatype for Informix compatibility mode. This work is
2421+
based on a patch send in by Böszörményi Zoltán <[email protected]>.
2422+
- Set ecpg library version to 6.2.
2423+
- Set ecpg version to 4.6.

src/interfaces/ecpg/compatlib/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.43 2009/07/13 01:37:05 momjian Exp $
8+
# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.44 2009/08/07 10:51:20 meskes Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
1515

1616
NAME= ecpg_compat
1717
SO_MAJOR_VERSION= 3
18-
SO_MINOR_VERSION= 2
18+
SO_MINOR_VERSION= 1
1919

2020
override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
2121
-I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS)

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.42 2009/01/15 11:52:55 petere Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.43 2009/08/07 10:51:20 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -138,6 +138,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
138138
case ECPGt_char:
139139
case ECPGt_unsigned_char:
140140
case ECPGt_varchar:
141+
case ECPGt_string:
141142
break;
142143

143144
default:
@@ -389,13 +390,29 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
389390

390391
case ECPGt_char:
391392
case ECPGt_unsigned_char:
393+
case ECPGt_string:
392394
if (pval)
393395
{
396+
char *str = (char *) ((long) var + offset * act_tuple);
394397
if (varcharsize == 0 || varcharsize > size)
395-
strncpy((char *) ((long) var + offset * act_tuple), pval, size + 1);
398+
{
399+
char *last;
400+
401+
strncpy(str, pval, size + 1);
402+
/* do the rtrim() */
403+
if (type == ECPGt_string)
404+
{
405+
char *last = str + size;
406+
while (last > str && (*last == ' ' || *last == '\0'))
407+
{
408+
*last = '\0';
409+
last--;
410+
}
411+
}
412+
}
396413
else
397414
{
398-
strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);
415+
strncpy(str, pval, varcharsize);
399416

400417
if (varcharsize < size)
401418
{

src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 2 additions & 1 deletion
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.32 2009/06/11 14:49:13 momjian Exp $
3+
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.33 2009/08/07 10:51:20 meskes Exp $
44
*/
55

66
#define POSTGRES_ECPG_INTERNAL
@@ -200,6 +200,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
200200
{
201201
case ECPGt_char:
202202
case ECPGt_unsigned_char:
203+
case ECPGt_string:
203204
strncpy((char *) var, value, varcharsize);
204205
break;
205206
case ECPGt_varchar:

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.85 2009/06/11 14:49:13 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.86 2009/08/07 10:51:20 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -359,6 +359,7 @@ ecpg_store_result(const PGresult *results, int act_field,
359359
{
360360
case ECPGt_char:
361361
case ECPGt_unsigned_char:
362+
case ECPGt_string:
362363
if (!var->varcharsize && !var->arrsize)
363364
{
364365
/* special mode for handling char**foo=0 */
@@ -418,7 +419,7 @@ ecpg_store_result(const PGresult *results, int act_field,
418419

419420
/* fill the variable with the tuple(s) */
420421
if (!var->varcharsize && !var->arrsize &&
421-
(var->type == ECPGt_char || var->type == ECPGt_unsigned_char))
422+
(var->type == ECPGt_char || var->type == ECPGt_unsigned_char || var->type == ECPGt_string))
422423
{
423424
/* special mode for handling char**foo=0 */
424425

@@ -757,6 +758,7 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
757758

758759
case ECPGt_char:
759760
case ECPGt_unsigned_char:
761+
case ECPGt_string:
760762
{
761763
/* set slen to string length if type is char * */
762764
int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : (unsigned int) var->varcharsize;

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.49 2009/06/11 14:49:13 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.50 2009/08/07 10:51:20 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -295,6 +295,7 @@ ECPGset_noind_null(enum ECPGttype type, void *ptr)
295295
{
296296
case ECPGt_char:
297297
case ECPGt_unsigned_char:
298+
case ECPGt_string:
298299
*((char *) ptr) = '\0';
299300
break;
300301
case ECPGt_short:
@@ -361,6 +362,7 @@ ECPGis_noind_null(enum ECPGttype type, void *ptr)
361362
{
362363
case ECPGt_char:
363364
case ECPGt_unsigned_char:
365+
case ECPGt_string:
364366
if (*((char *) ptr) == '\0')
365367
return true;
366368
break;

src/interfaces/ecpg/ecpglib/typename.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.14 2007/11/15 21:14:45 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.15 2009/08/07 10:51:20 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -19,6 +19,7 @@ ecpg_type_name(enum ECPGttype typ)
1919
switch (typ)
2020
{
2121
case ECPGt_char:
22+
case ECPGt_string:
2223
return "char";
2324
case ECPGt_unsigned_char:
2425
return "unsigned char";

src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* All types that can be handled for host variable declarations has to
66
* be handled eventually.
77
*
8-
* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpgtype.h,v 1.37 2007/08/14 10:01:52 meskes Exp $
8+
* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpgtype.h,v 1.38 2009/08/07 10:51:20 meskes Exp $
99
*/
1010

1111
/*
@@ -61,7 +61,8 @@ enum ECPGttype
6161
ECPGt_const, /* a constant is needed sometimes */
6262
ECPGt_EOIT, /* End of insert types. */
6363
ECPGt_EORT, /* End of result types. */
64-
ECPGt_NO_INDICATOR /* no indicator */
64+
ECPGt_NO_INDICATOR, /* no indicator */
65+
ECPGt_string /* trimmed (char *) type */
6566
};
6667

6768
/* descriptor items */
@@ -86,7 +87,7 @@ enum ECPGdtype
8687
ECPGd_cardinality
8788
};
8889

89-
#define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_interval)
90+
#define IS_SIMPLE_TYPE(type) (((type) >= ECPGt_char && (type) <= ECPGt_interval) || ((type) == ECPGt_string))
9091

9192
/* we also have to handle different statement types */
9293
enum ECPG_statement_type

src/interfaces/ecpg/pgtypeslib/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.44 2009/07/13 01:37:05 momjian Exp $
8+
# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.45 2009/08/07 10:51:20 meskes Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
1515

1616
NAME= pgtypes
1717
SO_MAJOR_VERSION= 3
18-
SO_MINOR_VERSION= 2
18+
SO_MINOR_VERSION= 1
1919

2020
override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
2121
-I$(top_srcdir)/src/include/utils -I$(libpq_srcdir) $(CPPFLAGS)

src/interfaces/ecpg/preproc/ecpg.header

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.7 2009/06/10 23:11:52 petere Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.8 2009/08/07 10:51:20 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -256,12 +256,12 @@ adjust_informix(struct arguments *list)
256256
original_var = ptr->variable->name;
257257
sprintf(temp, "%d))", ecpg_informix_var);
258258

259-
if ((ptr->variable->type->type != ECPGt_varchar && ptr->variable->type->type != ECPGt_char && ptr->variable->type->type != ECPGt_unsigned_char) && atoi(ptr->variable->type->size) > 1)
259+
if ((ptr->variable->type->type != ECPGt_varchar && ptr->variable->type->type != ECPGt_char && ptr->variable->type->type != ECPGt_unsigned_char && ptr->variable->type->type != ECPGt_string) && atoi(ptr->variable->type->size) > 1)
260260
{
261261
ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable->type->u.element->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable->type->u.element->type, make_str("1"), ptr->variable->type->u.element->lineno), ptr->variable->type->size), 0);
262262
sprintf(temp, "%d, (", ecpg_informix_var++);
263263
}
264-
else if ((ptr->variable->type->type == ECPGt_varchar || ptr->variable->type->type == ECPGt_char || ptr->variable->type->type == ECPGt_unsigned_char) && atoi(ptr->variable->type->size) > 1)
264+
else if ((ptr->variable->type->type == ECPGt_varchar || ptr->variable->type->type == ECPGt_char || ptr->variable->type->type == ECPGt_unsigned_char || ptr->variable->type->type == ECPGt_string) && atoi(ptr->variable->type->size) > 1)
265265
{
266266
ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size, ptr->variable->type->lineno), 0);
267267
sprintf(temp, "%d, (", ecpg_informix_var++);
@@ -343,6 +343,8 @@ add_typedef(char *name, char * dimension, char * length, enum ECPGttype type_enu
343343
type_enum == ECPGt_union) &&
344344
initializer == 1)
345345
mmerror(PARSE_ERROR, ET_ERROR, "initializer not allowed in type definition");
346+
else if (INFORMIX_MODE && strcmp(name, "string") == 0)
347+
mmerror(PARSE_ERROR, ET_ERROR, "type name \"string\" is reserved in Informix mode");
346348
else
347349
{
348350
for (ptr = types; ptr != NULL; ptr = ptr->next)
@@ -371,6 +373,7 @@ add_typedef(char *name, char * dimension, char * length, enum ECPGttype type_enu
371373
if (type_enum != ECPGt_varchar &&
372374
type_enum != ECPGt_char &&
373375
type_enum != ECPGt_unsigned_char &&
376+
type_enum != ECPGt_string &&
374377
atoi(this->type->type_index) >= 0)
375378
mmerror(PARSE_ERROR, ET_ERROR, "multidimensional arrays for simple data types are not supported");
376379

0 commit comments

Comments
 (0)