mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Use cases rather than casting bools to int in SQL
This commit is contained in:
parent
d54733ad98
commit
d1da6fbe5e
3 changed files with 5 additions and 13 deletions
|
@ -814,7 +814,6 @@ class Database {
|
||||||
// validate inputs
|
// validate inputs
|
||||||
$folder = $this->folderValidateId($user, $folder)['id'];
|
$folder = $this->folderValidateId($user, $folder)['id'];
|
||||||
// create a complex query
|
// create a complex query
|
||||||
$integer = $this->db->sqlToken("integer");
|
|
||||||
$q = new Query(
|
$q = new Query(
|
||||||
"WITH RECURSIVE
|
"WITH RECURSIVE
|
||||||
topmost(f_id, top) as (
|
topmost(f_id, top) as (
|
||||||
|
@ -853,7 +852,7 @@ class Database {
|
||||||
select
|
select
|
||||||
subscription,
|
subscription,
|
||||||
sum(hidden) as hidden,
|
sum(hidden) as hidden,
|
||||||
sum(cast((\"read\" = 1 and hidden = 0) as $integer)) as marked
|
sum(case when \"read\" = 1 and hidden = 0 then 1 else 0 end) as marked
|
||||||
from arsse_marks group by subscription
|
from arsse_marks group by subscription
|
||||||
) as mark_stats on mark_stats.subscription = s.id",
|
) as mark_stats on mark_stats.subscription = s.id",
|
||||||
["str", "int"],
|
["str", "int"],
|
||||||
|
@ -2053,7 +2052,6 @@ class Database {
|
||||||
|
|
||||||
/** Deletes from the database articles which are beyond the configured clean-up threshold */
|
/** Deletes from the database articles which are beyond the configured clean-up threshold */
|
||||||
public function articleCleanup(): bool {
|
public function articleCleanup(): bool {
|
||||||
$integer = $this->db->sqlToken("integer");
|
|
||||||
$query = $this->db->prepareArray(
|
$query = $this->db->prepareArray(
|
||||||
"WITH RECURSIVE
|
"WITH RECURSIVE
|
||||||
exempt_articles as (
|
exempt_articles as (
|
||||||
|
@ -2079,8 +2077,8 @@ class Database {
|
||||||
left join (
|
left join (
|
||||||
select
|
select
|
||||||
article,
|
article,
|
||||||
sum(cast((starred = 1 and hidden = 0) as $integer)) as starred,
|
sum(case when starred = 1 and hidden = 0 then 1 else 0 end) as starred,
|
||||||
sum(cast((\"read\" = 1 or hidden = 1) as $integer)) as \"read\",
|
sum(case when \"read\" = 1 or hidden = 1 then 1 else 0 end) as \"read\",
|
||||||
max(arsse_marks.modified) as marked_date
|
max(arsse_marks.modified) as marked_date
|
||||||
from arsse_marks
|
from arsse_marks
|
||||||
group by article
|
group by article
|
||||||
|
@ -2211,7 +2209,6 @@ class Database {
|
||||||
* @param boolean $includeEmpty Whether to include (true) or supress (false) labels which have no articles assigned to them
|
* @param boolean $includeEmpty Whether to include (true) or supress (false) labels which have no articles assigned to them
|
||||||
*/
|
*/
|
||||||
public function labelList(string $user, bool $includeEmpty = true): Db\Result {
|
public function labelList(string $user, bool $includeEmpty = true): Db\Result {
|
||||||
$integer = $this->db->sqlToken("integer");
|
|
||||||
return $this->db->prepareArray(
|
return $this->db->prepareArray(
|
||||||
"SELECT * FROM (
|
"SELECT * FROM (
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -2227,7 +2224,7 @@ class Database {
|
||||||
SELECT
|
SELECT
|
||||||
label,
|
label,
|
||||||
sum(hidden) as hidden,
|
sum(hidden) as hidden,
|
||||||
sum(cast((\"read\" = 1 and hidden = 0) as $integer)) as marked
|
sum(case when \"read\" = 1 and hidden = 0 then 1 else 0 end) as marked
|
||||||
from arsse_marks
|
from arsse_marks
|
||||||
join arsse_subscriptions on arsse_subscriptions.id = arsse_marks.subscription
|
join arsse_subscriptions on arsse_subscriptions.id = arsse_marks.subscription
|
||||||
join arsse_label_members on arsse_label_members.article = arsse_marks.article
|
join arsse_label_members on arsse_label_members.article = arsse_marks.article
|
||||||
|
@ -2277,7 +2274,6 @@ class Database {
|
||||||
$this->labelValidateId($user, $id, $byName, false);
|
$this->labelValidateId($user, $id, $byName, false);
|
||||||
$field = $byName ? "name" : "id";
|
$field = $byName ? "name" : "id";
|
||||||
$type = $byName ? "str" : "int";
|
$type = $byName ? "str" : "int";
|
||||||
$integer = $this->db->sqlToken("integer");
|
|
||||||
$out = $this->db->prepareArray(
|
$out = $this->db->prepareArray(
|
||||||
"SELECT
|
"SELECT
|
||||||
id,
|
id,
|
||||||
|
@ -2292,7 +2288,7 @@ class Database {
|
||||||
SELECT
|
SELECT
|
||||||
label,
|
label,
|
||||||
sum(hidden) as hidden,
|
sum(hidden) as hidden,
|
||||||
sum(cast((\"read\" = 1 and hidden = 0) as $integer)) as marked
|
sum(case when \"read\" = 1 and hidden = 0 then 1 else 0 end) as marked
|
||||||
from arsse_marks
|
from arsse_marks
|
||||||
join arsse_subscriptions on arsse_subscriptions.id = arsse_marks.subscription
|
join arsse_subscriptions on arsse_subscriptions.id = arsse_marks.subscription
|
||||||
join arsse_label_members on arsse_label_members.article = arsse_marks.article
|
join arsse_label_members on arsse_label_members.article = arsse_marks.article
|
||||||
|
|
|
@ -81,8 +81,6 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
|
||||||
switch (strtolower($token)) {
|
switch (strtolower($token)) {
|
||||||
case "nocase":
|
case "nocase":
|
||||||
return '"utf8mb4_unicode_ci"';
|
return '"utf8mb4_unicode_ci"';
|
||||||
case "integer":
|
|
||||||
return "signed integer";
|
|
||||||
case "asc":
|
case "asc":
|
||||||
return "";
|
return "";
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -384,7 +384,6 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$greatest = $this->drv->sqlToken("GrEatESt");
|
$greatest = $this->drv->sqlToken("GrEatESt");
|
||||||
$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");
|
|
||||||
$asc = $this->drv->sqlToken("asc");
|
$asc = $this->drv->sqlToken("asc");
|
||||||
$desc = $this->drv->sqlToken("desc");
|
$desc = $this->drv->sqlToken("desc");
|
||||||
$least = $this->drv->sqlToken("leASt");
|
$least = $this->drv->sqlToken("leASt");
|
||||||
|
@ -395,7 +394,6 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->assertSame("Z", $this->drv->query("SELECT $greatest('Z', 'A')")->getValue());
|
$this->assertSame("Z", $this->drv->query("SELECT $greatest('Z', 'A')")->getValue());
|
||||||
$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([null, 1, 2], array_column($this->drv->query("SELECT 1 as t union select null as t union select 2 as t order by t $asc")->getAll(), "t"));
|
$this->assertEquals([null, 1, 2], array_column($this->drv->query("SELECT 1 as t union select null as t union select 2 as t order by t $asc")->getAll(), "t"));
|
||||||
$this->assertEquals([2, 1, null], array_column($this->drv->query("SELECT 1 as t union select null as t union select 2 as t order by t $desc")->getAll(), "t"));
|
$this->assertEquals([2, 1, null], array_column($this->drv->query("SELECT 1 as t union select null as t union select 2 as t order by t $desc")->getAll(), "t"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue