Permalink
Browse files

- fix for bug #3146

git-svn-id: http://svn.php.net/repository/pear/packages/MDB/trunk@178945 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 4760a29 commit ea7ed247dce2a683f594645ec7dd2e57aaa3d355 Lukas Smith committed Feb 5, 2005
Showing with 59 additions and 2 deletions.
  1. +1 −1 MDB/ibase.php
  2. +2 −1 MDB/oci8.php
  3. +56 −0 tests/MDB_bugs_testcase.php
View
@@ -829,7 +829,7 @@ function fetchInto($result, $fetchmode=MDB_FETCHMODE_DEFAULT, $rownum=null)
max($this->highest_fetched_row[$result_value],
$this->current_row[$result_value]);
} else {
- ++$this->current_row[$result_value];
+ $this->current_row[$result_value] = $rownum;
}
if (isset($this->results[$result_value][$rownum])
&& $this->results[$result_value][$rownum]
View
@@ -596,6 +596,7 @@ function query($query, $types = NULL)
*/
function _executePreparedQuery($prepared_query, $query)
{
+ $this->last_query = $query;
$first = $this->first_selected_row;
$limit = $this->selected_row_limit;
$this->first_selected_row = $this->selected_row_limit = 0;
@@ -1598,7 +1599,7 @@ function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = NULL)
max($this->highest_fetched_row[$result_value],
$this->current_row[$result_value]);
} else {
- ++$this->current_row[$result_value];
+ $this->current_row[$result_value] = $rownum;
}
if (isset($this->results[$result_value][$rownum])
&& $this->results[$result_value][$rownum]
@@ -122,6 +122,21 @@ function insertTestValues($prepared_query, &$data) {
}
}
+ function verifyFetchedValues(&$result, $rownum, &$data) {
+ $row = $this->db->fetchInto($result, null, $rownum);
+ for ($i = 0; $i < count($this->fields); $i++) {
+ $type = $this->types[$i];
+ if ($this->types[$i] == 'float') {
+ $delta = 0.0000000001;
+ } else {
+ $delta = 0;
+ }
+ $value = $row[$i];
+ $field = $this->fields[$i];
+ $this->assertEquals($data[$field], $value, "the value retrieved for field \"$field\" ($value) using type $type doesn't match what was stored ($data[$field]).", $delta);
+ }
+ }
+
/**
*
*/
@@ -329,6 +344,47 @@ function testBug946() {
$this->db->freeResult($result);
}
+
+ /**
+ * http://pear.php.net/bugs/bug.php?id=3146
+ */
+ function testBug3146() {
+ $data = array();
+ $total_rows = 5;
+
+ $prepared_query = $this->db->prepareQuery('INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->types);
+
+ for ($row = 0; $row < $total_rows; $row++) {
+ $data[$row]['user_name'] = "user_$row";
+ $data[$row]['user_password'] = 'somepassword';
+ $data[$row]['subscribed'] = (boolean)($row % 2);
+ $data[$row]['user_id'] = $row;
+ $data[$row]['quota'] = sprintf("%.2f",strval(1+($row+1)/100));
+ $data[$row]['weight'] = sqrt($row);
+ $data[$row]['access_date'] = MDB_Date::mdbToday();
+ $data[$row]['access_time'] = MDB_Date::mdbTime();
+ $data[$row]['approved'] = MDB_Date::mdbNow();
+
+ $this->insertTestValues($prepared_query, $data[$row]);
+
+ $result = $this->db->executeQuery($prepared_query);
+ if (MDB::isError($result)) {
+ $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage());
+ }
+ }
+ $this->db->freePreparedQuery($prepared_query);
+
+ $result = $this->db->query('SELECT user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved FROM users ORDER BY user_id', $this->types);
+
+ $numrows = $this->db->numRows($result);
+
+ $this->verifyFetchedValues($result, 0, $data[0]);
+ $this->verifyFetchedValues($result, 2, $data[2]);
+ $this->verifyFetchedValues($result, null, $data[3]);
+ $this->verifyFetchedValues($result, 1, $data[1]);
+
+ $this->db->freeResult($result);
+ }
}
?>

0 comments on commit ea7ed24

Please sign in to comment.