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 $ */
2
2
3
3
#define POSTGRES_ECPG_INTERNAL
4
4
#include "postgres_fe.h"
16
16
#include "pgtypes_timestamp.h"
17
17
#include "pgtypes_interval.h"
18
18
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
+
19
37
bool
20
38
ECPGget_data (const PGresult * results , int act_tuple , int act_field , int lineno ,
21
39
enum ECPGttype type , enum ECPGttype ind_type ,
22
40
char * 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 )
24
42
{
25
43
struct sqlca_t * sqlca = ECPGget_sqlca ();
26
44
char * pval = (char * ) PQgetvalue (results , act_tuple , act_field );
27
45
int value_for_indicator = 0 ;
28
46
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 );
30
48
31
49
/* pval is a pointer to the value */
32
- /* let's check is it really is an array if it should be one */
33
- if (isarray )
50
+ /* let's check if it really is an array if it should be one */
51
+ if (isarray == ECPG_ARRAY_ARRAY )
34
52
{
35
53
if (* pval != '{' )
36
54
{
@@ -126,9 +144,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
126
144
if (pval )
127
145
{
128
146
res = 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 ))
132
148
{
133
149
ECPGraise (lineno , ECPG_INT_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
134
150
return (false);
@@ -160,8 +176,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
160
176
if (pval )
161
177
{
162
178
ures = 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 ))
165
180
{
166
181
ECPGraise (lineno , ECPG_UINT_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
167
182
return (false);
@@ -193,8 +208,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
193
208
if (pval )
194
209
{
195
210
* ((long long int * ) (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 ))
198
212
{
199
213
ECPGraise (lineno , ECPG_INT_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
200
214
return (false);
@@ -236,8 +250,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
236
250
if (isarray && * scan_length == '"' )
237
251
scan_length ++ ;
238
252
239
- if ((isarray && * scan_length != ',' && * scan_length != '}' )
240
- || (!isarray && * scan_length != '\0' && * scan_length != ' ' )) /* Garbage left */
253
+ if (garbage_left (isarray , scan_length , compat ))
241
254
{
242
255
ECPGraise (lineno , ECPG_FLOAT_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
243
256
return (false);
@@ -411,8 +424,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
411
424
if (isarray && * scan_length == '"' )
412
425
scan_length ++ ;
413
426
414
- if ((isarray && * scan_length != ',' && * scan_length != '}' )
415
- || (!isarray && * scan_length != '\0' && * scan_length != ' ' )) /* Garbage left */
427
+ if (garbage_left (isarray , scan_length , compat ))
416
428
{
417
429
ECPGraise (lineno , ECPG_NUMERIC_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
418
430
return (false);
@@ -455,8 +467,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
455
467
if (isarray && * scan_length == '"' )
456
468
scan_length ++ ;
457
469
458
- if ((isarray && * scan_length != ',' && * scan_length != '}' )
459
- || (!isarray && * scan_length != '\0' && * scan_length != ' ' )) /* Garbage left */
470
+ if (garbage_left (isarray , scan_length , compat ))
460
471
{
461
472
ECPGraise (lineno , ECPG_INTERVAL_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
462
473
return (false);
@@ -495,8 +506,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
495
506
if (isarray && * scan_length == '"' )
496
507
scan_length ++ ;
497
508
498
- if ((isarray && * scan_length != ',' && * scan_length != '}' )
499
- || (!isarray && * scan_length != '\0' && * scan_length != ' ' )) /* Garbage left */
509
+ if (garbage_left (isarray , scan_length , compat ))
500
510
{
501
511
ECPGraise (lineno , ECPG_DATE_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
502
512
return (false);
@@ -534,8 +544,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
534
544
if (isarray && * scan_length == '"' )
535
545
scan_length ++ ;
536
546
537
- if ((isarray && * scan_length != ',' && * scan_length != '}' )
538
- || (!isarray && * scan_length != '\0' && * scan_length != ' ' )) /* Garbage left */
547
+ if (garbage_left (isarray , scan_length , compat ))
539
548
{
540
549
ECPGraise (lineno , ECPG_TIMESTAMP_FORMAT , ECPG_SQLSTATE_DATATYPE_MISMATCH , pval );
541
550
return (false);
@@ -551,7 +560,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
551
560
return (false);
552
561
break ;
553
562
}
554
- if (isarray )
563
+ if (isarray == ECPG_ARRAY_ARRAY )
555
564
{
556
565
bool string = false;
557
566
@@ -566,7 +575,22 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
566
575
if (* pval == ',' )
567
576
++ pval ;
568
577
}
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' ));
570
594
571
595
return (true);
572
596
}
0 commit comments