1- /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.20 2003/09/20 09:10:09 meskes Exp $ */
1+ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.21 2003/11/08 19:46:27 meskes Exp $ */
22
33#define POSTGRES_ECPG_INTERNAL
44#include "postgres_fe.h"
1616#include "pgtypes_timestamp.h"
1717#include "pgtypes_interval.h"
1818
19+ static bool garbage_left (enum ARRAY_TYPE isarray ,char * scan_length ,enum COMPAT_MODE compat )
20+ {
21+ /* INFORMIX allows for selecting a numeric into an int, the result is truncated */
22+ if (isarray == ECPG_ARRAY_NONE && INFORMIX_MODE (compat )&& * scan_length == '.' )
23+ return false;
24+
25+ if (isarray == ECPG_ARRAY_ARRAY && * scan_length != ',' && * scan_length != '}' )
26+ return true;
27+
28+ if (isarray == ECPG_ARRAY_VECTOR && * scan_length != ' ' && * scan_length != '\0' )
29+ return true;
30+
31+ if (isarray == ECPG_ARRAY_NONE && * scan_length != ' ' && * scan_length != '\0' )
32+ return true;
33+
34+ return false;
35+ }
36+
1937bool
2038ECPGget_data (const PGresult * results ,int act_tuple ,int act_field ,int lineno ,
2139enum ECPGttype type ,enum ECPGttype ind_type ,
2240char * var ,char * ind ,long varcharsize ,long offset ,
23- long ind_offset ,bool isarray ,enum COMPAT_MODE compat ,bool force_indicator )
41+ long ind_offset ,enum ARRAY_TYPE isarray ,enum COMPAT_MODE compat ,bool force_indicator )
2442{
2543struct sqlca_t * sqlca = ECPGget_sqlca ();
2644char * pval = (char * )PQgetvalue (results ,act_tuple ,act_field );
2745int value_for_indicator = 0 ;
2846
29- ECPGlog ("ECPGget_data line %d: RESULT: %s offset: %ld\n" ,lineno ,pval ?pval :"" ,offset );
47+ ECPGlog ("ECPGget_data line %d: RESULT: %s offset: %ld array: %d \n" ,lineno ,pval ?pval :"" ,offset , isarray );
3048
3149/* pval is a pointer to the value */
32- /* let's checkis it really is an array if it should be one */
33- if (isarray )
50+ /* let's checkif it really is an array if it should be one */
51+ if (isarray == ECPG_ARRAY_ARRAY )
3452{
3553if (* pval != '{' )
3654{
@@ -126,9 +144,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
126144if (pval )
127145{
128146res = strtol (pval ,& scan_length ,10 );
129- /* INFORMIX allows for selecting a numeric into an int, the result is truncated */
130- if ((isarray && * scan_length != ',' && * scan_length != '}' )
131- || (!isarray && !(INFORMIX_MODE (compat )&& * scan_length == '.' )&& * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
147+ if (garbage_left (isarray ,scan_length ,compat ))
132148{
133149ECPGraise (lineno ,ECPG_INT_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
134150return (false);
@@ -160,8 +176,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
160176if (pval )
161177{
162178ures = strtoul (pval ,& scan_length ,10 );
163- if ((isarray && * scan_length != ',' && * scan_length != '}' )
164- || (!isarray && !(INFORMIX_MODE (compat )&& * scan_length == '.' )&& * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
179+ if (garbage_left (isarray ,scan_length ,compat ))
165180{
166181ECPGraise (lineno ,ECPG_UINT_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
167182return (false);
@@ -193,8 +208,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
193208if (pval )
194209{
195210* ((long longint * ) (var + offset * act_tuple ))= strtoll (pval ,& scan_length ,10 );
196- if ((isarray && * scan_length != ',' && * scan_length != '}' )
197- || (!isarray && !(INFORMIX_MODE (compat )&& * scan_length == '.' )&& * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
211+ if (garbage_left (isarray ,scan_length ,compat ))
198212{
199213ECPGraise (lineno ,ECPG_INT_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
200214return (false);
@@ -236,8 +250,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
236250if (isarray && * scan_length == '"' )
237251scan_length ++ ;
238252
239- if ((isarray && * scan_length != ',' && * scan_length != '}' )
240- || (!isarray && * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
253+ if (garbage_left (isarray ,scan_length ,compat ))
241254{
242255ECPGraise (lineno ,ECPG_FLOAT_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
243256return (false);
@@ -411,8 +424,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
411424if (isarray && * scan_length == '"' )
412425scan_length ++ ;
413426
414- if ((isarray && * scan_length != ',' && * scan_length != '}' )
415- || (!isarray && * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
427+ if (garbage_left (isarray ,scan_length ,compat ))
416428{
417429ECPGraise (lineno ,ECPG_NUMERIC_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
418430return (false);
@@ -455,8 +467,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
455467if (isarray && * scan_length == '"' )
456468scan_length ++ ;
457469
458- if ((isarray && * scan_length != ',' && * scan_length != '}' )
459- || (!isarray && * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
470+ if (garbage_left (isarray ,scan_length ,compat ))
460471{
461472ECPGraise (lineno ,ECPG_INTERVAL_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
462473return (false);
@@ -495,8 +506,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
495506if (isarray && * scan_length == '"' )
496507scan_length ++ ;
497508
498- if ((isarray && * scan_length != ',' && * scan_length != '}' )
499- || (!isarray && * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
509+ if (garbage_left (isarray ,scan_length ,compat ))
500510{
501511ECPGraise (lineno ,ECPG_DATE_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
502512return (false);
@@ -534,8 +544,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
534544if (isarray && * scan_length == '"' )
535545scan_length ++ ;
536546
537- if ((isarray && * scan_length != ',' && * scan_length != '}' )
538- || (!isarray && * scan_length != '\0' && * scan_length != ' ' ))/* Garbage left */
547+ if (garbage_left (isarray ,scan_length ,compat ))
539548{
540549ECPGraise (lineno ,ECPG_TIMESTAMP_FORMAT ,ECPG_SQLSTATE_DATATYPE_MISMATCH ,pval );
541550return (false);
@@ -551,7 +560,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
551560return (false);
552561break ;
553562}
554- if (isarray )
563+ if (isarray == ECPG_ARRAY_ARRAY )
555564{
556565bool string = false;
557566
@@ -566,7 +575,22 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
566575if (* pval == ',' )
567576++ pval ;
568577}
569- }while (isarray && * pval != '}' );
578+ else if (isarray == ECPG_ARRAY_VECTOR )
579+ {
580+ bool string = false;
581+
582+ /* set array to next entry */
583+ ++ act_tuple ;
584+
585+ /* set pval to the next entry */
586+ for (;string || (* pval != ' ' && * pval != '\0' );++ pval )
587+ if (* pval == '"' )
588+ string = string ? false : true;
589+
590+ if (* pval == ' ' )
591+ ++ pval ;
592+ }
593+ }while ((isarray == ECPG_ARRAY_ARRAY && * pval != '}' )|| (isarray == ECPG_ARRAY_VECTOR && * pval != '\0' ));
570594
571595return (true);
572596}