Skip to content

Commit 0a00159

Browse files
ext/pdo_pgsql: Move option handling before the cursor name allocation
1 parent ff4e854 commit 0a00159

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

‎ext/pdo_pgsql/pgsql_driver.c‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -297,31 +297,6 @@ static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *
297297
scrollable = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR,
298298
PDO_CURSOR_FWDONLY) == PDO_CURSOR_SCROLL;
299299

300-
if (scrollable) {
301-
if (S->cursor_name) {
302-
efree(S->cursor_name);
303-
}
304-
spprintf(&S->cursor_name, 0, "pdo_crsr_%08x", ++H->stmt_counter);
305-
emulate = 1;
306-
} else if (driver_options) {
307-
if (pdo_attr_lval(driver_options, PDO_ATTR_EMULATE_PREPARES, H->emulate_prepares) == 1) {
308-
emulate = 1;
309-
}
310-
if (pdo_attr_lval(driver_options, PDO_PGSQL_ATTR_DISABLE_PREPARES, H->disable_prepares) == 1) {
311-
execute_only = 1;
312-
}
313-
} else {
314-
emulate = H->emulate_prepares;
315-
execute_only = H->disable_prepares;
316-
}
317-
318-
if (emulate) {
319-
stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
320-
} else {
321-
stmt->supports_placeholders = PDO_PLACEHOLDER_NAMED;
322-
stmt->named_rewrite_template = "$%d";
323-
}
324-
325300
S->is_unbuffered =
326301
driver_options
327302
&& (val = zend_hash_index_find(Z_ARRVAL_P(driver_options), PDO_ATTR_PREFETCH))
@@ -362,6 +337,31 @@ static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *
362337
}
363338
#endif
364339

340+
if (scrollable) {
341+
if (S->cursor_name) {
342+
efree(S->cursor_name);
343+
}
344+
spprintf(&S->cursor_name, 0, "pdo_crsr_%08x", ++H->stmt_counter);
345+
emulate = 1;
346+
} else if (driver_options) {
347+
if (pdo_attr_lval(driver_options, PDO_ATTR_EMULATE_PREPARES, H->emulate_prepares) == 1) {
348+
emulate = 1;
349+
}
350+
if (pdo_attr_lval(driver_options, PDO_PGSQL_ATTR_DISABLE_PREPARES, H->disable_prepares) == 1) {
351+
execute_only = 1;
352+
}
353+
} else {
354+
emulate = H->emulate_prepares;
355+
execute_only = H->disable_prepares;
356+
}
357+
358+
if (emulate) {
359+
stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
360+
} else {
361+
stmt->supports_placeholders = PDO_PLACEHOLDER_NAMED;
362+
stmt->named_rewrite_template = "$%d";
363+
}
364+
365365
ret = pdo_parse_params(stmt, sql, &nsql);
366366

367367
if (ret == -1) {

0 commit comments

Comments
 (0)