This commit is contained in:
joyqi 2021-10-21 11:10:34 +08:00
parent b33a9c4d02
commit c66b6e20ec
11 changed files with 46 additions and 7 deletions

View File

@ -129,6 +129,14 @@ class Db
$this->adapter = new $adapterName();
}
/**
* @return Adapter
*/
public function getAdapter(): Adapter
{
return $this->adapter;
}
/**
* 获取适配器名称
*

View File

@ -37,6 +37,13 @@ interface Adapter
*/
public function getVersion($handle): string;
/**
* 获取数据库类型
*
* @return string
*/
public function getDriver(): string;
/**
* 清空数据表
*

View File

@ -29,4 +29,12 @@ trait MysqlTrait
{
return $this->buildQuery($sql);
}
/**
* @return string
*/
public function getDriver(): string
{
return 'mysql';
}
}

View File

@ -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;
}
/**

View File

@ -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);
}
/**

View File

@ -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'];
}
/**

View File

@ -153,6 +153,14 @@ WHERE
return 0;
}
/**
* @return string
*/
public function getDriver(): string
{
return 'pgsql';
}
abstract public function query(
string $query,
$handle,

View File

@ -57,7 +57,7 @@ class SQLite implements Adapter
*/
public function getVersion($handle): string
{
return 'sqlite:sqlite ' . \SQLite3::version()['versionString'];
return \SQLite3::version()['versionString'];
}
/**

View File

@ -99,4 +99,12 @@ trait SQLiteTrait
return $query;
}
/**
* @return string
*/
public function getDriver(): string
{
return 'sqlite';
}
}

View File

@ -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');
}

View File

@ -4,7 +4,6 @@ namespace Widget;
use Typecho\Config;
use Typecho\Db;
use Typecho\Plugin;
use Typecho\Widget;
if (!defined('__TYPECHO_ROOT_DIR__')) {