Added count_all method to query_builder
This commit is contained in:
parent
49503dfb3d
commit
f7d18b19fd
@ -45,7 +45,7 @@ Create a connection array or object similar to this:
|
|||||||
The parameters required depend on the database.
|
The parameters required depend on the database.
|
||||||
|
|
||||||
### Running Queries
|
### Running Queries
|
||||||
Query uses the same interface as CodeIgniter's [Active Record class](http://codeigniter.com/user_guide/database/active_record.html). However, it does not implement the `count_all_results`, `having`, `or_having`, `insert_batch`, `update_batch`, or `count_all` methods.
|
Query uses the same interface as CodeIgniter's [Active Record class](http://codeigniter.com/user_guide/database/active_record.html). However, it does not implement the `count_all_results`, `having`, `or_having`, `insert_batch`, `update_batch` methods.
|
||||||
|
|
||||||
#### Retrieving Results
|
#### Retrieving Results
|
||||||
|
|
||||||
|
@ -1043,7 +1043,9 @@ class Query_Builder {
|
|||||||
*/
|
*/
|
||||||
public function count_all($table)
|
public function count_all($table)
|
||||||
{
|
{
|
||||||
//@todo Implement count_all
|
$sql = 'SELECT * FROM '.$this->quote_ident($table);
|
||||||
|
$res = $this->query($sql);
|
||||||
|
return count($res->fetchAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -1290,7 +1292,7 @@ class Query_Builder {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// echo $sql . '<br />';
|
//echo $sql . '<br />';
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*
|
*
|
||||||
* PDO-firebird isn't stable, so this is a wrapper of the fbird_ public functions.
|
* PDO-firebird isn't stable, so this is a wrapper of the fbird_ public functions.
|
||||||
*/
|
*/
|
||||||
class firebird extends DB_PDO {
|
class Firebird extends DB_PDO {
|
||||||
|
|
||||||
protected $statement, $statement_link, $trans, $count, $result, $conn;
|
protected $statement, $statement_link, $trans, $count, $result, $conn;
|
||||||
|
|
||||||
@ -33,11 +33,11 @@ class firebird extends DB_PDO {
|
|||||||
$this->conn = fbird_connect($dbpath, $user, $pass, 'utf-8');
|
$this->conn = fbird_connect($dbpath, $user, $pass, 'utf-8');
|
||||||
|
|
||||||
// Throw an exception to make this match other pdo classes
|
// Throw an exception to make this match other pdo classes
|
||||||
/*if ( ! is_resource($this->conn))
|
if ( ! is_resource($this->conn))
|
||||||
{
|
{
|
||||||
throw new PDOException(fbird_errmsg());
|
throw new PDOException(fbird_errmsg());
|
||||||
die();
|
die();
|
||||||
}*/
|
}
|
||||||
|
|
||||||
$class = __CLASS__."_sql";
|
$class = __CLASS__."_sql";
|
||||||
$this->sql = new $class;
|
$this->sql = new $class;
|
||||||
@ -92,8 +92,6 @@ class firebird extends DB_PDO {
|
|||||||
return new FireBird_Result($this->statement_link);
|
return new FireBird_Result($this->statement_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,16 +122,7 @@ class firebird extends DB_PDO {
|
|||||||
*/
|
*/
|
||||||
public function num_rows()
|
public function num_rows()
|
||||||
{
|
{
|
||||||
// @todo: Redo this similar to the codeigniter driver
|
return $this->statement->num_rows();
|
||||||
if(isset($this->result))
|
|
||||||
{
|
|
||||||
return count($this->result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Fetch all the rows for the result
|
|
||||||
$this->result = $this->statement->fetchAll();
|
|
||||||
|
|
||||||
return count($this->result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
@ -135,6 +135,18 @@ class Firebird_Result {
|
|||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of rows for the select query
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function num_rows()
|
||||||
|
{
|
||||||
|
return count($this->fetchAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to emulate PDO->errorInfo / PDOStatement->errorInfo
|
* Method to emulate PDO->errorInfo / PDOStatement->errorInfo
|
||||||
*
|
*
|
||||||
|
@ -71,7 +71,7 @@ class pgSQL extends DB_PDO {
|
|||||||
*/
|
*/
|
||||||
public function num_rows()
|
public function num_rows()
|
||||||
{
|
{
|
||||||
return (isset($this->statement)) ? $this->statement->rowCount : FALSE;
|
return (isset($this->statement)) ? $this->statement->rowCount() : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
@ -139,7 +139,7 @@ SQL;
|
|||||||
*/
|
*/
|
||||||
public function num_rows()
|
public function num_rows()
|
||||||
{
|
{
|
||||||
return (isset($this->statement)) ? $this->statement->rowCount : FALSE;
|
return (isset($this->statement)) ? $this->statement->rowCount() : FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//End of sqlite_driver.php
|
//End of sqlite_driver.php
|
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
abstract class QBTest extends UnitTestCase {
|
abstract class QBTest extends UnitTestCase {
|
||||||
|
|
||||||
|
// ! Get Tests
|
||||||
|
|
||||||
function TestGet()
|
function TestGet()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty($this->db)) return;
|
||||||
@ -44,6 +46,24 @@ abstract class QBTest extends UnitTestCase {
|
|||||||
$this->assertIsA($query, 'PDOStatement');
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TestGetWhere()
|
||||||
|
{
|
||||||
|
if (empty($this->db)) return;
|
||||||
|
|
||||||
|
$query = $this->db->get_where('create_test', array('id !=' => 1), 2, 1);
|
||||||
|
|
||||||
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
|
}
|
||||||
|
|
||||||
|
function TestGetViews()
|
||||||
|
{
|
||||||
|
if (empty($this->db)) return;
|
||||||
|
|
||||||
|
$this->assertTrue(is_array($this->db->get_views()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! Select Tests
|
||||||
|
|
||||||
function TestSelectWhereGet()
|
function TestSelectWhereGet()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty($this->db)) return;
|
||||||
@ -118,15 +138,6 @@ abstract class QBTest extends UnitTestCase {
|
|||||||
$this->assertIsA($query, 'PDOStatement');
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
}
|
}
|
||||||
|
|
||||||
function TestGetWhere()
|
|
||||||
{
|
|
||||||
if (empty($this->db)) return;
|
|
||||||
|
|
||||||
$query = $this->db->get_where('create_test', array('id !=' => 1), 2, 1);
|
|
||||||
|
|
||||||
$this->assertIsA($query, 'PDOStatement');
|
|
||||||
}
|
|
||||||
|
|
||||||
function TestSelectGet()
|
function TestSelectGet()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty($this->db)) return;
|
||||||
@ -162,6 +173,8 @@ abstract class QBTest extends UnitTestCase {
|
|||||||
$this->assertIsA($query, 'PDOStatement');
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ! Query modifier tests
|
||||||
|
|
||||||
function TestOrderBy()
|
function TestOrderBy()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty($this->db)) return;
|
||||||
@ -248,6 +261,8 @@ abstract class QBTest extends UnitTestCase {
|
|||||||
$this->assertIsA($query, 'PDOStatement');
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ! DB update tests
|
||||||
|
|
||||||
function TestInsert()
|
function TestInsert()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty($this->db)) return;
|
||||||
@ -282,12 +297,16 @@ abstract class QBTest extends UnitTestCase {
|
|||||||
$this->assertIsA($query, 'PDOStatement');
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
}
|
}
|
||||||
|
|
||||||
function TestGetViews()
|
// ! Non-data read queries
|
||||||
|
|
||||||
|
function TestCountAll()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty($this->db)) return;
|
||||||
|
$query = $this->db->count_all('create_test');
|
||||||
|
|
||||||
$this->assertTrue(is_array($this->db->get_views()));
|
$this->assertTrue(is_numeric($query));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of db_qb_test.php
|
// End of db_qb_test.php
|
BIN
tests/db_files/FB_TEST_DB.FDB
Executable file → Normal file
BIN
tests/db_files/FB_TEST_DB.FDB
Executable file → Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user