Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["activerecord", "orm"],
"homepage": "http://www.phpactiverecord.org/",
"license": "MIT",
"version": "2.0.0-rc.7",
"version": "2.0.0-rc.8",
"require": {
"php": ">=8.1.0",
"ext-bcmath": "*"
Expand Down
10 changes: 5 additions & 5 deletions lib/WhereClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public function to_s(Connection $connection, string $prependTableName = '', arra
}

$ret = '';
if (1 == count($values) && is_array($values[0])) {
$num_values = count($values[0]);
} else {
$num_values = count($values);
}
$num_values = count($values);
$quotes = 0;

if (1 == $num_values && is_array($values[0]) && 0 == count($values[0])) {
return '1=0';
}

for ($i = 0, $j = 0; $i < strlen($expression); ++$i) {
$ch = $expression[$i];

Expand Down
14 changes: 6 additions & 8 deletions test/ActiveRecordFindTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use ActiveRecord\Exception\DatabaseException;
use ActiveRecord\Exception\RecordNotFound;
use ActiveRecord\Exception\ValidationsArgumentError;
use ActiveRecord\Model;
Expand All @@ -17,6 +16,12 @@ public function testFindWithNoParams()
Author::find();
}

public function testWhereWithEmptyArray()
{
$authors = Author::where(['author_id' => []])->to_a();
$this->assertEquals(0, count($authors));
}

public function testFindWithEmptyArray()
{
$this->expectException(RecordNotFound::class);
Expand Down Expand Up @@ -166,13 +171,6 @@ public function testFindAllWithNoBindValues()
$this->assertEquals(1, $authors[0]->author_id);
}

public function testFindAllWithEmptyArrayBindValueThrowsException()
{
$this->expectException(DatabaseException::class);
$this->expectExceptionMessage('No bound parameter for index 0');
Author::where(['author_id IN(?)', []])->to_a();
}

public function testFindHashUsingAlias()
{
$venues = Venue::where(['marquee' => 'Warner Theatre', 'city' => [
Expand Down
7 changes: 0 additions & 7 deletions test/WhereClauseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use ActiveRecord\ConnectionManager;
use ActiveRecord\Exception\DatabaseException;
use ActiveRecord\WhereClause;
use test\models\Author;

class WhereClauseTest extends DatabaseTestCase
{
Expand Down Expand Up @@ -135,12 +134,6 @@ public function testSubstituteEscapeQuotesWithConnectionsEscapeMethod(): void
$this->assertEquals("name=$escaped", $a->to_s(ConnectionManager::get_connection(), substitute: true));
}

public function testBindInvalidParameterNumberArrayWithIn()
{
$this->expectException(DatabaseException::class);
Author::where(['author_id IN(?)', []])->to_a();
}

public function testSubstituteUsingAlternateValues(): void
{
$a = new WhereClause('name=?', ['Tito']);
Expand Down