RE: [PECL-DEV] PDO_MySQL contribution

From: Date: Fri, 01 May 2009 20:34:37 +0000
Subject: RE: [PECL-DEV] PDO_MySQL contribution
References: 1 2 3 4  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-6366@lists.php.net to get a copy of this message
--- mysql_statement.orig.c 2008-12-31 09:17:42.000000000 -0200 +++ mysql_statement.c 2009-05-01 17:19:19.000000000 -0300 @@ -14,6 +14,7 @@ +----------------------------------------------------------------------+ | Author: George Schlossnagle <george@omniti.com> | | Wez Furlong <wez@php.net> | + | Contributions by: Sam Shull <sam.shull@jhspecialty.com> | +----------------------------------------------------------------------+ */ @@ -111,7 +112,10 @@ S->result = mysql_stmt_result_metadata(S->stmt); if (S->result) { int calc_max_length = H->buffered && S->max_length == 1; - + + /* cursor scrolling - initialize the current position counter for scrolling cursor */ + S->current_position = 0; + S->fields = mysql_fetch_fields(S->result); if (S->bound_result) { @@ -385,10 +389,15 @@ return 1; } + static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, long offset TSRMLS_DC) { - pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; +/* cursor scrolling */ +long cursor_scroll_row; +enum pdo_cursor_type cursor; + +pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; #if HAVE_MYSQL_STMT_PREPARE int ret; @@ -416,12 +425,54 @@ strcpy(stmt->error_code, "HY000"); return 0; } + + /* cursor scrolling */ + if (S->cursor_attr != PDO_CURSOR_FWDONLY && ori != PDO_FETCH_ORI_NEXT) { + switch (ori) { + case PDO_FETCH_ORI_PRIOR: + if (S->current_position > 0) + { + S->current_position -= 1; + } + mysql_data_seek(S->result, S->current_position); + break; + case PDO_FETCH_ORI_FIRST: + mysql_data_seek(S->result, 0); + S->current_position = 0; + break; + case PDO_FETCH_ORI_LAST: + cursor_scroll_row = mysql_num_rows(S->result); + mysql_data_seek(S->result, (cursor_scroll_row - 1)); + S->current_position = cursor_scroll_row - 1; + break; + case PDO_FETCH_ORI_ABS: + mysql_data_seek(S->result, offset); + S->current_position = offset; + break; + case PDO_FETCH_ORI_REL: + cursor_scroll_row = mysql_num_rows(S->result); + if ((S->current_position + offset) > -1 && (S->current_position + offset) < cursor_scroll_row) + { + S->current_position += offset; + mysql_data_seek(S->result, S->current_position); + } + break; + } + } + if ((S->current_data = mysql_fetch_row(S->result)) == NULL) { if (mysql_errno(S->H->server)) { pdo_mysql_error_stmt(stmt); } return 0; } + + /* + * cursor scrolling + * add this for the PDO_FETCH_ORI_PRIOR + */ + S->current_position += 1; + S->current_lengths = mysql_fetch_lengths(S->result); return 1; } --- mysql_driver.orig.c 2008-12-31 09:17:42.000000000 -0200 +++ mysql_driver.c 2009-05-01 17:24:00.000000000 -0300 @@ -14,6 +14,7 @@ +----------------------------------------------------------------------+ | Author: George Schlossnagle <george@omniti.com> | | Wez Furlong <wez@php.net> | + | Contributions by: Sam Shull <sam.shull@jhspecialty.com> | +----------------------------------------------------------------------+ */ @@ -230,7 +231,7 @@ dbh->alloc_own_columns = 1; S->max_length = pdo_attr_lval(driver_options, PDO_ATTR_MAX_COLUMN_LEN, 0 TSRMLS_CC); - + return 1; fallback: @@ -238,6 +239,9 @@ end: stmt->supports_placeholders = PDO_PLACEHOLDER_NONE; + /* cursor scrolling */ + S->cursor_attr = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, H->cursor_attr TSRMLS_CC); + return 1; } @@ -322,6 +326,12 @@ case PDO_ATTR_EMULATE_PREPARES: ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = Z_BVAL_P(val); return 1; + + /* cursor scrolling */ + case PDO_ATTR_CURSOR: + ((pdo_mysql_db_handle *)dbh->driver_data)->cursor_attr = val->value.lval; + return 1; + default: return 0; } @@ -371,6 +381,11 @@ case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE: ZVAL_LONG(return_value, H->max_buffer_size); return 1; + + /* cursor scrolling */ + case PDO_ATTR_CURSOR: + ZVAL_LONG(return_value, H->cursor_attr); + return 1; default: return 0; @@ -487,6 +502,9 @@ PDO_ATTR_EMULATE_PREPARES, H->emulate_prepare TSRMLS_CC); H->max_buffer_size = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, H->max_buffer_size TSRMLS_CC); + + /* cursor scrolling */ + H->cursor_attr = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL TSRMLS_CC); if (mysql_options(H->server, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout)) { pdo_mysql_error(dbh); --- php_pdo_mysql_int.orig.h 2008-12-31 09:17:42.000000000 -0200 +++ php_pdo_mysql_int.h 2009-05-01 17:19:19.000000000 -0300 @@ -14,6 +14,7 @@ +----------------------------------------------------------------------+ | Author: George Schlossnagle <george@omniti.com> | | Wez Furlong <wez@php.net> | + | Contributions by: Sam Shull <sam.shull@jhspecialty.com> | +----------------------------------------------------------------------+ */ @@ -41,6 +42,9 @@ unsigned _reserved:31; unsigned long max_buffer_size; + /* cursor scrolling */ + enum pdo_cursor_type cursor_attr; + pdo_mysql_error_info einfo; } pdo_mysql_db_handle; @@ -55,6 +59,14 @@ MYSQL_ROW current_data; long *current_lengths; pdo_mysql_error_info einfo; + + /* + cursor scrolling + added for tracking position in the current result + */ + long current_position; + enum pdo_cursor_type cursor_attr; + #if HAVE_MYSQL_STMT_PREPARE MYSQL_STMT *stmt; Sam Shull sam.shull@jhspecialty.com

« previous php.pecl.dev (#6366) next »