Added SQLite3 installed check (#92)

This commit is contained in:
Roman Kelesidis 2023-04-01 00:47:52 +07:00 committed by GitHub
parent 5af4f7f113
commit ebe3e62570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -23,6 +23,11 @@ class cache_sqlite extends cache_common
function cache_sqlite ($cfg, $prefix = null) function cache_sqlite ($cfg, $prefix = null)
{ {
if (!$this->is_installed())
{
die('Error: SQLite3 extension not installed');
}
$this->cfg = array_merge($this->cfg, $cfg); $this->cfg = array_merge($this->cfg, $cfg);
$this->db = new sqlite_common($this->cfg); $this->db = new sqlite_common($this->cfg);
$this->prefix = $prefix; $this->prefix = $prefix;
@ -107,6 +112,11 @@ class cache_sqlite extends cache_common
$result = $this->db->query("DELETE FROM ". $this->cfg['table_name'] ." WHERE cache_expire_time < $expire_time"); $result = $this->db->query("DELETE FROM ". $this->cfg['table_name'] ." WHERE cache_expire_time < $expire_time");
return ($result) ? $this->db->changes() : 0; return ($result) ? $this->db->changes() : 0;
} }
function is_installed ()
{
return class_exists('SQLite3');
}
} }
class sqlite_common extends cache_common class sqlite_common extends cache_common

View File

@ -22,6 +22,11 @@ class datastore_sqlite extends datastore_common
function datastore_sqlite ($cfg, $prefix = null) function datastore_sqlite ($cfg, $prefix = null)
{ {
if (!$this->is_installed())
{
die('Error: SQLite3 extension not installed');
}
$this->cfg = array_merge($this->cfg, $cfg); $this->cfg = array_merge($this->cfg, $cfg);
$this->db = new sqlite_common($this->cfg); $this->db = new sqlite_common($this->cfg);
$this->prefix = $prefix; $this->prefix = $prefix;
@ -63,4 +68,9 @@ class datastore_sqlite extends datastore_common
} }
$this->db->debug('stop'); $this->db->debug('stop');
} }
function is_installed ()
{
return class_exists('SQLite3');
}
} }