require_once('common/database/traits/database_action.php');
require_once('common/database/traits/database_name.php');
-require_once('common/database/traits/database_rename_column_to.php');
+require_once('common/database/traits/database_options.php');
+require_once('common/database/traits/database_owner_to.php');
+require_once('common/database/traits/database_rename_column.php');
require_once('common/database/traits/database_rename_to.php');
+require_once('common/database/traits/database_set_schema.php');
+require_once('common/database/traits/database_set_with_oids.php');
/**
* The class for building and returning a Postgresql ALTER FOREIGN TABLE query string.
* @see: https://www.postgresql.org/docs/current/static/sql-alterforeigntable.html
*/
class c_database_alter_foreign_table extends c_database_query {
- protected const pr_QUERY_COMMAND = 'alter foreign table';
use t_database_action;
use t_database_name;
- use t_database_rename_column_to;
+ use t_database_options;
+ use t_database_owner_to;
+ use t_database_rename_column;
use t_database_rename_to;
+ use t_database_set_schema;
+ use t_database_set_with_oids;
+
+ protected const pr_QUERY_COMMAND = 'alter foreign table';
protected $if_exists;
protected $include_descendents; // The '*' following 'name'
protected $only;
-// sub-forms:
-// ADD COLUMN
-// DROP COLUMN
-// SET DATA TYPE
-// SET DEFAULT
-// SET NOT NULL
-// SET STATISTICS
-// SET
-// RESET
-// SET STORAGE
-// ADD ...
-// VALIDATE CONSTRAINT
-// DROP CONSTRAINT
-// DISABLE/ENABLE
-// SET WITH OIDS
-// SET WITHOUT OIDS
-// INHERIT
-// NO INHERIT
-// OWNER
-// OPTIONS
-// RENAME
-// SET SCHEMA
-
/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
- $this->action = NULL;
- $this->name = NULL;
- $this->rename_column_to = NULL;
- $this->rename_to = NULL;
+ $this->action = NULL;
+ $this->name = NULL;
+ $this->options = NULL;
+ $this->owner_to = NULL;
+ $this->rename_column = NULL;
+ $this->rename_to = NULL;
+ $this->set_schema = NULL;
+ $this->set_with_oids = NULL;
$this->if_exists = NULL;
$this->include_descendents = NULL;
unset($this->action);
unset($this->name);
- unset($this->rename_column_to);
+ unset($this->options);
+ unset($this->owner_to);
+ unset($this->rename_column);
unset($this->rename_to);
+ unset($this->set_schema);
+ unset($this->set_with_oids);
unset($this->if_exists);
unset($this->include_descendents);
}
/**
+ * Assigns IF EXISTS.
+ *
+ * @param bool|null $if_exists
+ * Set to TRUE to enable IF EXISTS, FALSE to disable.
+ * Set to NULL to disable.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
+ */
+ public function set_if_exists($if_exists) {
+ if (is_null($if_exists)) {
+ $this->if_exists = NULL;
+ return new c_base_return_true();
+ }
+
+ if (is_bool($if_exists)) {
+ $this->if_exists = $if_exists;
+ return new c_base_return_true();
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'if_exists', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ /**
+ * Assigns wildcard '*' after the table name.
+ *
+ * @param bool|null $include_decendents
+ * Set to TRUE to enable wildcard '*', FALSE to disable.
+ * Set to NULL to disable.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
+ */
+ public function set_include_decendents($include_decendents) {
+ if (is_null($include_decendents)) {
+ $this->include_decendents = NULL;
+ return new c_base_return_true();
+ }
+
+ if (is_bool($include_decendents)) {
+ $this->include_decendents = $include_decendents;
+ return new c_base_return_true();
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'include_decendents', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ /**
+ * Assigns ONLY.
+ *
+ * @param bool|null $only
+ * Set to TRUE to enable ONLY, FALSE to disable.
+ * Set to NULL to disable.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
+ */
+ public function set_only($only) {
+ if (is_null($only)) {
+ $this->only = NULL;
+ return new c_base_return_true();
+ }
+
+ if (is_bool($only)) {
+ $this->only = $only;
+ return new c_base_return_true();
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'only', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ /**
* Implements do_build().
*/
public function do_build() {
$action = ' ' . c_database_string::IF_EXISTS;
}
- if ($this->only) {
- $action = ' ' . c_database_string::ONLY;
+ if (is_array($this->rename_column)) {
+ if ($this->only) {
+ $action .= is_null($action) ? '' : ' ';
+ $action .= c_database_string::ONLY;
+ }
+
+ $action .= ' ' . $this->p_do_build_rename_column();
+ }
+ else if (is_array($this->rename_to)) {
+ $action .= is_null($action) ? '' : ' ';
+ $action .= $this->p_do_build_rename_to();
}
+ else if (is_array($this->set_schema)) {
+ $action .= is_null($action) ? '' : ' ';
+ $action .= $this->p_do_build_set_schema();
+ }
+ else {
+ if ($this->only) {
+ $action .= is_null($action) ? '' : ' ';
+ $action .= c_database_string::ONLY;
+ }
+
+ $action .= is_null($action) ? '' : ' ';
+ // @todo
- // @todo
+// sub-forms:
+// ADD COLUMN
+// DROP COLUMN
+// SET DATA TYPE
+// SET DEFAULT
+// SET NOT NULL
+// SET STATISTICS
+// SET
+// RESET
+// SET STORAGE
+// ADD ...
+// VALIDATE CONSTRAINT
+// DROP CONSTRAINT
+// DISABLE/ENABLE
+// SET WITH OIDS
+// SET WITHOUT OIDS
+// INHERIT
+// NO INHERIT
+// OWNER
+// OPTIONS
+// RENAME
+// SET SCHEMA
+ else if (is_bool($this->set_with_oids)) {
+ $action .= $this->p_do_build_set_with_oids();
+ }
+ else if (is_array($this->inherit)) {
+ $action .= $this->p_do_build_inherit();
+ }
+ else if (is_array($this->owner_to)) {
+ $action .= $this->p_do_build_owner_to();
+ }
+ else if (is_array($this->options)) {
+ $action .= $this->p_do_build_options();
+ }
+ else {
+ unset($action);
+ return new c_base_return_false();
+ }
+ }
$this->value = static::pr_QUERY_COMMAND;
$this->value .= ' ' . $this->name;
$this->value .' *';
}
- $this->value .= $action;
+ $this->value .= ' ' . $action;
unset($action);
return new c_base_return_true();
public const HANDLER = 'handler';
public const IF_EXISTS = 'if exists';
public const IN = 'in';
+ public const INHERIT = 'inherit';
public const INSERT = 'insert';
public const IS_TEMPLATE = 'is_template';
public const LANGUAGE = 'language';
public const MATERIALIZED_VIEW = 'materialized view';
public const NO_HANDLER = 'no handler';
+ public const NO_INHERIT = 'no inherit';
public const NO_VALIDATOR = 'no validator';
public const NOT_NULL = 'not null';
public const NOT_VALID = 'not valid';
public const SET_DEFAULT = 'set default';
public const SET_SCHEMA = 'set schema';
public const SET_TABLESPACE = 'set tablespace';
+ public const SET_WITH_OIDS = 'set with oids';
+ public const SET_WITHOUT_OIDS = 'set without oids';
public const TABLE = 'table';
public const TEXT_SEARCH_CONFIGURATION = 'text search configuration';
public const TEXT_SEARCH_DICTIONARY = 'text search dictionary';
* NULL is returned if there is nothing to process or there is an error.
*/
protected function p_do_build_group_by() {
- //return c_database_string::GROUP_BY . ' (' . $this->group_by . ')';
+ return c_database_string::GROUP_BY . $this->group_by;
}
}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+/**
+ * Provide the sql INHERIT functionality.
+ */
+trait t_database_inherit {
+ protected $inherit;
+
+ /**
+ * Set the INHERIT settings.
+ *
+ * @param string|null $name
+ * The table name to inherit from.
+ * Set to NULL to disable.
+ * @param bool $inherit
+ * Set to TRUE for INHERIT an FALSE for NO INHERIT.
+ * This is ignored when $name is NULL.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_inherit($name, $inherit = TRUE) {
+ if (is_null($name)) {
+ $this->name = NULL;
+ return new c_base_return_true();
+ }
+
+ if (!is_string($name)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'inherit', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->inherit = [
+ 'name' => $name,
+ 'inherit' => $inherit,
+ ];
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned inherit status.
+ *
+ * @return c_base_return_bool|c_base_return_null
+ * TRUE for INHERIT or FALSE for NO INHERIT on success.
+ * NULL is returned if not set.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_inherit() {
+ if (is_null($this->inherit)) {
+ return new c_base_return_null();
+ }
+
+ if (is_bool($this->inherit['inherit'])) {
+ return c_base_return_bool::s_new($this->inherit['inherit']);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'inherit[inherit]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Get the currently assigned name to inherit from.
+ *
+ * @return c_base_return_string|c_base_return_null
+ * A name on success.
+ * NULL is returned if not set.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_inherit_name() {
+ if (is_null($this->inherit)) {
+ return new c_base_return_null();
+ }
+
+ if (is_string($this->inherit['name'])) {
+ return c_base_return_string::s_new($this->inherit['name']);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'inherit[name]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_inherit() {
+ $value = $this->inherit['inherit'] ? c_database_string::INHERIT : c_database_string::NO_INHERIT;
+ $value .= ' ' . $this->inherit['name'];
+ return $value;
+ }
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+/**
+ * Provide the sql SET WITH OIDS functionality.
+ */
+trait t_database_set_with_oids {
+ protected $set_with_oids;
+
+ /**
+ * Set the SET WITH OIDS value.
+ *
+ * @param bool|null $set_with_oids
+ * Set to TRUE for SET WITH OIDS an FALSE for SET WITHOUT OIDS.
+ * Set to NULL to disable.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_set_with_oids($set_with_oids) {
+ if (is_null($set_with_oids)) {
+ $this->set_with_oids = NULL;
+ return new c_base_return_true();
+ }
+
+ if (!is_bool($set_with_oids)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'set_with_oids', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->set_with_oids = $set_with_oids;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned set with oids status.
+ *
+ * @return c_base_return_bool|c_base_return_null
+ * TRUE for SET WITH OIDS or FALSE for SET WITHOUT OIDS on success.
+ * NULL is returned if not set.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_set_with_oids() {
+ if (is_null($this->set_with_oids)) {
+ return new c_base_return_null();
+ }
+
+ if (is_bool($this->set_with_oids)) {
+ return c_base_return_bool::s_new($this->set_with_oids);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_with_oids', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_set_with_oids() {
+ return $this->set_with_oids ? c_database_string::SET_WITH_OIDS : c_database_string::SET_WITHOUT_OIDS;
+ }
+}