Introduce SQLite resource type

refs #3381

Signed-off-by: Eric Lippmann <eric.lippmann@icinga.com>
This commit is contained in:
Uwe Ebel 2018-05-23 19:50:31 +02:00 committed by Eric Lippmann
parent c633c86db7
commit 4b5cf47cce
3 changed files with 122 additions and 90 deletions

View File

@ -45,6 +45,9 @@ class DbResourceForm extends Form
if (Platform::hasOciSupport()) { if (Platform::hasOciSupport()) {
$dbChoices['oci'] = 'Oracle (OCI8)'; $dbChoices['oci'] = 'Oracle (OCI8)';
} }
if (Platform::hasSqliteSupport()) {
$dbChoices['sqlite'] = 'SQLite';
}
$offerPostgres = false; $offerPostgres = false;
$offerIbm = false; $offerIbm = false;
@ -89,6 +92,17 @@ class DbResourceForm extends Form
'multiOptions' => $dbChoices 'multiOptions' => $dbChoices
) )
); );
if ($dbChoice === 'sqlite') {
$this->addElement(
'text',
'dbname',
array(
'required' => true,
'label' => $this->translate('Database Name'),
'description' => $this->translate('The name of the database to use')
)
);
} else {
$this->addElement( $this->addElement(
'text', 'text',
'host', 'host',
@ -133,6 +147,7 @@ class DbResourceForm extends Form
'password', 'password',
'password', 'password',
array( array(
'required' => true,
'renderPassword' => true, 'renderPassword' => true,
'label' => $this->translate('Password'), 'label' => $this->translate('Password'),
'description' => $this->translate('The password to use for authentication') 'description' => $this->translate('The password to use for authentication')
@ -201,6 +216,7 @@ class DbResourceForm extends Form
) )
); );
} }
}
return $this; return $this;
} }

View File

@ -420,4 +420,16 @@ class Platform
{ {
return static::extensionLoaded('pdo_pgsql') && static::classExists('Zend_Db_Adapter_Pdo_Pgsql'); return static::extensionLoaded('pdo_pgsql') && static::classExists('Zend_Db_Adapter_Pdo_Pgsql');
} }
/**
* Return whether it's possible to connect to a SQLite database
*
* Checks whether the sqlite pdo extension has been loaded and the Zend framework adapter for SQLite is available
*
* @return bool
*/
public static function hasSqliteSupport()
{
return static::extensionLoaded('pdo_sqlite') && static::classExists('Zend_Db_Adapter_Pdo_Sqlite');
}
} }

View File

@ -224,6 +224,10 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
$adapter = 'Pdo_Ibm'; $adapter = 'Pdo_Ibm';
$defaultPort = 50000; $defaultPort = 50000;
break; break;
case 'sqlite':
$adapter = 'Pdo_Sqlite';
$defaultPort = 0; // Dummy port because a value is required
break;
default: default:
throw new ConfigurationError( throw new ConfigurationError(
'Backend "%s" is not supported', 'Backend "%s" is not supported',