Autocomplete for PostreSQL
This commit is contained in:
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- Column autocomplete for PostgreSQL
|
||||||
|
- Currently supported parameters in README.md
|
||||||
|
|
||||||
## [2.4.0] - 2017-12-26
|
## [2.4.0] - 2017-12-26
|
||||||
### Added
|
### Added
|
||||||
- This CHANGELOG.md file
|
- This CHANGELOG.md file
|
||||||
|
|||||||
38
README.md
38
README.md
@@ -20,7 +20,43 @@ specified user to login into any account. Use supervisor username and target
|
|||||||
username separated by ';' to login as target user using supervisor's password
|
username separated by ';' to login as target user using supervisor's password
|
||||||
(ex. superuser;user).
|
(ex. superuser;user).
|
||||||
|
|
||||||
Credits
|
The column autocomplete works only for MySQL and PostgreSQL database which is used to validate form data.
|
||||||
|
If you use other database use *occ* command to set the application config parameters with domain suffix.
|
||||||
|
|
||||||
|
For example to set 'sql_hostname' parameter in default domain use:
|
||||||
|
|
||||||
|
```occ config:app:set user_sql 'sql_hostname_default' --value='localhost'```
|
||||||
|
|
||||||
|
### Currently supported parameters
|
||||||
|
|
||||||
|
- sql_hostname
|
||||||
|
- sql_username
|
||||||
|
- sql_password
|
||||||
|
- sql_database
|
||||||
|
- sql_table
|
||||||
|
- sql_driver
|
||||||
|
- col_username
|
||||||
|
- col_password
|
||||||
|
- col_active
|
||||||
|
- col_displayname
|
||||||
|
- col_email
|
||||||
|
- col_gethome
|
||||||
|
- set_active_invert
|
||||||
|
- set_supervisor
|
||||||
|
- supervisor
|
||||||
|
- set_allow_pwchange
|
||||||
|
- set_default_domain
|
||||||
|
- set_strip_domain
|
||||||
|
- set_crypt_type
|
||||||
|
- set_mail_sync_mode
|
||||||
|
- set_enable_gethome
|
||||||
|
- set_gethome_mode
|
||||||
|
- set_gethome
|
||||||
|
- sql_group_table
|
||||||
|
- col_group_username
|
||||||
|
- col_group_name
|
||||||
|
|
||||||
|
### Credits
|
||||||
|
|
||||||
* Andreas Boehler for releasing the first version of this application
|
* Andreas Boehler for releasing the first version of this application
|
||||||
* Johan Hendriks provided his user_postfixadmin
|
* Johan Hendriks provided his user_postfixadmin
|
||||||
|
|||||||
@@ -304,35 +304,39 @@ class Helper {
|
|||||||
*/
|
*/
|
||||||
public function verifyTable($parameters, $sql_driver, $table)
|
public function verifyTable($parameters, $sql_driver, $table)
|
||||||
{
|
{
|
||||||
$tables = $this->getTables($parameters, $sql_driver);
|
$tablesWithSchema = $this->getTables($parameters, $sql_driver, true);
|
||||||
return in_array($table, $tables, true);
|
$tablesWithoutSchema = $this->getTables($parameters, $sql_driver, false);
|
||||||
|
return in_array($table, $tablesWithSchema, true) || in_array($table, $tablesWithoutSchema, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a list of tables for the given connection parameters
|
* Retrieve a list of tables for the given connection parameters
|
||||||
* @param array $parameters The connection parameters
|
* @param array $parameters The connection parameters
|
||||||
* @param string $sql_driver The SQL driver to use
|
* @param string $sql_driver The SQL driver to use
|
||||||
* @return array The found tables, empty if an error occured
|
* @param boolean $schema Return table name with schema
|
||||||
|
* @return array The found tables, empty if an error occurred
|
||||||
*/
|
*/
|
||||||
public function getTables($parameters, $sql_driver)
|
public function getTables($parameters, $sql_driver, $schema = true)
|
||||||
{
|
{
|
||||||
$cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig());
|
$cm = new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig());
|
||||||
try {
|
try {
|
||||||
$conn = $cm -> getConnection($sql_driver, $parameters);
|
$conn = $cm -> getConnection($sql_driver, $parameters);
|
||||||
$platform = $conn -> getDatabasePlatform();
|
$platform = $conn -> getDatabasePlatform();
|
||||||
|
|
||||||
$queries = array(
|
$queryTables = $platform->getListTablesSQL();
|
||||||
'Tables_in_'.$parameters['dbname'] => $platform -> getListTablesSQL(),
|
$queryViews = $platform->getListViewsSQL($parameters['dbname']);
|
||||||
'TABLE_NAME' => $platform -> getListViewsSQL($parameters['dbname']));
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
foreach($queries as $field => $query)
|
|
||||||
{
|
$result = $conn->executeQuery($queryTables);
|
||||||
$result = $conn -> executeQuery($query);
|
while ($row = $result->fetch()) {
|
||||||
while($row = $result -> fetch())
|
$name = $this->getTableNameFromRow($sql_driver, $parameters['dbname'], $row, $schema);
|
||||||
{
|
|
||||||
$name = $row[$field];
|
|
||||||
$ret[] = $name;
|
$ret[] = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = $conn->executeQuery($queryViews);
|
||||||
|
while ($row = $result->fetch()) {
|
||||||
|
$name = $this->getViewNameFromRow($sql_driver, $row, $schema);
|
||||||
|
$ret[] = $name;
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
@@ -342,6 +346,53 @@ class Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve table name from database list table SQL
|
||||||
|
* @param string $sql_driver The SQL driver to use
|
||||||
|
* @param string $dbname The database name
|
||||||
|
* @param array $row Query result row
|
||||||
|
* @param boolean $schema Return table name with schema
|
||||||
|
* @return string Table name
|
||||||
|
*/
|
||||||
|
public function getTableNameFromRow($sql_driver, $dbname, $row, $schema)
|
||||||
|
{
|
||||||
|
switch ($sql_driver) {
|
||||||
|
case 'mysql':
|
||||||
|
return $row['Tables_in_' . $dbname];
|
||||||
|
case 'pgsql':
|
||||||
|
if ($schema) {
|
||||||
|
return $row['schema_name'] . '.' . $row['table_name'];
|
||||||
|
} else {
|
||||||
|
return $row['table_name'];
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve view name from database list table SQL
|
||||||
|
* @param string $sql_driver The SQL driver to use
|
||||||
|
* @param array $row Query result row
|
||||||
|
* @param boolean $schema Return table name with schema
|
||||||
|
* @return string Table name
|
||||||
|
*/
|
||||||
|
public function getViewNameFromRow($sql_driver, $row, $schema)
|
||||||
|
{
|
||||||
|
switch ($sql_driver) {
|
||||||
|
case 'mysql':
|
||||||
|
return $row['TABLE_NAME'];
|
||||||
|
case 'pgsql':
|
||||||
|
if ($schema) {
|
||||||
|
return $row['schemaname'] . '.' . $row['viewname'];
|
||||||
|
} else {
|
||||||
|
return $row['viewname'];
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a list of columns for the given connection parameters
|
* Retrieve a list of columns for the given connection parameters
|
||||||
* @param array $parameters The connection parameters
|
* @param array $parameters The connection parameters
|
||||||
@@ -360,7 +411,16 @@ class Helper {
|
|||||||
$ret = array();
|
$ret = array();
|
||||||
while($row = $result -> fetch())
|
while($row = $result -> fetch())
|
||||||
{
|
{
|
||||||
|
switch ($sql_driver) {
|
||||||
|
case 'mysql':
|
||||||
$name = $row['Field'];
|
$name = $row['Field'];
|
||||||
|
break;
|
||||||
|
case 'pgsql':
|
||||||
|
$name = $row['field'];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
$ret[] = $name;
|
$ret[] = $name;
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user