mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Sort nulls consistently
PostgreSQL normally sorts nulls after everything else in ascending order and vice versa; we reverse this, to match SQLIte and MySQL
This commit is contained in:
parent
9d7ada7f59
commit
ed27e0aaaa
5 changed files with 14 additions and 0 deletions
|
@ -75,6 +75,8 @@ interface Driver {
|
||||||
* - "nocase": the name of a general-purpose case-insensitive collation sequence
|
* - "nocase": the name of a general-purpose case-insensitive collation sequence
|
||||||
* - "like": the case-insensitive LIKE operator
|
* - "like": the case-insensitive LIKE operator
|
||||||
* - "integer": the integer type to use for explicit casts
|
* - "integer": the integer type to use for explicit casts
|
||||||
|
* - "asc": ascending sort order
|
||||||
|
* - "desc": descending sort order
|
||||||
*/
|
*/
|
||||||
public function sqlToken(string $token): string;
|
public function sqlToken(string $token): string;
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
|
||||||
return '"utf8mb4_unicode_ci"';
|
return '"utf8mb4_unicode_ci"';
|
||||||
case "integer":
|
case "integer":
|
||||||
return "signed integer";
|
return "signed integer";
|
||||||
|
case "asc":
|
||||||
|
return "";
|
||||||
default:
|
default:
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,10 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
|
||||||
return '"und-x-icu"';
|
return '"und-x-icu"';
|
||||||
case "like":
|
case "like":
|
||||||
return "ilike";
|
return "ilike";
|
||||||
|
case "asc":
|
||||||
|
return "nulls first";
|
||||||
|
case "desc":
|
||||||
|
return "desc nulls last";
|
||||||
default:
|
default:
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
|
||||||
switch (strtolower($token)) {
|
switch (strtolower($token)) {
|
||||||
case "greatest":
|
case "greatest":
|
||||||
return "max";
|
return "max";
|
||||||
|
case "asc":
|
||||||
|
return "";
|
||||||
default:
|
default:
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,6 +385,8 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$nocase = $this->drv->sqlToken("noCASE");
|
$nocase = $this->drv->sqlToken("noCASE");
|
||||||
$like = $this->drv->sqlToken("liKe");
|
$like = $this->drv->sqlToken("liKe");
|
||||||
$integer = $this->drv->sqlToken("InTEGer");
|
$integer = $this->drv->sqlToken("InTEGer");
|
||||||
|
$asc = $this->drv->sqlToken("asc");
|
||||||
|
$desc = $this->drv->sqlToken("desc");
|
||||||
|
|
||||||
$this->assertSame("NOT_A_TOKEN", $this->drv->sqlToken("NOT_A_TOKEN"));
|
$this->assertSame("NOT_A_TOKEN", $this->drv->sqlToken("NOT_A_TOKEN"));
|
||||||
|
|
||||||
|
@ -392,5 +394,7 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->assertSame("Z", $this->drv->query("SELECT 'Z' collate $nocase")->getValue());
|
$this->assertSame("Z", $this->drv->query("SELECT 'Z' collate $nocase")->getValue());
|
||||||
$this->assertSame("Z", $this->drv->query("SELECT 'Z' where 'Z' $like 'z'")->getValue());
|
$this->assertSame("Z", $this->drv->query("SELECT 'Z' where 'Z' $like 'z'")->getValue());
|
||||||
$this->assertEquals(1, $this->drv->query("SELECT CAST((1=1) as $integer)")->getValue());
|
$this->assertEquals(1, $this->drv->query("SELECT CAST((1=1) as $integer)")->getValue());
|
||||||
|
$this->assertEquals([null, 1], array_column($this->drv->query("SELECT 1 as t union select null as t order by t $asc")->getAll(), "t"));
|
||||||
|
$this->assertEquals([1, null], array_column($this->drv->query("SELECT 1 as t union select null as t order by t $desc")->getAll(), "t"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue