summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql/pgsql_driver.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2005-01-13 01:59:39 +0000
committerWez Furlong <wez@php.net>2005-01-13 01:59:39 +0000
commitef0de01b62abcaaa72d85c64d27adcbc5945e157 (patch)
tree38fecacaf0b1cc52908d3074f2973c9d8a8da11f /ext/pdo_pgsql/pgsql_driver.c
parent10cba41a70f546316056d2ef27a5509a82c236f9 (diff)
downloadphp-git-ef0de01b62abcaaa72d85c64d27adcbc5945e157.tar.gz
Take a blind stab at implementing scrollable cursors for pgsql.
We allocate a unique cursor name for each statement, so that we don't interfere with other open statement handles on the same dbh. Note, however, that we force a new transaction for each open scrollable cursor (postgres requires cursors to be used inside a transaction). This is okay, except for the case where a scrollable cursor is opened, an update is made and the cursor is closed; closing the cursor commits the transaction that was begun when it was opened. It might well be better to avoid the transaction in PDO and force the user to be aware of the requirements of cursors and explicitly initiate the transaction themselves. This is all untested code; it compiles and looks like it will work, but I encourage someone with a real postgres setup to actually sit down and try to use it.
Diffstat (limited to 'ext/pdo_pgsql/pgsql_driver.c')
-rw-r--r--ext/pdo_pgsql/pgsql_driver.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index c5071e13fa..f0815cbada 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -124,12 +124,30 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
pdo_pgsql_stmt *S = ecalloc(1, sizeof(pdo_pgsql_stmt));
+ int ret = 1;
+ int scrollable;
S->H = H;
stmt->driver_data = S;
stmt->methods = &pgsql_stmt_methods;
-
- return 1;
+
+ scrollable = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR,
+ PDO_CURSOR_FWDONLY TSRMLS_CC) == PDO_CURSOR_SCROLL;
+
+ if (scrollable) {
+ PGresult *res;
+ int ret = 1;
+
+ spprintf(&S->cursor_name, 0, "pdo_pgsql_cursor_%08x", stmt);
+
+ res = PQexec(H->server, "BEGIN");
+ if (PQresultStatus(res) != PGRES_COMMAND_OK) {
+ ret = 0;
+ }
+ PQclear(res);
+ }
+
+ return ret;
}
static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC)