Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a96ad2f

Browse files
author
Michael Meskes
committed
Streamlined array handling code in libecpg a little bit, in the process fixing yet another incorrect log output.
1 parent c00353a commit a96ad2f

38 files changed

+493
-479
lines changed

src/interfaces/ecpg/ecpglib/data.c

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.48 2010/02/02 16:09:11 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.49 2010/02/04 09:41:34 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -17,23 +17,49 @@
1717
#include "pgtypes_timestamp.h"
1818
#include "pgtypes_interval.h"
1919

20+
/* returns true if character c is a delimiter for the given array type */
21+
static bool
22+
array_delimiter(enum ARRAY_TYPE isarray, char c)
23+
{
24+
if (isarray == ECPG_ARRAY_ARRAY && c == ',')
25+
return true;
26+
27+
if (isarray == ECPG_ARRAY_VECTOR && c == ' ')
28+
return true;
29+
30+
return false;
31+
}
32+
33+
/* returns true if character c marks the boundary for the given array type */
34+
static bool
35+
array_boundary(enum ARRAY_TYPE isarray, char c)
36+
{
37+
if (isarray == ECPG_ARRAY_ARRAY && c == '}')
38+
return true;
39+
40+
if (isarray == ECPG_ARRAY_VECTOR && c == '\0')
41+
return true;
42+
43+
return false;
44+
}
45+
46+
/* returns true if some garbage is found at the end of the scanned string */
2047
static bool
2148
garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat)
2249
{
2350
/*
2451
* INFORMIX allows for selecting a numeric into an int, the result is
2552
* truncated
2653
*/
27-
if (isarray == ECPG_ARRAY_NONE && INFORMIX_MODE(compat) && *scan_length == '.')
28-
return false;
29-
30-
if (isarray == ECPG_ARRAY_ARRAY && *scan_length != ',' && *scan_length != '}')
31-
return true;
32-
33-
if (isarray == ECPG_ARRAY_VECTOR && *scan_length != ' ' && *scan_length != '\0')
34-
return true;
54+
if (isarray == ECPG_ARRAY_NONE)
55+
{
56+
if (INFORMIX_MODE(compat) && *scan_length == '.')
57+
return false;
3558

36-
if (isarray == ECPG_ARRAY_NONE && *scan_length != ' ' && *scan_length != '\0')
59+
if (*scan_length != ' ' && *scan_length != '\0')
60+
return true;
61+
}
62+
else if (ECPG_IS_ARRAY(isarray) && !array_delimiter(isarray, *scan_length) && !array_boundary(isarray, *scan_length))
3763
return true;
3864

3965
return false;
@@ -113,7 +139,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
113139
else
114140
log_offset = offset;
115141

116-
ecpg_log("ecpg_get_data on line %d: RESULT: %s offset: %ld; array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", log_offset, isarray ? "yes" : "no");
142+
ecpg_log("ecpg_get_data on line %d: RESULT: %s offset: %ld; array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", log_offset, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
117143

118144
/* pval is a pointer to the value */
119145
if (!pval)
@@ -726,38 +752,24 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
726752
return (false);
727753
break;
728754
}
729-
if (isarray == ECPG_ARRAY_ARRAY)
730-
{
731-
bool string = false;
732-
733-
/* set array to next entry */
734-
++act_tuple;
735-
736-
/* set pval to the next entry */
737-
for (; string || (*pval != ',' && *pval != '}' && *pval != '\0'); ++pval)
738-
if (*pval == '"')
739-
string = string ? false : true;
740-
741-
if (*pval == ',')
742-
++pval;
743-
}
744-
else if (isarray == ECPG_ARRAY_VECTOR)
755+
if (ECPG_IS_ARRAY(isarray))
745756
{
746757
bool string = false;
747758

748759
/* set array to next entry */
749760
++act_tuple;
750761

751762
/* set pval to the next entry */
752-
for (; string || (*pval != ' ' && *pval != '\0'); ++pval)
763+
/* *pval != '\0' should not be needed, but is used as a safety guard */
764+
for (; *pval != '\0' && (string || (!array_delimiter(isarray, *pval) && !array_boundary(isarray, *pval))); ++pval)
753765
if (*pval == '"')
754766
string = string ? false : true;
755767

756-
if (*pval == ' ')
768+
if (array_delimiter(isarray, *pval))
757769
++pval;
758770
}
759771
}
760-
} while (*pval != '\0' && ((isarray == ECPG_ARRAY_ARRAY && *pval != '}') || isarray == ECPG_ARRAY_VECTOR));
772+
} while (*pval != '\0' && array_boundary(isarray, *pval));
761773

762774
return (true);
763775
}

src/interfaces/ecpg/ecpglib/execute.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.92 2010/02/03 03:25:55 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.93 2010/02/04 09:41:34 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -305,7 +305,7 @@ ecpg_is_type_an_array(int type, const struct statement * stmt, const struct vari
305305
return (ECPG_ARRAY_ERROR);
306306

307307
ecpg_type_infocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno);
308-
ecpg_log("ecpg_is_type_an_array on line %d: type (%d); C (%d); array (%s)\n", stmt->lineno, type, var->type, (isarray != ECPG_ARRAY_NONE) ? "yes" : "no");
308+
ecpg_log("ecpg_is_type_an_array on line %d: type (%d); C (%d); array (%s)\n", stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
309309
return isarray;
310310
}
311311

