Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5d34af4

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 <zb@cybertec.at>.
1 parent06f1f53 commit5d34af4

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 <zb@cybertec.at>.
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
overrideCPPFLAGS := -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
#definePOSTGRES_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
caseECPGt_char:
139139
caseECPGt_unsigned_char:
140140
caseECPGt_varchar:
141+
caseECPGt_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
caseECPGt_char:
391392
caseECPGt_unsigned_char:
393+
caseECPGt_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
#definePOSTGRES_ECPG_INTERNAL
@@ -200,6 +200,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
200200
{
201201
caseECPGt_char:
202202
caseECPGt_unsigned_char:
203+
caseECPGt_string:
203204
strncpy((char*)var,value,varcharsize);
204205
break;
205206
caseECPGt_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
caseECPGt_char:
361361
caseECPGt_unsigned_char:
362+
caseECPGt_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
caseECPGt_char:
759760
caseECPGt_unsigned_char:
761+
caseECPGt_string:
760762
{
761763
/* set slen to string length if type is char * */
762764
intslen= (var->varcharsize==0) ?strlen((char*)var->value) : (unsignedint)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
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -295,6 +295,7 @@ ECPGset_noind_null(enum ECPGttype type, void *ptr)
295295
{
296296
caseECPGt_char:
297297
caseECPGt_unsigned_char:
298+
caseECPGt_string:
298299
*((char*)ptr)='\0';
299300
break;
300301
caseECPGt_short:
@@ -361,6 +362,7 @@ ECPGis_noind_null(enum ECPGttype type, void *ptr)
361362
{
362363
caseECPGt_char:
363364
caseECPGt_unsigned_char:
365+
caseECPGt_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
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -19,6 +19,7 @@ ecpg_type_name(enum ECPGttype typ)
1919
switch (typ)
2020
{
2121
caseECPGt_char:
22+
caseECPGt_string:
2223
return"char";
2324
caseECPGt_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-
#defineIS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_interval)
90+
#defineIS_SIMPLE_TYPE(type) (((type) >= ECPGt_char && (type) <= ECPGt_interval) || ((type) == ECPGt_string))
9091

9192
/* we also have to handle different statement types */
9293
enumECPG_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
overrideCPPFLAGS := -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

‎src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.9 2009/06/10 23:11:52 petere Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.10 2009/08/07 10:51:20 meskes Exp $ */
22

33
statements: /*EMPTY*/
44
| statements statement
@@ -213,6 +213,7 @@ char_variable: cvariable
213213
{
214214
case ECPGt_char:
215215
case ECPGt_unsigned_char:
216+
case ECPGt_string:
216217
$$ = $1;
217218
break;
218219
case ECPGt_varchar:
@@ -587,6 +588,14 @@ var_type:simple_type
587588
$$.type_index = make_str("-1");
588589
$$.type_sizeof = NULL;
589590
}
591+
else if ((strcmp($1, "string") == 0) && INFORMIX_MODE)
592+
{
593+
$$.type_enum = ECPGt_string;
594+
$$.type_str = make_str("char");
595+
$$.type_dimension = make_str("-1");
596+
$$.type_index = make_str("-1");
597+
$$.type_sizeof = NULL;
598+
}
590599
else
591600
{
592601
/* this is for typedef'ed types */
@@ -849,6 +858,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
849858

850859
case ECPGt_char:
851860
case ECPGt_unsigned_char:
861+
case ECPGt_string:
852862
if (atoi(dimension) == -1)
853863
{
854864
int i = strlen($5);
@@ -1269,6 +1279,7 @@ ECPGVar: SQL_VAR
12691279

12701280
case ECPGt_char:
12711281
case ECPGt_unsigned_char:
1282+
case ECPGt_string:
12721283
if (atoi(dimension) == -1)
12731284
type = ECPGmake_simple_type($5.type_enum, length, 0);
12741285
else

‎src/interfaces/ecpg/preproc/type.c

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

33
#include"postgres_fe.h"
44

@@ -200,6 +200,9 @@ get_type(enum ECPGttype type)
200200
caseECPGt_timestamp:
201201
return ("ECPGt_timestamp");
202202
break;
203+
caseECPGt_string:
204+
return ("ECPGt_string");
205+
break;
203206
default:
204207
mmerror(PARSE_ERROR,ET_ERROR,"unrecognized variable type code %d",type);
205208
}
@@ -366,6 +369,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
366369
caseECPGt_char:
367370
caseECPGt_unsigned_char:
368371
caseECPGt_char_variable:
372+
caseECPGt_string:
369373

370374
/*
371375
* we have to use the pointer except for arrays with given

‎src/interfaces/ecpg/preproc/variable.c

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

33
#include"postgres_fe.h"
44

@@ -500,7 +500,7 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty
500500
"multilevel pointers (more than 2 levels) are not supported; found %d levels",pointer_len),
501501
pointer_len);
502502

503-
if (pointer_len>1&&type_enum!=ECPGt_char&&type_enum!=ECPGt_unsigned_char)
503+
if (pointer_len>1&&type_enum!=ECPGt_char&&type_enum!=ECPGt_unsigned_char&&type_enum!=ECPGt_string)
504504
mmerror(PARSE_ERROR,ET_FATAL,"pointer to pointer is not supported for this data type");
505505

506506
if (pointer_len>1&& (atoi(*length) >=0||atoi(*dimension) >=0))
@@ -539,6 +539,7 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty
539539
break;
540540
caseECPGt_char:
541541
caseECPGt_unsigned_char:
542+
caseECPGt_string:
542543
/* char ** */
543544
if (pointer_len==2)
544545
{

‎src/interfaces/ecpg/test/compat_informix/test_informix.pgc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@ int main(void)
1313
{
1414
$int i = 14;
1515
$decimal j, m, n;
16+
$string c[10];
1617

1718
ECPGdebug(1, stderr);
1819
$whenever sqlerror do dosqlprint();
1920

2021
$connect to REGRESSDB1;
2122
if (sqlca.sqlcode != 0) exit(1);
2223

23-
$create table test(i int primary key, j int);
24+
$create table test(i int primary key, j int, c text);
2425

2526
/* this INSERT works */
2627
rsetnull(CDECIMALTYPE, (char *)&j);
27-
$insert into test (i, j) values (7, :j);
28+
$insert into test (i, j, c) values (7, :j, 'test ');
2829
$commit;
2930

3031
/* this INSERT should fail because i is a unique column */
31-
$insert into test (i, j) values (7, NUMBER);
32+
$insert into test (i, j, c) values (7, NUMBER, 'a');
3233
printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
3334
if (sqlca.sqlcode != 0) $rollback;
3435

35-
$insert into test (i, j) values (:i, 1);
36+
$insert into test (i, j, c) values (:i, 1, 'a ');
3637
$commit;
3738

3839
/* this will fail (more than one row in subquery) */
@@ -51,7 +52,7 @@ int main(void)
5152

5253
while (1)
5354
{
54-
$fetch forward c into :i, :j;
55+
$fetch forward c into :i, :j, :c;
5556
if (sqlca.sqlcode == 100) break;
5657
else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);
5758

@@ -62,7 +63,7 @@ int main(void)
6263
int a;
6364

6465
dectoint(&j, &a);
65-
printf("%d %d\n", i, a);
66+
printf("%d %d \"%s\"\n", i, a, c);
6667
}
6768
}
6869

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp