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()) {
$dbChoices['oci'] = 'Oracle (OCI8)';
}
if (Platform::hasSqliteSupport()) {
$dbChoices['sqlite'] = 'SQLite';
}
$offerPostgres = false;
$offerIbm = false;
$offerMysql = false;
$dbChoice = isset($formData['db']) ? $formData['db'] : key($dbChoices);
if ($dbChoice === 'pgsql') {
$offerPostgres = true;
} elseif ($dbChoice === 'mysql') {
$offerMysql = true;
} elseif ($dbChoice === 'ibm') {
$offerIbm = true;
}
$socketInfo = '';
@ -89,6 +89,17 @@ class DbResourceForm extends Form
'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(
'text',
'host',
@ -133,6 +144,7 @@ class DbResourceForm extends Form
'password',
'password',
array(
'required' => true,
'renderPassword' => true,
'label' => $this->translate('Password'),
'description' => $this->translate('The password to use for authentication')
@ -201,6 +213,7 @@ class DbResourceForm extends Form
)
);
}
}
return $this;
}

View File

@ -420,4 +420,16 @@ class Platform
{
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';
$defaultPort = 50000;
break;
case 'sqlite':
$adapter = 'Pdo_Sqlite';
$defaultPort = 0; // Dummy port because a value is required
break;
default:
throw new ConfigurationError(
'Backend "%s" is not supported',