src/interfaces/ecpg/ecpglib/extern.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.37 2010/01/15 10:44:34 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.38 2010/02/04 09:41:34 meskes Exp $ */
22

33
#ifndef _ECPG_LIB_EXTERN_H
44
#define _ECPG_LIB_EXTERN_H
@@ -27,6 +27,8 @@ enum ARRAY_TYPE
2727
ECPG_ARRAY_ERROR, ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
2828
};
2929

30+
#define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
31+
3032
/* A generic varchar type. */
3133
struct ECPGgeneric_varchar
3234
{

src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -66,51 +66,51 @@
6666
[NO_PID]: sqlca: code: 0, state: 00000
6767
[NO_PID]: ecpg_execute on line 59: correctly got 1 tuples with 10 fields
6868
[NO_PID]: sqlca: code: 0, state: 00000
69-
[NO_PID]: ecpg_get_data on line 59: RESULT: abc offset: -1; array: yes
69+
[NO_PID]: ecpg_get_data on line 59: RESULT: abc offset: -1; array: no
7070
[NO_PID]: sqlca: code: 0, state: 00000
71-
[NO_PID]: ecpg_get_data on line 59: RESULT: 17 offset: -1; array: yes
71+
[NO_PID]: ecpg_get_data on line 59: RESULT: 17 offset: -1; array: no
7272
[NO_PID]: sqlca: code: 0, state: 00000
73-
[NO_PID]: ecpg_get_data on line 59: RESULT: -74874 offset: -1; array: yes
73+
[NO_PID]: ecpg_get_data on line 59: RESULT: -74874 offset: -1; array: no
7474
[NO_PID]: sqlca: code: 0, state: 00000
75-
[NO_PID]: ecpg_get_data on line 59: RESULT: t offset: -1; array: yes
75+
[NO_PID]: ecpg_get_data on line 59: RESULT: t offset: -1; array: no
7676
[NO_PID]: sqlca: code: 0, state: 00000
77-
[NO_PID]: ecpg_get_data on line 59: RESULT: 3.710000038147 offset: -1; array: yes
77+
[NO_PID]: ecpg_get_data on line 59: RESULT: 3.710000038147 offset: -1; array: no
7878
[NO_PID]: sqlca: code: 0, state: 00000
79-
[NO_PID]: ecpg_get_data on line 59: RESULT: 487444 offset: -1; array: yes
79+
[NO_PID]: ecpg_get_data on line 59: RESULT: 487444 offset: -1; array: no
8080
[NO_PID]: sqlca: code: 0, state: 00000
81-
[NO_PID]: ecpg_get_data on line 59: RESULT: 404.404 offset: -1; array: yes
81+
[NO_PID]: ecpg_get_data on line 59: RESULT: 404.404 offset: -1; array: no
8282
[NO_PID]: sqlca: code: 0, state: 00000
83-
[NO_PID]: ecpg_get_data on line 59: RESULT: offset: -1; array: yes
83+
[NO_PID]: ecpg_get_data on line 59: RESULT: offset: -1; array: no
8484
[NO_PID]: sqlca: code: 0, state: 00000
85-
[NO_PID]: ecpg_get_data on line 59: RESULT: offset: -1; array: yes
85+
[NO_PID]: ecpg_get_data on line 59: RESULT: offset: -1; array: no
8686
[NO_PID]: sqlca: code: 0, state: 00000
87-
[NO_PID]: ecpg_get_data on line 59: RESULT: offset: -1; array: yes
87+
[NO_PID]: ecpg_get_data on line 59: RESULT: offset: -1; array: no
8888
[NO_PID]: sqlca: code: 0, state: 00000
8989
[NO_PID]: ecpg_execute on line 76: query: select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 2; with 0 parameter(s) on connection regress1
9090
[NO_PID]: sqlca: code: 0, state: 00000
9191
[NO_PID]: ecpg_execute on line 76: using PQexec
9292
[NO_PID]: sqlca: code: 0, state: 00000
9393
[NO_PID]: ecpg_execute on line 76: correctly got 1 tuples with 10 fields
9494
[NO_PID]: sqlca: code: 0, state: 00000
95-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
95+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
9696
[NO_PID]: sqlca: code: 0, state: 00000
97-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
97+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
9898
[NO_PID]: sqlca: code: 0, state: 00000
99-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
99+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
100100
[NO_PID]: sqlca: code: 0, state: 00000
101-
[NO_PID]: ecpg_get_data on line 76: RESULT: t offset: -1; array: yes
101+
[NO_PID]: ecpg_get_data on line 76: RESULT: t offset: -1; array: no
102102
[NO_PID]: sqlca: code: 0, state: 00000
103-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
103+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
104104
[NO_PID]: sqlca: code: 0, state: 00000
105-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
105+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
106106
[NO_PID]: sqlca: code: 0, state: 00000
107-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
107+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
108108
[NO_PID]: sqlca: code: 0, state: 00000
109-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
109+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
110110
[NO_PID]: sqlca: code: 0, state: 00000
111-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
111+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
112112
[NO_PID]: sqlca: code: 0, state: 00000
113-
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: yes
113+
[NO_PID]: ecpg_get_data on line 76: RESULT: offset: -1; array: no
114114
[NO_PID]: sqlca: code: 0, state: 00000
115115
[NO_PID]: ecpg_execute on line 91: query: drop table test; with 0 parameter(s) on connection regress1
116116
[NO_PID]: sqlca: code: 0, state: 00000

0 commit comments

Comments
 (0)