Skip to content

Commit

Permalink
Merge pull request #24 from andela-iadeniyi/1.0.0
Browse files Browse the repository at this point in the history
Update the where clause
  • Loading branch information
Adeniyi Ibraheem committed Mar 7, 2016
2 parents 62fed00 + 1ae5876 commit edf4b9e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Database/DatabaseQuery.php
Expand Up @@ -228,7 +228,7 @@ public static function whereAndClause($tableName, $data, $condition)
*
* @return string
*/
public static function selectQuery($tableName, $data, $condition, $connection)
public static function selectQuery($tableName, $fields, $data, $condition, $connection)
{
$query = "";
try
Expand All @@ -241,7 +241,7 @@ public static function selectQuery($tableName, $data, $condition, $connection)
else
{
$columnName = self::whereAndClause($tableName, $data, $condition);
$query = "SELECT * FROM $tableName WHERE $columnName";
$query = "SELECT $fields FROM $tableName WHERE $columnName";
}
} catch ( PDOException $e ) {
$query = $e->getMessage();
Expand Down
4 changes: 2 additions & 2 deletions src/Helper/Model.php
Expand Up @@ -134,7 +134,7 @@ public function where($data, $condition = NULL, $dbConnection = NULL)
$databaseQuery = new DatabaseQuery();
$connection = $databaseQuery->checkConnection($dbConnection);

$sqlQuery = $databaseQuery->selectQuery(self::getTableName($connection), $data, $condition, $connection);
$sqlQuery = $databaseQuery->selectQuery(self::getTableName($connection), self::fields(), $data, $condition, $connection);
$query = $connection->prepare($sqlQuery);
$query->execute();
if ( $query->rowCount() )
Expand All @@ -154,7 +154,7 @@ public static function find($value, $dbConnection = NULL)
{
$connection = DatabaseQuery::checkConnection($dbConnection);

$sqlQuery = DatabaseQuery::selectQuery(self::getTableName($connection), ['id' => $value], NULL, $connection);
$sqlQuery = DatabaseQuery::selectQuery(self::getTableName($connection), self::fields(), ['id' => $value], NULL, $connection);
$query = $connection->prepare($sqlQuery);
$query->execute();
if ( $query->rowCount() )
Expand Down
2 changes: 1 addition & 1 deletion src/Interface/DatabaseQueryInterface.php
Expand Up @@ -15,7 +15,7 @@ public function checkTableExist($table, $con=NULL);

public static function checkTableName($table, $dbConnection=NULL);

public static function selectQuery($tableName, $field, $value, $connection);
public static function selectQuery($tableName, $fields, $data, $condition, $connection);

public static function whereAndClause($tableName, $data, $condition);

Expand Down
2 changes: 1 addition & 1 deletion test/DatabaseQueryTest.php
Expand Up @@ -45,6 +45,6 @@ public function testSelectQuery()
$this->dbConnectionMocked = Mockery::mock('\Ibonly\PotatoORM\DBConfig');
$this->statement = Mockery::mock('\PDOStatement');

$this->assertInternalType("string", $this->databaseQuery->selectQuery('users' , [],NULL, $this->dbConnectionMocked));
$this->assertInternalType("string", $this->databaseQuery->selectQuery('users' , '*', [],NULL, $this->dbConnectionMocked));
}
}

0 comments on commit edf4b9e

Please sign in to comment.