11
11
#include " cubedata.h"
12
12
#include " buffer.h"
13
13
14
- #include " utils/palloc.h"
15
- #include " utils/elog.h"
16
-
17
14
#undef yylex /* falure to redefine yylex will result in a call to the */
18
15
#define yylex cube_yylex /* wrong scanner when running inside the postgres backend */
19
16
48
45
if ( c != ' \0 ' ) {
49
46
/* Not at EOF */
50
47
reset_parse_buffer ();
51
- elog (ERROR, " (0) bad cube representation; garbage at or before char %d, ('%c', \\ %03o)\n " , pos, c, c );
48
+ ereport (ERROR,
49
+ (errcode(ERRCODE_SYNTAX_ERROR),
50
+ errmsg(" bad cube representation" ),
51
+ errdetail(" garbage at or before char %d, ('%c', \\ %03o)" ,
52
+ pos, c, c)));
52
53
YYERROR ;
53
54
}
54
55
55
56
dim = delim_count($2 , ' ,' ) + 1 ;
56
57
if ( (delim_count($4 , ' ,' ) + 1 ) != dim ) {
57
58
reset_parse_buffer ();
58
- elog (ERROR, " (1) bad cube representation; different point dimensions in (%s) and (%s)\n " , $2 , $4 );
59
+ ereport (ERROR,
60
+ (errcode(ERRCODE_SYNTAX_ERROR),
61
+ errmsg(" bad cube representation" ),
62
+ errdetail(" different point dimensions in (%s) and (%s)" ,
63
+ $2 , $4 )));
59
64
YYABORT ;
60
65
}
61
66
if (dim > CUBE_MAX_DIM) {
62
67
reset_parse_buffer ();
63
- elog (ERROR, " (8) bad cube representation; more than %d dimensions\n " , CUBE_MAX_DIM);
68
+ ereport (ERROR,
69
+ (errcode(ERRCODE_SYNTAX_ERROR),
70
+ errmsg(" bad cube representation" ),
71
+ errdetail(" more than %d dimensions" ,
72
+ CUBE_MAX_DIM)));
64
73
YYABORT ;
65
74
}
66
75
75
84
76
85
if ( c != ' \0 ' ) { /* Not at EOF */
77
86
reset_parse_buffer ();
78
- elog (ERROR, " (2) bad cube representation; garbage at or before char %d, ('%c', \\ %03o)\n " , pos, c, c );
87
+ ereport (ERROR,
88
+ (errcode(ERRCODE_SYNTAX_ERROR),
89
+ errmsg(" bad cube representation" ),
90
+ errdetail(" garbage at or before char %d, ('%c', \\ %03o)" ,
91
+ pos, c, c)));
79
92
YYABORT ;
80
93
}
81
94
82
95
dim = delim_count($1 , ' ,' ) + 1 ;
83
96
84
97
if ( (delim_count($3 , ' ,' ) + 1 ) != dim ) {
85
98
reset_parse_buffer ();
86
- elog (ERROR, " (3) bad cube representation; different point dimensions in (%s) and (%s)\n " , $1 , $3 );
99
+ ereport (ERROR,
100
+ (errcode(ERRCODE_SYNTAX_ERROR),
101
+ errmsg(" bad cube representation" ),
102
+ errdetail(" different point dimensions in (%s) and (%s)" ,
103
+ $1 , $3 )));
87
104
YYABORT ;
88
105
}
89
106
if (dim > CUBE_MAX_DIM) {
90
107
reset_parse_buffer ();
91
- elog (ERROR, " (8) bad cube representation; more than %d dimensions\n " , CUBE_MAX_DIM);
108
+ ereport (ERROR,
109
+ (errcode(ERRCODE_SYNTAX_ERROR),
110
+ errmsg(" bad cube representation" ),
111
+ errdetail(" more than %d dimensions" ,
112
+ CUBE_MAX_DIM)));
92
113
YYABORT ;
93
114
}
94
115
@@ -103,21 +124,33 @@ box:
103
124
104
125
if ( c != ' \0 ' ) { /* Not at EOF */
105
126
reset_parse_buffer ();
106
- elog (ERROR, " (4) bad cube representation; garbage at or before char %d, ('%c', \\ %03o)\n " , pos, c, c );
127
+ ereport (ERROR,
128
+ (errcode(ERRCODE_SYNTAX_ERROR),
129
+ errmsg(" bad cube representation" ),
130
+ errdetail(" garbage at or before char %d, ('%c', \\ %03o)" ,
131
+ pos, c, c)));
107
132
YYABORT ;
108
133
}
109
134
110
135
if ( yychar != YYEOF) {
111
136
/* There's still a lookahead token to be parsed */
112
137
reset_parse_buffer ();
113
- elog (ERROR, " (5) bad cube representation; garbage at or before char %d, ('end of input', \\ %03o)\n " , pos, c);
138
+ ereport (ERROR,
139
+ (errcode(ERRCODE_SYNTAX_ERROR),
140
+ errmsg(" bad cube representation" ),
141
+ errdetail(" garbage at or before char %d, ('end of input', \\ %03o)" ,
142
+ pos, c)));
114
143
YYABORT ;
115
144
}
116
145
117
146
dim = delim_count($1 , ' ,' ) + 1 ;
118
147
if (dim > CUBE_MAX_DIM) {
119
148
reset_parse_buffer ();
120
- elog (ERROR, " (8) bad cube representation; more than %d dimensions\n " , CUBE_MAX_DIM);
149
+ ereport (ERROR,
150
+ (errcode(ERRCODE_SYNTAX_ERROR),
151
+ errmsg(" bad cube representation" ),
152
+ errdetail(" more than %d dimensions" ,
153
+ CUBE_MAX_DIM)));
121
154
YYABORT ;
122
155
}
123
156
@@ -133,21 +166,33 @@ box:
133
166
134
167
if ( c != ' \0 ' ) { /* Not at EOF */
135
168
reset_parse_buffer ();
136
- elog (ERROR, " (6) bad cube representation; garbage at or before char %d, ('%c', \\ %03o)\n " , pos, c, c);
169
+ ereport (ERROR,
170
+ (errcode(ERRCODE_SYNTAX_ERROR),
171
+ errmsg(" bad cube representation" ),
172
+ errdetail(" garbage at or before char %d, ('%c', \\ %03o)" ,
173
+ pos, c, c)));
137
174
YYABORT ;
138
175
}
139
176
140
177
if ( yychar != YYEOF) {
141
178
/* There's still a lookahead token to be parsed */
142
179
reset_parse_buffer ();
143
- elog (ERROR, " (7) bad cube representation; garbage at or before char %d, ('end of input', \\ %03o)\n " , pos, c);
180
+ ereport (ERROR,
181
+ (errcode(ERRCODE_SYNTAX_ERROR),
182
+ errmsg(" bad cube representation" ),
183
+ errdetail(" garbage at or before char %d, ('end of input', \\ %03o)" ,
184
+ pos, c)));
144
185
YYABORT ;
145
186
}
146
187
147
188
dim = delim_count($1 , ' ,' ) + 1 ;
148
189
if (dim > CUBE_MAX_DIM) {
149
190
reset_parse_buffer ();
150
- elog (ERROR, " (8) bad cube representation; more than %d dimensions\n " , CUBE_MAX_DIM);
191
+ ereport (ERROR,
192
+ (errcode(ERRCODE_SYNTAX_ERROR),
193
+ errmsg(" bad cube representation" ),
194
+ errdetail(" more than %d dimensions" ,
195
+ CUBE_MAX_DIM)));
151
196
YYABORT ;
152
197
}
153
198
*((void **)result) = write_point_as_box($1 , dim);
@@ -191,7 +236,7 @@ int cube_yyerror ( char *msg ) {
191
236
snprintf (
192
237
buf,
193
238
256 ,
194
- " %s at or before position %d, character ('%c', \\ %03o), input: '%s'\n " ,
239
+ " %s at or before position %d, character ('%c', \\ %03o), input: '%s'" ,
195
240
msg,
196
241
position,
197
242
parse_buffer ()[position - 1 ],
@@ -200,7 +245,11 @@ int cube_yyerror ( char *msg ) {
200
245
);
201
246
202
247
reset_parse_buffer ();
203
- elog (ERROR, " %s" , buf);
248
+ ereport (ERROR,
249
+ (errcode (ERRCODE_SYNTAX_ERROR),
250
+ errmsg (" bad cube representation" ),
251
+ errdetail (" %s" , buf)));
252
+
204
253
return 0 ;
205
254
}
206
255
0 commit comments