Skip to content

Commit 52ed85d

Browse files
committed
Cleanup: unnest array check
1 parent 6179d16 commit 52ed85d

File tree

1 file changed

+94
-93
lines changed

1 file changed

+94
-93
lines changed

ibase_query.c

Lines changed: 94 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -136,110 +136,111 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{
136136
zend_ulong ar_size = 1;
137137
XSQLVAR *var = &sqlda->sqlvar[i];
138138

139-
if ((var->sqltype & ~1) == SQL_ARRAY) {
140-
ibase_array *a = &ar[n++];
141-
ISC_ARRAY_DESC *ar_desc = &a->ar_desc;
139+
if ((var->sqltype & ~1) != SQL_ARRAY) {
140+
continue;
141+
}
142142

143-
if (isc_array_lookup_bounds(IB_STATUS, &link, &trans, var->relname,
144-
var->sqlname, ar_desc)) {
145-
_php_ibase_error();
146-
efree(ar);
147-
return FAILURE;
148-
}
143+
ibase_array *a = &ar[n++];
144+
ISC_ARRAY_DESC *ar_desc = &a->ar_desc;
149145

150-
switch (ar_desc->array_desc_dtype) {
151-
case blr_text:
152-
case blr_text2:
153-
a->el_type = SQL_TEXT;
154-
a->el_size = ar_desc->array_desc_length;
155-
break;
156-
// Boolean data type exists since FB 3.0
146+
if (isc_array_lookup_bounds(IB_STATUS, &link, &trans, var->relname,
147+
var->sqlname, ar_desc)) {
148+
_php_ibase_error();
149+
efree(ar);
150+
return FAILURE;
151+
}
152+
153+
switch (ar_desc->array_desc_dtype) {
154+
case blr_text:
155+
case blr_text2:
156+
a->el_type = SQL_TEXT;
157+
a->el_size = ar_desc->array_desc_length;
158+
break;
157159
#ifdef SQL_BOOLEAN
158160
case blr_bool:
159161
a->el_type = SQL_BOOLEAN;
160162
a->el_size = sizeof(FB_BOOLEAN);
161163
break;
162164
#endif
163-
case blr_short:
164-
a->el_type = SQL_SHORT;
165-
a->el_size = sizeof(short);
166-
break;
167-
case blr_long:
168-
a->el_type = SQL_LONG;
169-
a->el_size = sizeof(ISC_LONG);
170-
break;
171-
case blr_float:
172-
a->el_type = SQL_FLOAT;
173-
a->el_size = sizeof(float);
174-
break;
175-
case blr_double:
176-
a->el_type = SQL_DOUBLE;
177-
a->el_size = sizeof(double);
178-
break;
179-
case blr_int64:
180-
a->el_type = SQL_INT64;
181-
a->el_size = sizeof(ISC_INT64);
182-
break;
183-
case blr_timestamp:
184-
a->el_type = SQL_TIMESTAMP;
185-
a->el_size = sizeof(ISC_TIMESTAMP);
186-
break;
187-
case blr_sql_date:
188-
a->el_type = SQL_TYPE_DATE;
189-
a->el_size = sizeof(ISC_DATE);
190-
break;
191-
case blr_sql_time:
192-
a->el_type = SQL_TYPE_TIME;
193-
a->el_size = sizeof(ISC_TIME);
194-
break;
165+
case blr_short:
166+
a->el_type = SQL_SHORT;
167+
a->el_size = sizeof(short);
168+
break;
169+
case blr_long:
170+
a->el_type = SQL_LONG;
171+
a->el_size = sizeof(ISC_LONG);
172+
break;
173+
case blr_float:
174+
a->el_type = SQL_FLOAT;
175+
a->el_size = sizeof(float);
176+
break;
177+
case blr_double:
178+
a->el_type = SQL_DOUBLE;
179+
a->el_size = sizeof(double);
180+
break;
181+
case blr_int64:
182+
a->el_type = SQL_INT64;
183+
a->el_size = sizeof(ISC_INT64);
184+
break;
185+
case blr_timestamp:
186+
a->el_type = SQL_TIMESTAMP;
187+
a->el_size = sizeof(ISC_TIMESTAMP);
188+
break;
189+
case blr_sql_date:
190+
a->el_type = SQL_TYPE_DATE;
191+
a->el_size = sizeof(ISC_DATE);
192+
break;
193+
case blr_sql_time:
194+
a->el_type = SQL_TYPE_TIME;
195+
a->el_size = sizeof(ISC_TIME);
196+
break;
195197
#if FB_API_VER >= 40
196-
// These are converted to VARCHAR via isc_dpb_set_bind tag at connect
197-
// blr_dec64
198-
// blr_dec128
199-
// blr_int128
200-
case blr_sql_time_tz:
201-
a->el_type = SQL_TIME_TZ;
202-
a->el_size = sizeof(ISC_TIME_TZ);
203-
break;
204-
case blr_timestamp_tz:
205-
a->el_type = SQL_TIMESTAMP_TZ;
206-
a->el_size = sizeof(ISC_TIMESTAMP_TZ);
207-
break;
198+
// These are converted to VARCHAR via isc_dpb_set_bind tag at connect
199+
// blr_dec64
200+
// blr_dec128
201+
// blr_int128
202+
case blr_sql_time_tz:
203+
a->el_type = SQL_TIME_TZ;
204+
a->el_size = sizeof(ISC_TIME_TZ);
205+
break;
206+
case blr_timestamp_tz:
207+
a->el_type = SQL_TIMESTAMP_TZ;
208+
a->el_size = sizeof(ISC_TIMESTAMP_TZ);
209+
break;
208210
#endif
209-
case blr_varying:
210-
case blr_varying2:
211-
/**
212-
* IB has a strange way of handling VARCHAR arrays. It doesn't store
213-
* the length in the first short, as with VARCHAR fields. It does,
214-
* however, expect the extra short to be allocated for each element.
215-
*/
216-
a->el_type = SQL_TEXT;
217-
a->el_size = ar_desc->array_desc_length + sizeof(short);
218-
break;
219-
case blr_quad:
220-
case blr_blob_id:
221-
case blr_cstring:
222-
case blr_cstring2:
223-
/**
224-
* These types are mentioned as array types in the manual, but I
225-
* wouldn't know how to create an array field with any of these
226-
* types. I assume these types are not applicable to arrays, and
227-
* were mentioned erroneously.
228-
*/
229-
default:
230-
_php_ibase_module_error("Unsupported array type %d in relation '%s' column '%s'",
231-
ar_desc->array_desc_dtype, var->relname, var->sqlname);
232-
efree(ar);
233-
return FAILURE;
234-
} /* switch array_desc_type */
211+
case blr_varying:
212+
case blr_varying2:
213+
/**
214+
* IB has a strange way of handling VARCHAR arrays. It doesn't store
215+
* the length in the first short, as with VARCHAR fields. It does,
216+
* however, expect the extra short to be allocated for each element.
217+
*/
218+
a->el_type = SQL_TEXT;
219+
a->el_size = ar_desc->array_desc_length + sizeof(short);
220+
break;
221+
case blr_quad:
222+
case blr_blob_id:
223+
case blr_cstring:
224+
case blr_cstring2:
225+
/**
226+
* These types are mentioned as array types in the manual, but I
227+
* wouldn't know how to create an array field with any of these
228+
* types. I assume these types are not applicable to arrays, and
229+
* were mentioned erroneously.
230+
*/
231+
default:
232+
_php_ibase_module_error("Unsupported array type %d in relation '%s' column '%s'",
233+
ar_desc->array_desc_dtype, var->relname, var->sqlname);
234+
efree(ar);
235+
return FAILURE;
236+
} /* switch array_desc_type */
235237

236-
/* calculate elements count */
237-
for (dim = 0; dim < ar_desc->array_desc_dimensions; dim++) {
238-
ar_size *= 1 + ar_desc->array_desc_bounds[dim].array_bound_upper
239-
-ar_desc->array_desc_bounds[dim].array_bound_lower;
240-
}
241-
a->ar_size = a->el_size * ar_size;
242-
} /* if SQL_ARRAY */
238+
/* calculate elements count */
239+
for (dim = 0; dim < ar_desc->array_desc_dimensions; dim++) {
240+
ar_size *= 1 + ar_desc->array_desc_bounds[dim].array_bound_upper
241+
-ar_desc->array_desc_bounds[dim].array_bound_lower;
242+
}
243+
a->ar_size = a->el_size * ar_size;
243244
} /* for column */
244245
*ib_arrayp = ar;
245246
return SUCCESS;

0 commit comments

Comments
 (0)