Hi,

   In ecpg, the error occurs in value lists of the INSERT statement,
when 'short' or 'unsigned short' host variables are used.

1. Program sample

   exec sql begin declare section;
      short s ;
      unsigned short us;
   exec sql end   declare section;
   exec sql create table test(s smallint, us smallint);
   exec sql commit;
   s = 1; us =32000;
   exec sql insert into test values( :s, :us ) ;  <== error

2. Error messege

   Following error message are output.  
   "i4toi2: '-600309759' causes int2 underflow"

3. Patch

   The error does not occur, when following patches were applied.  
Is this patch right?  please confirm it.  

--
Regards.

SAKAIDA Masaaki <sakaida@psn.co.jp>
Personal Software, Inc. Osaka Japan


*** postgresql-6.5/src/interfaces/ecpg/lib/ecpglib.c.orig	Wed Jun 24 15:21:30 1999
--- postgresql-6.5/src/interfaces/ecpg/lib/ecpglib.c	Wed Jun 24 15:31:57
1999
***************
*** 469,480 ****
--- 469,488 ----
  			switch (var->type)
  			{
  				case ECPGt_short:
+ 					sprintf(buff, "%d", *(short *) var->value);
+ 					tobeinserted = buff;
+ 					break;
+ 
  				case ECPGt_int:
  					sprintf(buff, "%d", *(int *) var->value);
  					tobeinserted = buff;
  					break;
  
  				case ECPGt_unsigned_short:
+ 					sprintf(buff, "%d", *(unsigned short *) var->value);
+ 					tobeinserted = buff;
+ 					break;
+ 
  				case ECPGt_unsigned_int:
  					sprintf(buff, "%d", *(unsigned int *) var->value);
  					tobeinserted = buff;


Thu, 24 Jun 1999 17:57:01 +0900
SAKAIDA <sakaida@psn.co.jp>
INSERT VALUES error in ecpg.

This patch looks good.  Comments?


> Hi,
> 
>    In ecpg, the error occurs in value lists of the INSERT statement,
> when 'short' or 'unsigned short' host variables are used.
> 
> 1. Program sample
> 
>    exec sql begin declare section;
>       short s ;
>       unsigned short us;
>    exec sql end   declare section;
>    exec sql create table test(s smallint, us smallint);
>    exec sql commit;
>    s = 1; us =32000;
>    exec sql insert into test values( :s, :us ) ;  <== error
> 
> 2. Error messege
> 
>    Following error message are output.  
>    "i4toi2: '-600309759' causes int2 underflow"
> 
> 3. Patch
> 
>    The error does not occur, when following patches were applied.  
> Is this patch right?  please confirm it.  
> 
> --
> Regards.
> 
> SAKAIDA Masaaki <sakaida@psn.co.jp>
> Personal Software, Inc. Osaka Japan
> 
> 
> *** postgresql-6.5/src/interfaces/ecpg/lib/ecpglib.c.orig	Wed Jun 24 15:21:30 1999
> --- postgresql-6.5/src/interfaces/ecpg/lib/ecpglib.c	Wed Jun 24 15:31:57
> 1999
> ***************
> *** 469,480 ****
> --- 469,488 ----
>   			switch (var->type)
>   			{
>   				case ECPGt_short:
> + 					sprintf(buff, "%d", *(short *) var->value);
> + 					tobeinserted = buff;
> + 					break;
> + 
>   				case ECPGt_int:
>   					sprintf(buff, "%d", *(int *) var->value);
>   					tobeinserted = buff;
>   					break;
>   
>   				case ECPGt_unsigned_short:
> + 					sprintf(buff, "%d", *(unsigned short *) var->value);
> + 					tobeinserted = buff;
> + 					break;
> + 
>   				case ECPGt_unsigned_int:
>   					sprintf(buff, "%d", *(unsigned int *) var->value);
>   					tobeinserted = buff;
> 
> 
> 


-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Wed, 7 Jul 1999 21:57:35 -0400 (EDT)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] INSERT VALUES error in ecpg.
I have applied this patch, and it will appear in 6.5.1.


> Hi,
> 
>    In ecpg, the error occurs in value lists of the INSERT statement,
> when 'short' or 'unsigned short' host variables are used.
> 
> 1. Program sample
> 
>    exec sql begin declare section;
>       short s ;
>       unsigned short us;
>    exec sql end   declare section;
>    exec sql create table test(s smallint, us smallint);
>    exec sql commit;
>    s = 1; us =32000;
>    exec sql insert into test values( :s, :us ) ;  <== error
> 
> 2. Error messege
> 
>    Following error message are output.  
>    "i4toi2: '-600309759' causes int2 underflow"
> 
> 3. Patch
> 
>    The error does not occur, when following patches were applied.  
> Is this patch right?  please confirm it.  
> 
> --
> Regards.
> 
> SAKAIDA Masaaki <sakaida@psn.co.jp>
> Personal Software, Inc. Osaka Japan
> 
> 
> *** postgresql-6.5/src/interfaces/ecpg/lib/ecpglib.c.orig	Wed Jun 24 15:21:30 1999
> --- postgresql-6.5/src/interfaces/ecpg/lib/ecpglib.c	Wed Jun 24 15:31:57
> 1999
> ***************
> *** 469,480 ****
> --- 469,488 ----
>   			switch (var->type)
>   			{
>   				case ECPGt_short:
> + 					sprintf(buff, "%d", *(short *) var->value);
> + 					tobeinserted = buff;
> + 					break;
> + 
>   				case ECPGt_int:
>   					sprintf(buff, "%d", *(int *) var->value);
>   					tobeinserted = buff;
>   					break;
>   
>   				case ECPGt_unsigned_short:
> + 					sprintf(buff, "%d", *(unsigned short *) var->value);
> + 					tobeinserted = buff;
> + 					break;
> + 
>   				case ECPGt_unsigned_int:
>   					sprintf(buff, "%d", *(unsigned int *) var->value);
>   					tobeinserted = buff;
> 
> 
> 


-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Sun, 11 Jul 1999 22:25:01 -0400 (EDT)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] INSERT VALUES error in ecpg.