diff --git a/var/Typecho/Db.php b/var/Typecho/Db.php index aa1ceaea..547d9ccb 100644 --- a/var/Typecho/Db.php +++ b/var/Typecho/Db.php @@ -129,6 +129,14 @@ class Db $this->adapter = new $adapterName(); } + /** + * @return Adapter + */ + public function getAdapter(): Adapter + { + return $this->adapter; + } + /** * 获取适配器名称 * diff --git a/var/Typecho/Db/Adapter.php b/var/Typecho/Db/Adapter.php index 907b766c..6ab95e7b 100644 --- a/var/Typecho/Db/Adapter.php +++ b/var/Typecho/Db/Adapter.php @@ -37,6 +37,13 @@ interface Adapter */ public function getVersion($handle): string; + /** + * 获取数据库类型 + * + * @return string + */ + public function getDriver(): string; + /** * 清空数据表 * diff --git a/var/Typecho/Db/Adapter/MysqlTrait.php b/var/Typecho/Db/Adapter/MysqlTrait.php index a71ed3c1..5b123615 100644 --- a/var/Typecho/Db/Adapter/MysqlTrait.php +++ b/var/Typecho/Db/Adapter/MysqlTrait.php @@ -29,4 +29,12 @@ trait MysqlTrait { return $this->buildQuery($sql); } + + /** + * @return string + */ + public function getDriver(): string + { + return 'mysql'; + } } diff --git a/var/Typecho/Db/Adapter/Mysqli.php b/var/Typecho/Db/Adapter/Mysqli.php index 8754e910..c2121955 100644 --- a/var/Typecho/Db/Adapter/Mysqli.php +++ b/var/Typecho/Db/Adapter/Mysqli.php @@ -75,7 +75,7 @@ class Mysqli implements Adapter */ public function getVersion($handle): string { - return 'mysqli:mysql ' . $this->dbLink->server_version; + return $this->dbLink->server_version; } /** diff --git a/var/Typecho/Db/Adapter/Pdo.php b/var/Typecho/Db/Adapter/Pdo.php index 4f957982..3041c55c 100644 --- a/var/Typecho/Db/Adapter/Pdo.php +++ b/var/Typecho/Db/Adapter/Pdo.php @@ -81,8 +81,7 @@ abstract class Pdo implements Adapter */ public function getVersion($handle): string { - return 'pdo:' . $handle->getAttribute(\PDO::ATTR_DRIVER_NAME) - . ' ' . $handle->getAttribute(\PDO::ATTR_SERVER_VERSION); + return $handle->getAttribute(\PDO::ATTR_SERVER_VERSION); } /** diff --git a/var/Typecho/Db/Adapter/Pgsql.php b/var/Typecho/Db/Adapter/Pgsql.php index 66c885c3..c97d488f 100644 --- a/var/Typecho/Db/Adapter/Pgsql.php +++ b/var/Typecho/Db/Adapter/Pgsql.php @@ -63,7 +63,7 @@ class Pgsql implements Adapter public function getVersion($handle): string { $version = pg_version($handle); - return 'pgsql:pgsql ' . $version['server']; + return $version['server']; } /** diff --git a/var/Typecho/Db/Adapter/PgsqlTrait.php b/var/Typecho/Db/Adapter/PgsqlTrait.php index 1dbb03f6..21048eba 100644 --- a/var/Typecho/Db/Adapter/PgsqlTrait.php +++ b/var/Typecho/Db/Adapter/PgsqlTrait.php @@ -153,6 +153,14 @@ WHERE return 0; } + /** + * @return string + */ + public function getDriver(): string + { + return 'pgsql'; + } + abstract public function query( string $query, $handle, diff --git a/var/Typecho/Db/Adapter/SQLite.php b/var/Typecho/Db/Adapter/SQLite.php index cc83a2d5..dd4b071f 100644 --- a/var/Typecho/Db/Adapter/SQLite.php +++ b/var/Typecho/Db/Adapter/SQLite.php @@ -57,7 +57,7 @@ class SQLite implements Adapter */ public function getVersion($handle): string { - return 'sqlite:sqlite ' . \SQLite3::version()['versionString']; + return \SQLite3::version()['versionString']; } /** diff --git a/var/Typecho/Db/Adapter/SQLiteTrait.php b/var/Typecho/Db/Adapter/SQLiteTrait.php index 7a1aa1b4..a2e42f90 100644 --- a/var/Typecho/Db/Adapter/SQLiteTrait.php +++ b/var/Typecho/Db/Adapter/SQLiteTrait.php @@ -99,4 +99,12 @@ trait SQLiteTrait return $query; } + + /** + * @return string + */ + public function getDriver(): string + { + return 'sqlite'; + } } diff --git a/var/Widget/Archive.php b/var/Widget/Archive.php index 90d699fb..b4feb260 100644 --- a/var/Widget/Archive.php +++ b/var/Widget/Archive.php @@ -2175,7 +2175,9 @@ class Archive extends Contents $select->where("table.contents.password IS NULL OR table.contents.password = ''"); } - $select->where('table.contents.title LIKE ? OR table.contents.text LIKE ?', $searchQuery, $searchQuery) + $op = $this->db->getAdapter()->getDriver() == 'pgsql' ? 'ILIKE' : 'LIKE'; + + $select->where("table.contents.title {$op} ? OR table.contents.text {$op} ?", $searchQuery, $searchQuery) ->where('table.contents.type = ?', 'post'); } diff --git a/var/Widget/Base.php b/var/Widget/Base.php index d843654d..e28be21f 100644 --- a/var/Widget/Base.php +++ b/var/Widget/Base.php @@ -4,7 +4,6 @@ namespace Widget; use Typecho\Config; use Typecho\Db; -use Typecho\Plugin; use Typecho\Widget; if (!defined('__TYPECHO_ROOT_DIR__')) {