Skip to content

Commit 692d283

Browse files
committed
Merge some fixes from Senthil. Some test diffs still remain.
1 parent 7a9764c commit 692d283

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

ext/pdo_oci/oci_statement.c

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ static sb4 oci_bind_input_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, dv
188188
{
189189
struct pdo_bound_param_data *param = (struct pdo_bound_param_data*)ctx;
190190
pdo_oci_bound_param *P = (pdo_oci_bound_param*)param->driver_data;
191+
zval *parameter;
191192

192193
if (!param) {
193194
php_error_docref(NULL, E_WARNING, "param is NULL in oci_bind_input_cb; this should not happen");
@@ -196,19 +197,24 @@ static sb4 oci_bind_input_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, dv
196197

197198
*indpp = &P->indicator;
198199

200+
if (Z_ISREF(param->parameter))
201+
parameter = Z_REFVAL(param->parameter);
202+
else
203+
parameter = &param->parameter;
204+
199205
if (P->thing) {
200206
*bufpp = P->thing;
201207
*alenp = sizeof(void*);
202-
} else if (ZVAL_IS_NULL(&param->parameter)) {
208+
} else if (ZVAL_IS_NULL(parameter)) {
203209
/* insert a NULL value into the column */
204210
P->indicator = -1; /* NULL */
205211
*bufpp = 0;
206212
*alenp = -1;
207213
} else if (!P->thing) {
208214
/* regular string bind */
209-
convert_to_string(&param->parameter);
210-
*bufpp = Z_STRVAL(param->parameter);
211-
*alenp = Z_STRLEN(param->parameter);
215+
convert_to_string(parameter);
216+
*bufpp = Z_STRVAL_P(parameter);
217+
*alenp = Z_STRLEN_P(parameter);
212218
}
213219

214220
*piecep = OCI_ONE_PIECE;
@@ -219,12 +225,18 @@ static sb4 oci_bind_output_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, d
219225
{
220226
struct pdo_bound_param_data *param = (struct pdo_bound_param_data*)ctx;
221227
pdo_oci_bound_param *P = (pdo_oci_bound_param*)param->driver_data;
228+
zval *parameter;
222229

223230
if (!param) {
224231
php_error_docref(NULL, E_WARNING, "param is NULL in oci_bind_output_cb; this should not happen");
225232
return OCI_ERROR;
226233
}
227234

235+
if (Z_ISREF(param->parameter))
236+
parameter = Z_REFVAL(param->parameter);
237+
else
238+
parameter = &param->parameter;
239+
228240
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) {
229241
P->actual_len = sizeof(OCILobLocator*);
230242
*bufpp = P->thing;
@@ -235,20 +247,20 @@ static sb4 oci_bind_output_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, d
235247
return OCI_CONTINUE;
236248
}
237249

238-
if (Z_TYPE(param->parameter) == IS_OBJECT || Z_TYPE(param->parameter) == IS_RESOURCE) {
250+
if (Z_TYPE_P(parameter) == IS_OBJECT || Z_TYPE_P(parameter) == IS_RESOURCE) {
239251
return OCI_CONTINUE;
240252
}
241253

242-
convert_to_string(&param->parameter);
243-
zval_dtor(&param->parameter);
254+
convert_to_string(parameter);
255+
zval_dtor(parameter);
244256

245-
Z_STRLEN(param->parameter) = param->max_value_len;
246-
Z_STR(param->parameter) = ecalloc(1, Z_STRLEN(param->parameter)+1);
257+
Z_STRLEN_P(parameter) = param->max_value_len;
258+
Z_STR_P(parameter) = ecalloc(1, Z_STRLEN_P(parameter)+1);
247259
P->used_for_output = 1;
248260

249-
P->actual_len = Z_STRLEN(param->parameter);
261+
P->actual_len = Z_STRLEN_P(parameter);
250262
*alenpp = &P->actual_len;
251-
*bufpp = Z_STRVAL(param->parameter);
263+
*bufpp = Z_STRVAL_P(parameter);
252264
*piecep = OCI_ONE_PIECE;
253265
*rcodepp = &P->retcode;
254266
*indpp = &P->indicator;
@@ -264,6 +276,12 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
264276
if (param->is_param) {
265277
pdo_oci_bound_param *P;
266278
sb4 value_sz = -1;
279+
zval *parameter;
280+
281+
if (Z_ISREF(param->parameter))
282+
parameter = Z_REFVAL(param->parameter);
283+
else
284+
parameter = &param->parameter;
267285

268286
P = (pdo_oci_bound_param*)param->driver_data;
269287

@@ -343,29 +361,29 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
343361
if (P->used_for_output) {
344362
if (P->indicator == -1) {
345363
/* set up a NULL value */
346-
if (Z_TYPE(param->parameter) == IS_STRING) {
364+
if (Z_TYPE_P(parameter) == IS_STRING) {
347365
/* OCI likes to stick non-terminated strings in things */
348-
*Z_STRVAL(param->parameter) = '\0';
366+
*Z_STRVAL_P(parameter) = '\0';
349367
}
350-
zval_dtor(&param->parameter);
351-
ZVAL_UNDEF(&param->parameter);
352-
} else if (Z_TYPE(param->parameter) == IS_STRING) {
353-
Z_STRLEN(param->parameter) = P->actual_len;
354-
Z_STR(param->parameter) = erealloc(Z_STRVAL(param->parameter), P->actual_len+1);
355-
Z_STRVAL(param->parameter)[P->actual_len] = '\0';
368+
zval_dtor(parameter);
369+
ZVAL_UNDEF(parameter);
370+
} else if (Z_TYPE_P(parameter) == IS_STRING) {
371+
Z_STRLEN_P(parameter) = P->actual_len;
372+
Z_STR_P(parameter) = erealloc(Z_STRVAL_P(parameter), P->actual_len+1);
373+
Z_STRVAL_P(parameter)[P->actual_len] = '\0';
356374
}
357375
} else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && P->thing) {
358376
php_stream *stm;
359377

360-
if (Z_TYPE(param->parameter) == IS_NULL) {
378+
if (Z_TYPE_P(parameter) == IS_NULL) {
361379
/* if the param is NULL, then we assume that they
362380
* wanted to bind a lob locator into it from the query
363381
* */
364382

365383
stm = oci_create_lob_stream(stmt, (OCILobLocator*)P->thing);
366384
if (stm) {
367385
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE);
368-
php_stream_to_zval(stm, &param->parameter);
386+
php_stream_to_zval(stm, parameter);
369387
P->thing = NULL;
370388
}
371389
} else {
@@ -374,7 +392,7 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
374392
ub4 amt, offset = 1;
375393
char *consume;
376394

377-
php_stream_from_zval_no_verify(stm, &param->parameter);
395+
php_stream_from_zval_no_verify(stm, parameter);
378396
if (stm) {
379397
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE);
380398
do {
@@ -397,10 +415,10 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
397415
} while (1);
398416
OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing);
399417
OCILobFlushBuffer(S->H->svc, S->err, (OCILobLocator*)P->thing, 0);
400-
} else if (Z_TYPE(param->parameter) == IS_STRING) {
418+
} else if (Z_TYPE_P(parameter) == IS_STRING) {
401419
/* stick the string into the LOB */
402-
consume = Z_STRVAL(param->parameter);
403-
n = Z_STRLEN(param->parameter);
420+
consume = Z_STRVAL_P(parameter);
421+
n = Z_STRLEN_P(parameter);
404422
if (n) {
405423
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE);
406424
while (n) {
@@ -651,7 +669,7 @@ static int oci_blob_close(php_stream *stream, int close_handle)
651669
efree(self);
652670
}
653671

654-
php_pdo_free_statement(stmt);
672+
/* php_pdo_free_statement(stmt); */
655673
return 0;
656674
}
657675

0 commit comments

Comments
 (0)