-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support added.
- Loading branch information
Showing
3 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
* @author 10 Quality <[email protected]> | ||
* @license MIT | ||
* @package wp-query-builder | ||
* @version 1.0.5.2 | ||
* @version 1.0.6 | ||
*/ | ||
class QueryBuilder | ||
{ | ||
|
@@ -417,6 +417,38 @@ public function count( $column = 1, $bypass_limit = true ) | |
$query = apply_filters( 'query_builder_count_query_' . $this->id, $query ); | ||
return intval( $wpdb->get_var( $query ) ); | ||
} | ||
/** | ||
* Retunrs column results from builder statements. | ||
* @since 1.0.6 | ||
* | ||
* @global object $wpdb | ||
* | ||
* @param int $x Column index number. | ||
* | ||
* @return array | ||
*/ | ||
public function col( $x = 0 ) | ||
{ | ||
global $wpdb; | ||
$this->builder = apply_filters( 'query_builder_col_builder', $this->builder ); | ||
$this->builder = apply_filters( 'query_builder_col_builder_' . $this->id, $this->builder ); | ||
// Build | ||
// Query | ||
$query = ''; | ||
$this->_query_select( $query ); | ||
$this->_query_from( $query ); | ||
$this->_query_join( $query ); | ||
$this->_query_where( $query ); | ||
$this->_query_group( $query ); | ||
$this->_query_having( $query ); | ||
$this->_query_order( $query ); | ||
$this->_query_limit( $query ); | ||
$this->_query_offset( $query ); | ||
// Process | ||
$query = apply_filters( 'query_builder_col_query', $query ); | ||
$query = apply_filters( 'query_builder_col_query_' . $this->id, $query ); | ||
return $wpdb->get_col( $query, $x ); | ||
} | ||
/** | ||
* Builds query's select statement. | ||
* @since 1.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* @author 10 Quality <[email protected]> | ||
* @license MIT | ||
* @package wp-query-builder | ||
* @version 1.0.0 | ||
* @version 1.0.6 | ||
*/ | ||
class QueryBuilderOperationsTest extends PHPUnit_Framework_TestCase | ||
{ | ||
|
@@ -142,4 +142,30 @@ public function testValueY() | |
// Assert dummy results | ||
$this->assertEquals( 2, $var ); | ||
} | ||
/** | ||
* Test query builder | ||
* @since 1.0.6 | ||
*/ | ||
public function testCol() | ||
{ | ||
// Preapre | ||
$builder = QueryBuilder::create( 'test' ); | ||
// Exec | ||
$columns = $builder->col(); | ||
// Assert dummy results | ||
$this->assertEquals( [1,2,3,4], $columns ); | ||
} | ||
/** | ||
* Test query builder | ||
* @since 1.0.6 | ||
*/ | ||
public function testCol2() | ||
{ | ||
// Preapre | ||
$builder = QueryBuilder::create( 'test' ); | ||
// Exec | ||
$columns = $builder->col(1); | ||
// Assert dummy results | ||
$this->assertEquals( ['type','type','type','type'], $columns ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters