Merge pull request #3463 from kobmaki/feature/Allow-to-interface-with-sqlite-databases-3381

Support SQLite resources
This commit is contained in:
Eric Lippmann 2018-06-28 11:42:00 +02:00 committed by GitHub
commit 966148e8f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 122 additions and 93 deletions

View File

@ -45,17 +45,17 @@ 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;
$offerMysql = false; $offerMysql = false;
$dbChoice = isset($formData['db']) ? $formData['db'] : key($dbChoices); $dbChoice = isset($formData['db']) ? $formData['db'] : key($dbChoices);
if ($dbChoice === 'pgsql') { if ($dbChoice === 'pgsql') {
$offerPostgres = true; $offerPostgres = true;
} elseif ($dbChoice === 'mysql') { } elseif ($dbChoice === 'mysql') {
$offerMysql = true; $offerMysql = true;
} elseif ($dbChoice === 'ibm') {
$offerIbm = true;
} }
$socketInfo = ''; $socketInfo = '';
@ -89,6 +89,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 +144,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 +213,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',