mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-05-15 20:47:33 +08:00
support pg
This commit is contained in:
@@ -164,9 +164,9 @@ class NexusDB
|
||||
if (!IN_NEXUS) {
|
||||
return DB::table($table)->insertGetId($data);
|
||||
}
|
||||
$fields = array_map(function ($value) {return "`$value`";}, array_keys($data));
|
||||
$fields = array_map(function ($value) {return "$value";}, array_keys($data));
|
||||
$values = array_map(function ($value) {return sqlesc($value);}, array_values($data));
|
||||
$sql = sprintf("insert into `%s` (%s) values (%s)", $table, implode(', ', $fields), implode(', ', $values));
|
||||
$sql = sprintf("insert into %s (%s) values (%s)", $table, implode(', ', $fields), implode(', ', $values));
|
||||
sql_query($sql);
|
||||
return mysql_insert_id();
|
||||
}
|
||||
@@ -486,4 +486,24 @@ class NexusDB
|
||||
return $indexesNames;
|
||||
}
|
||||
|
||||
public static function getDatabaseVersionInfo(): array
|
||||
{
|
||||
if (self::isMysql()) {
|
||||
$sql = 'select version() as v';
|
||||
$result = NexusDB::select($sql);
|
||||
$version = $result[0]['v'];
|
||||
$minVersion = '5.7.8';
|
||||
} else if (self::isPgsql()) {
|
||||
$sql = 'SHOW server_version;';
|
||||
$result = NexusDB::select($sql);
|
||||
$version = $result[0]['server_version'];
|
||||
$minVersion = '16.0';
|
||||
} else {
|
||||
throw new \RuntimeException('Not supported database.');
|
||||
}
|
||||
$dbType = self::getConnectionName();
|
||||
$match = version_compare($version, $minVersion, '>=');
|
||||
return compact('version', 'match', 'minVersion', 'dbType');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -384,7 +384,14 @@ JS;
|
||||
$torrentIdArr = [$torrentId];
|
||||
}
|
||||
$torrentIdStr = implode(',', $torrentIdArr);
|
||||
$res = sql_query("select f.*, v.custom_field_value, v.torrent_id from torrents_custom_field_values v inner join torrents_custom_fields f on v.custom_field_id = f.id inner join searchbox box on box.id = $searchBoxId and find_in_set(f.id, box.custom_fields) where torrent_id in ($torrentIdStr) order by f.priority desc");
|
||||
if (NexusDB::isMysql()) {
|
||||
$customFieldStr = "find_in_set(f.id, box.custom_fields)";
|
||||
} elseif (NexusDB::isPgsql()) {
|
||||
$customFieldStr = "f.id = ANY(string_to_array(box.custom_fields, ',')::int[])";
|
||||
} else {
|
||||
throw new \RuntimeException("Not supported database");
|
||||
}
|
||||
$res = sql_query("select f.*, v.custom_field_value, v.torrent_id from torrents_custom_field_values v inner join torrents_custom_fields f on v.custom_field_id = f.id inner join searchbox box on box.id = $searchBoxId and $customFieldStr where torrent_id in ($torrentIdStr) order by f.priority desc");
|
||||
$values = [];
|
||||
$result = [];
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
|
||||
@@ -733,23 +733,7 @@ class Install
|
||||
|
||||
public function getDatabaseVersionInfo(): array
|
||||
{
|
||||
if (NexusDB::isMysql()) {
|
||||
$sql = 'select version() as v';
|
||||
$result = NexusDB::select($sql);
|
||||
$version = $result[0]['v'];
|
||||
$minVersion = '5.7.8';
|
||||
$dbType = "mysql";
|
||||
} else if (NexusDB::isPgsql()) {
|
||||
$sql = 'SHOW server_version;';
|
||||
$result = NexusDB::select($sql);
|
||||
$version = $result[0]['server_version'];
|
||||
$minVersion = '16.0';
|
||||
$dbType = "pgsql";
|
||||
} else {
|
||||
throw new \RuntimeException('Not supported database.');
|
||||
}
|
||||
$match = version_compare($version, $minVersion, '>=');
|
||||
return compact('version', 'match', 'minVersion', 'dbType');
|
||||
return NexusDB::getDatabaseVersionInfo();
|
||||
}
|
||||
|
||||
public function getRedisVersionInfo(): array
|
||||
|
||||
Reference in New Issue
Block a user