Преглед изворни кода

Added result_count method to SQL plugin.

Taddeus Kroes пре 14 година
родитељ
комит
72b6e45659
2 измењених фајлова са 22 додато и 2 уклоњено
  1. 14 0
      pquery.sql.php
  2. 8 2
      test/test_sql.php

+ 14 - 0
pquery.sql.php

@@ -140,6 +140,20 @@ class pQuerySql extends pQuery implements pQueryExtension {
 		return $this;
 	}
 	
+	/**
+	 * Find the number of resulting rows of the current query.
+	 * 
+	 * @returns int The number of rows.
+	 */
+	function result_count() {
+		$this->assert_execution();
+		
+		if( !$this->result )
+			return 0;
+		
+		return mysql_num_rows($this->result);
+	}
+	
 	/**
 	 * Fetch a row from the current result.
 	 * 

+ 8 - 2
test/test_sql.php

@@ -53,8 +53,14 @@ class pQuerySqlTest extends UnitTestCase {
 	
 	function test_select_simple() {
 		$sql = _sql("select bar from foo where id = 1");
-		$results = $sql->fetch_all('object');
-		$this->assertEqual($results[0]->bar, 'test1');
+		$result = $sql->fetch('object');
+		$this->assertEqual($result->bar, 'test1');
+		$this->assertIdentical($sql->fetch(), false);
+	}
+	
+	function test_result_count() {
+		$sql = _sql("select bar from foo where id in (1, 2)");
+		$this->assertEqual($sql->result_count(), 2);
 	}
 }