mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
add db::ciEquals()
This commit is contained in:
parent
b3e640a1f7
commit
476ccc99ff
6 changed files with 29 additions and 1 deletions
|
|
@ -178,6 +178,12 @@ class Database_Mysql extends Database_Abstract
|
|||
return '`'. $column. '` LIKE '. $this->quoteForLike($format, $string);
|
||||
}
|
||||
|
||||
function ciEquals(string $column, string $value): string
|
||||
{
|
||||
$column = str_replace('`', '``', $column);
|
||||
return 'LOWER(`'. $column. '`) = LOWER('. $this->quote($value). ')';
|
||||
}
|
||||
|
||||
function lastInsertId(?string $name = null): ?string
|
||||
{
|
||||
$ret = $this->dbh->lastInsertId();
|
||||
|
|
|
|||
|
|
@ -151,6 +151,12 @@ class Database_Mysqli extends Database_Abstract
|
|||
return '`'. $column. '` LIKE '. $this->quoteForLike($format, $string);
|
||||
}
|
||||
|
||||
function ciEquals(string $column, string $value): string
|
||||
{
|
||||
$column = str_replace('`', '``', $column);
|
||||
return 'LOWER(`'. $column. '`) = LOWER('. $this->quote($value). ')';
|
||||
}
|
||||
|
||||
function tableExists(string $table): bool
|
||||
{
|
||||
$r = $this->sq("SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?",
|
||||
|
|
|
|||
|
|
@ -181,6 +181,12 @@ class Database_Postgres extends Database_Abstract
|
|||
return '"'. $column. '" ILIKE '. $this->quoteForLike($format, $string);
|
||||
}
|
||||
|
||||
function ciEquals(string $column, string $value): string
|
||||
{
|
||||
$column = str_replace('"', '""', $column);
|
||||
return 'LOWER("'. $column. '") = LOWER('. $this->quote($value). ')';
|
||||
}
|
||||
|
||||
function lastInsertId(?string $name = null): ?string
|
||||
{
|
||||
$ret = $this->dbh->lastInsertId();
|
||||
|
|
|
|||
|
|
@ -188,6 +188,15 @@ class Database_Sqlite3 extends Database_Abstract
|
|||
return 'utf8_lower("'. $column. '") LIKE '. $this->quoteForLike($format, $this->utf8_lower($string));
|
||||
}
|
||||
|
||||
function ciEquals(string $column, string $value): string
|
||||
{
|
||||
$column = str_replace('"', '""', $column);
|
||||
if ($this->useNormalizedUtf8) {
|
||||
return 'utf8_normalized_lower("'. $column. '") = '. $this->quote($this->utf8_normalized_lower($value));
|
||||
}
|
||||
return 'utf8_lower("'. $column. '") = '. $this->quote($this->utf8_lower($value));
|
||||
}
|
||||
|
||||
function lastInsertId(?string $name = null): ?string
|
||||
{
|
||||
$ret = $this->dbh->lastInsertId();
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ abstract class Database_Abstract
|
|||
abstract function quote($value): string;
|
||||
abstract function quoteForLike(string $format, string $string): string;
|
||||
abstract function like(string $column, string $format, string $string): string;
|
||||
abstract function ciEquals(string $column, string $value): string;
|
||||
abstract function lastInsertId(?string $name = null): ?string;
|
||||
abstract function tableExists(string $table): bool;
|
||||
abstract function tableFieldExists(string $table, string $field): bool;
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ class DBCore
|
|||
function getTagIdsByName(string $name): array
|
||||
{
|
||||
$db = DBConnection::instance();
|
||||
$q = $db->dq("SELECT id FROM {$db->prefix}tags WHERE ". $db->like('name', '%s', $name));
|
||||
$q = $db->dq("SELECT id FROM {$db->prefix}tags WHERE ". $db->ciEquals('name', $name));
|
||||
$a = [];
|
||||
while ($r = $q->fetchAssoc()) {
|
||||
$a[] = (int) $r['id'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue