aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2012-05-09 12:50:13 +0200
committerAndreas Fischer <bantu@phpbb.com>2012-05-09 12:50:13 +0200
commit12dbcc7f1e13f71b96a5aa31ece4632fb1eb4139 (patch)
treedad98e4d4eeb68c795a3776614173f26daa5ef62
parentc0718fae96a991182f3941dee02599077b5b447d (diff)
parent09d49fb7b2be51a29f5a03c0a1a3816d7e55a466 (diff)
downloadforums-12dbcc7f1e13f71b96a5aa31ece4632fb1eb4139.tar
forums-12dbcc7f1e13f71b96a5aa31ece4632fb1eb4139.tar.gz
forums-12dbcc7f1e13f71b96a5aa31ece4632fb1eb4139.tar.bz2
forums-12dbcc7f1e13f71b96a5aa31ece4632fb1eb4139.tar.xz
forums-12dbcc7f1e13f71b96a5aa31ece4632fb1eb4139.zip
Merge remote-tracking branch 'Noxwizard/ticket/10858' into develop-olympus
* Noxwizard/ticket/10858: [ticket/10858] Move generic row seeking to DBAL [ticket/10858] Tests for row seeking with fetchfield() [ticket/10858] Fix MSSQL Native's row seeking behavior
-rw-r--r--phpBB/includes/db/dbal.php43
-rw-r--r--phpBB/includes/db/firebird.php43
-rw-r--r--phpBB/includes/db/mssql_odbc.php43
-rw-r--r--phpBB/includes/db/mssqlnative.php18
-rw-r--r--tests/dbal/select_test.php26
5 files changed, 69 insertions, 104 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index 5d456c2ff0..358df50402 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -195,6 +195,49 @@ class dbal
}
/**
+ * Seek to given row number
+ * rownum is zero-based
+ */
+ function sql_rowseek($rownum, &$query_id)
+ {
+ global $cache;
+
+ if ($query_id === false)
+ {
+ $query_id = $this->query_result;
+ }
+
+ if (isset($cache->sql_rowset[$query_id]))
+ {
+ return $cache->sql_rowseek($rownum, $query_id);
+ }
+
+ if ($query_id === false)
+ {
+ return false;
+ }
+
+ $this->sql_freeresult($query_id);
+ $query_id = $this->sql_query($this->last_query_text);
+
+ if ($query_id === false)
+ {
+ return false;
+ }
+
+ // We do not fetch the row for rownum == 0 because then the next resultset would be the second row
+ for ($i = 0; $i < $rownum; $i++)
+ {
+ if (!$this->sql_fetchrow($query_id))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Fetch field
* if rownum is false, the current row is used, else it is pointing to the row (zero-based)
*/
diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index 7e3f15ed1d..7072c58ac0 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -360,49 +360,6 @@ class dbal_firebird extends dbal
}
/**
- * Seek to given row number
- * rownum is zero-based
- */
- function sql_rowseek($rownum, &$query_id)
- {
- global $cache;
-
- if ($query_id === false)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_rowseek($rownum, $query_id);
- }
-
- if ($query_id === false)
- {
- return;
- }
-
- $this->sql_freeresult($query_id);
- $query_id = $this->sql_query($this->last_query_text);
-
- if ($query_id === false)
- {
- return false;
- }
-
- // We do not fetch the row for rownum == 0 because then the next resultset would be the second row
- for ($i = 0; $i < $rownum; $i++)
- {
- if (!$this->sql_fetchrow($query_id))
- {
- return false;
- }
- }
-
- return true;
- }
-
- /**
* Get last inserted id after insert statement
*/
function sql_nextid()
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 75a080b1b7..34f7a87337 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -256,49 +256,6 @@ class dbal_mssql_odbc extends dbal
}
/**
- * Seek to given row number
- * rownum is zero-based
- */
- function sql_rowseek($rownum, &$query_id)
- {
- global $cache;
-
- if ($query_id === false)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_rowseek($rownum, $query_id);
- }
-
- if ($query_id === false)
- {
- return false;
- }
-
- $this->sql_freeresult($query_id);
- $query_id = $this->sql_query($this->last_query_text);
-
- if ($query_id === false)
- {
- return false;
- }
-
- // We do not fetch the row for rownum == 0 because then the next resultset would be the second row
- for ($i = 0; $i < $rownum; $i++)
- {
- if (!$this->sql_fetchrow($query_id))
- {
- return false;
- }
- }
-
- return true;
- }
-
- /**
* Get last inserted id after insert statement
*/
function sql_nextid()
diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php
index 7fbc374e77..92ac9b1fb9 100644
--- a/phpBB/includes/db/mssqlnative.php
+++ b/phpBB/includes/db/mssqlnative.php
@@ -440,24 +440,6 @@ class dbal_mssqlnative extends dbal
}
/**
- * Seek to given row number
- * rownum is zero-based
- */
- function sql_rowseek($rownum, &$query_id)
- {
- global $cache;
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_rowseek($rownum, $query_id);
- }
-
- $seek = new result_mssqlnative($query_id);
- $row = $seek->seek($rownum);
- return ($row = $seek->fetch()) ? $row : false;
- }
-
- /**
* Get last inserted id after insert statement
*/
function sql_nextid()
diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php
index 21b12777dc..1b04450fcd 100644
--- a/tests/dbal/select_test.php
+++ b/tests/dbal/select_test.php
@@ -125,6 +125,32 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$this->assertEquals($expected, $ary);
}
+ public static function fetchfield_seek_data()
+ {
+ return array(
+ array(1, 'foobar'),
+ array(0, 'barfoo'),
+ array(2, 'bertie'),
+ );
+ }
+
+ /**
+ * @dataProvider fetchfield_seek_data
+ */
+ public function test_fetchfield_seek($rownum, $expected)
+ {
+ $db = $this->new_dbal();
+
+ $result = $db->sql_query('SELECT username_clean
+ FROM phpbb_users
+ ORDER BY user_id ASC');
+
+ $field = $db->sql_fetchfield('username_clean', $rownum, $result);
+ $db->sql_freeresult($result);
+
+ $this->assertEquals($expected, $field);
+ }
+
public static function query_limit_data()
{
return array(