From fb486439debd68f36869aea159ac5f1e385bad48 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 12 Dec 2018 18:28:42 -0600 Subject: [PATCH] Progress: continue development on database abstraction --- .../classes/database_alter_foreign_table.php | 2 +- common/database/classes/database_alter_index.php | 8 +- .../database/classes/database_alter_language.php | 50 +++++- .../classes/database_alter_large_object.php | 28 +++- .../classes/database_alter_materialized_view.php | 168 ++++++++++++++++++++- common/database/classes/database_string.php | 13 +- .../enumerations/database_attribute_option.php | 17 +++ common/database/enumerations/database_cascade.php | 2 +- .../database/enumerations/database_set_storage.php | 19 +++ common/database/enumerations/database_user.php | 1 + common/database/traits/database_add_user.php | 4 - common/database/traits/database_argument_type.php | 4 - common/database/traits/database_cascade.php | 6 +- common/database/traits/database_column_reset.php | 137 +++++++++++++++++ common/database/traits/database_column_set.php | 149 ++++++++++++++++++ .../traits/database_column_set_statistics.php | 94 ++++++++++++ .../traits/database_column_set_storage.php | 115 ++++++++++++++ common/database/traits/database_constraint.php | 4 - .../traits/database_depends_on_extension.php | 4 - common/database/traits/database_enable_trigger.php | 4 - common/database/traits/database_for_role.php | 4 - .../database/traits/database_function_action.php | 4 - .../database/traits/database_grant_option_for.php | 4 - common/database/traits/database_handler.php | 6 +- common/database/traits/database_in_schema.php | 4 - common/database/traits/database_inherit.php | 4 - common/database/traits/database_name.php | 4 - common/database/traits/database_no_wait.php | 4 - common/database/traits/database_oid.php | 80 ++++++++++ common/database/traits/database_on.php | 4 - common/database/traits/database_options.php | 4 - common/database/traits/database_order_by.php | 4 - common/database/traits/database_owned_by.php | 58 +++---- common/database/traits/database_owner_to.php | 4 - common/database/traits/database_privilege.php | 4 - common/database/traits/database_procedural.php | 83 ++++++++++ common/database/traits/database_rename_column.php | 4 - common/database/traits/database_rename_to.php | 4 - common/database/traits/database_reset.php | 4 - .../traits/database_reset_storage_parameter.php | 4 - common/database/traits/database_restrict.php | 4 - .../traits/database_role_specification.php | 4 - common/database/traits/database_set.php | 4 - common/database/traits/database_set_schema.php | 4 - .../traits/database_set_storage_parameter.php | 4 - common/database/traits/database_set_tablespace.php | 4 - common/database/traits/database_set_with_oids.php | 4 - .../traits/database_set_without_cluster.php | 83 ++++++++++ common/database/traits/database_to_role.php | 4 - common/database/traits/database_validator.php | 6 +- .../database/traits/database_with_grant_option.php | 10 +- 51 files changed, 1062 insertions(+), 189 deletions(-) create mode 100644 common/database/enumerations/database_attribute_option.php create mode 100644 common/database/enumerations/database_set_storage.php create mode 100644 common/database/traits/database_column_reset.php create mode 100644 common/database/traits/database_column_set.php create mode 100644 common/database/traits/database_column_set_statistics.php create mode 100644 common/database/traits/database_column_set_storage.php create mode 100644 common/database/traits/database_oid.php create mode 100644 common/database/traits/database_procedural.php create mode 100644 common/database/traits/database_set_without_cluster.php diff --git a/common/database/classes/database_alter_foreign_table.php b/common/database/classes/database_alter_foreign_table.php index 5deb5a9..113beb5 100644 --- a/common/database/classes/database_alter_foreign_table.php +++ b/common/database/classes/database_alter_foreign_table.php @@ -319,7 +319,7 @@ class c_database_alter_foreign_table extends c_database_query { $value .= ' ' . $this->p_do_build_rename_column(); } - else if (is_array($this->rename_to)) { + else if (is_string($this->rename_to)) { $value .= is_null($value) ? '' : ' '; $value .= $this->p_do_build_rename_to(); } diff --git a/common/database/classes/database_alter_index.php b/common/database/classes/database_alter_index.php index 5383ba0..1515804 100644 --- a/common/database/classes/database_alter_index.php +++ b/common/database/classes/database_alter_index.php @@ -33,8 +33,8 @@ class c_database_alter_index extends c_database_query { use t_database_no_wait; use t_database_owned_by; use t_database_rename_to; - use t_database_reset_index_storage_parameter; - use t_database_set_index_storage_parameter; + use t_database_reset_storage_parameter; + use t_database_set_storage_parameter; // @todo: override the storage parameter to limit/restrict parameters to index storage parameters. use t_database_set_tablespace; protected const p_QUERY_COMMAND = 'alter index'; @@ -108,7 +108,7 @@ class c_database_alter_index extends c_database_query { $if_exists = ' ' . $this->p_do_build_if_exists(); } - $value = $this->name; + $value = $this->p_do_build_name(); if (is_string($this->rename_to)) { $value .= ' ' . $this->p_do_build_rename_to(); } @@ -129,7 +129,7 @@ class c_database_alter_index extends c_database_query { $if_exists = NULL; $value = c_database_string::ALL_IN_TABLESPACE . ' ' . $value; - if (is_array($this->owned_by)) { + if (!is_null($this->owned_by)) { $value .= ' ' . $this->p_do_build_owned_by(); } diff --git a/common/database/classes/database_alter_language.php b/common/database/classes/database_alter_language.php index 1cd8887..047981b 100644 --- a/common/database/classes/database_alter_language.php +++ b/common/database/classes/database_alter_language.php @@ -1,7 +1,7 @@ name = NULL; + $this->owner_to = NULL; + $this->procedural = NULL; + $this->rename_to = NULL; } /** * Class destructor. */ public function __destruct() { + unset($this->name); + unset($this->owner_to); + unset($this->procedural); + unset($this->rename_to); + parent::__destruct(); } @@ -63,10 +83,28 @@ class c_database_alter_coalation extends c_database_query { return new c_base_return_false(); } - // @todo + $value = $this->p_do_build_name(); + if (is_string($this->rename_to)) { + $value .= ' ' . $this->p_do_build_rename_to(); + } + else if (is_array($this->owner_to)) { + $value .= ' ' . $this->p_do_build_owner_to(); + } + else { + unset($value); + return new c_base_return_false(); + } + + if (is_bool($this->procedural)) { + $this->value = c_database_string::ALTER . ' ' . $this->p_do_build_procedural() . ' ' . c_database_string::LANGUAGE; + } + else { + $this->value = static::p_QUERY_COMMAND; + } - $this->value = static::p_QUERY_COMMAND; $this->value .= ' ' . $value; unset($value); + + return new c_base_return_true(); } } diff --git a/common/database/classes/database_alter_large_object.php b/common/database/classes/database_alter_large_object.php index 54885a7..ca4171c 100644 --- a/common/database/classes/database_alter_large_object.php +++ b/common/database/classes/database_alter_large_object.php @@ -10,14 +10,19 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); +require_once('common/database/traits/database_oid.php'); +require_once('common/database/traits/database_owner_to.php'); /** - * The class for building and returning a Postgresql ALTER COALATION query string. + * The class for building and returning a Postgresql ALTER LARGE OBJECT query string. * - * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html + * @see: https://www.postgresql.org/docs/current/static/sql-alterlargeobject.html */ -class c_database_alter_coalation extends c_database_query { - protected const p_QUERY_COMMAND = 'alter coalation'; +class c_database_alter_large_object extends c_database_query { + use t_database_oid; + use t_database_owner_to; + + protected const p_QUERY_COMMAND = 'alter large object'; /** @@ -25,12 +30,18 @@ class c_database_alter_coalation extends c_database_query { */ public function __construct() { parent::__construct(); + + $this->oid = NULL; + $this->owner_to = NULL; } /** * Class destructor. */ public function __destruct() { + unset($this->oid); + unset($this->owner_to); + parent::__destruct(); } @@ -59,9 +70,14 @@ class c_database_alter_coalation extends c_database_query { * Implements do_build(). */ public function do_build() { - $this->value = NULL; + if (!is_string($this->oid) || !is_array($this->owner_to)) { + return new c_base_return_false(); + } - // @todo + $this->value = static::p_QUERY_COMMAND; + $this->value .= ' ' . $this->p_do_build_oid(); + $this->value .= ' ' . $this->p_do_build_owner_to(); + unset($value); return new c_base_return_true(); } diff --git a/common/database/classes/database_alter_materialized_view.php b/common/database/classes/database_alter_materialized_view.php index 54885a7..7faa575 100644 --- a/common/database/classes/database_alter_materialized_view.php +++ b/common/database/classes/database_alter_materialized_view.php @@ -10,14 +10,54 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); +require_once('common/database/traits/database_all_in_tablespace.php'); +require_once('common/database/traits/database_cluster_on.php'); +require_once('common/database/traits/database_column_reset.php'); +require_once('common/database/traits/database_column_set.php'); +require_once('common/database/traits/database_column_set_statistics.php'); +require_once('common/database/traits/database_column_set_storage.php'); +require_once('common/database/traits/database_depends_on_extension.php'); +require_once('common/database/traits/database_if_exists.php'); +require_once('common/database/traits/database_name.php'); +require_once('common/database/traits/database_no_wait.php'); +require_once('common/database/traits/database_owned_by.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_reset_storage_parameter.php'); +require_once('common/database/traits/database_set_schema.php'); +require_once('common/database/traits/database_set_storage_parameter.php'); +require_once('common/database/traits/database_set_tablespace.php'); +require_once('common/database/traits/database_set_without_cluster.php'); + /** - * The class for building and returning a Postgresql ALTER COALATION query string. + * The class for building and returning a Postgresql ALTER MATERIALIZED VIEW query string. * - * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html + * @see: https://www.postgresql.org/docs/current/static/sql-altermaterializedview.html */ -class c_database_alter_coalation extends c_database_query { - protected const p_QUERY_COMMAND = 'alter coalation'; +class c_database_alter_materialized_view extends c_database_query { + use t_database_all_in_tablespace; + use t_database_cluster_on; + use t_database_column_reset; + use t_database_column_set; + use t_database_column_set_statistics; + use t_database_column_set_storage; + use t_database_depends_on_extension; + use t_database_if_exists; + use t_database_name; + use t_database_no_wait; + use t_database_owned_by; + use t_database_owner_to; + use t_database_rename_column; + use t_database_rename_to; + use t_database_reset_storage_parameter; + use t_database_set_schema; + use t_database_set_storage_parameter; + use t_database_set_tablespace; + use t_database_set_without_cluster; + + protected const p_QUERY_COMMAND = 'alter materialized view'; /** @@ -25,12 +65,52 @@ class c_database_alter_coalation extends c_database_query { */ public function __construct() { parent::__construct(); + + $this->all_in_tablespace = NULL; + $this->cluster_on = NULL; + $this->column_reset = NULL; + $this->column_set = NULL; + $this->column_set_statistics = NULL; + $this->column_set_storage = NULL; + $this->depends_on_extension = NULL; + $this->if_exists = NULL; + $this->name = NULL; + $this->no_wait = NULL; + $this->owned_by = NULL; + $this->owner_to = NULL; + $this->rename_column = NULL; + $this->rename_to = NULL; + $this->reset_storage_parameter = NULL; + $this->set_schema = NULL; + $this->set_storage_parameter = NULL; + $this->set_tablespace = NULL; + $this->set_without_cluster = NULL; } /** * Class destructor. */ public function __destruct() { + unset($this->all_in_tablespace); + unset($this->cluster_on); + unset($this->column_reset); + unset($this->column_set); + unset($this->column_set_statistics); + unset($this->column_set_storage); + unset($this->depends_on_extension); + unset($this->if_exists); + unset($this->name); + unset($this->no_wait); + unset($this->owner_to); + unset($this->owned_by); + unset($this->rename_column); + unset($this->rename_to); + unset($this->reset_storage_parameter); + unset($this->set_schema); + unset($this->set_storage_parameter); + unset($this->set_tablespace); + unset($this->set_without_cluster); + parent::__destruct(); } @@ -59,9 +139,85 @@ class c_database_alter_coalation extends c_database_query { * Implements do_build(). */ public function do_build() { - $this->value = NULL; + if (!is_string($this->name)) { + return new c_base_return_false(); + } + + $if_exists = NULL; + if (is_bool($this->if_exists)) { + $if_exists = ' ' . $this->p_do_build_if_exists(); + } + + $value = $this->p_do_build_name(); + if (is_string($this->depends_on_extension)) { + $value .= ' ' . $this->p_do_build_depends_on_extension(); + $if_exists = NULL; + } + else if (is_array($this->rename_column)) { + $value .= ' ' . $this->p_do_build_rename_column(); + } + else if (is_string($this->rename_to)) { + $value .= ' ' . $this->p_do_build_rename_to(); + } + else if (is_string($this->set_schema)) { + $value .= ' ' . $this->p_do_build_set_schema(); + } + else if (is_string($this->set_tablespace)) { + $if_exists = NULL; + $value = c_database_string::ALL_IN_TABLESPACE . ' ' . $value; + + if (!is_null($this->owned_by)) { + $value .= ' ' . $this->p_do_build_owned_by(); + } + + $value .= ' ' . $this->p_do_build_set_tablespace(); + + if (is_bool($this->no_wait)) { + $value .= ' ' . $this->p_do_build_no_wait(); + } + } + else if (is_array($this->column_set_statistics)) { + $value .= ' ' . $this->p_do_build_column_set_statistics(); + } + else if (is_array($this->column_set)) { + $value .= ' ' . $this->p_do_build_column_set(); + } + else if (is_array($this->column_reset)) { + $value .= ' ' . $this->p_do_build_column_reset(); + } + else if (is_array($this->column_set_storage)) { + $value .= ' ' . $this->p_do_build_column_set_storage(); + } + else if (is_string($this->cluster_on)) { + $value .= ' ' . $this->p_do_build_cluster_on(); + } + else if (is_string($this->set_without_cluster)) { + $value .= ' ' . $this->p_do_build_set_without_cluster(); + } + else if (is_string($this->set_storage_parameter)) { + $value .= ' ' . $this->p_do_build_set_storage_parameter(); + } + else if (is_string($this->reset_storage_parameter)) { + $value .= ' ' . $this->p_do_build_reset_storage_parameter(); + } + else if (is_string($this->owner_to)) { + $value .= ' ' . $this->p_do_build_owner_to(); + } + else { + unset($value); + unset($if_exists); + return new c_base_return_false(); + } + + $this->value = static::p_QUERY_COMMAND; + + if (is_string($if_exists)) { + $this->value .= ' ' . $if_exists; + } + unset($if_exists); - // @todo + $this->value .= ' ' . $value; + unset($value); return new c_base_return_true(); } diff --git a/common/database/classes/database_string.php b/common/database/classes/database_string.php index 4ae4911..0d77039 100644 --- a/common/database/classes/database_string.php +++ b/common/database/classes/database_string.php @@ -16,6 +16,7 @@ class c_database_string { public const AGGREGATE = 'aggregate'; public const ALL = 'all'; public const ALLOW_CONNECTIONS = 'allow_connections'; + public const ALTER = 'alter'; public const AS = 'as'; public const ASCEND = 'asc'; public const AUTOSUMMARIZE = 'autosummarize'; @@ -35,7 +36,9 @@ class c_database_string { public const CALLED_ON_NULL_INPUT = 'called on null input'; public const CASCADE = 'cascade'; public const CAST = 'cast'; + public const CLUSTER_ON = 'cluster on'; public const COLLATION = 'collation'; + public const COLUMN = 'column'; public const CONNECTION_LIMIT = 'connection limit'; public const CONVERSION = 'conversion'; public const COST = 'cost'; @@ -54,6 +57,7 @@ class c_database_string { public const ENABLE_TRIGGER = 'enable trigger'; public const EVENT_TRIGGER = 'event trigger'; public const EXECUTE = 'execute'; + public const EXTENDED = 'extended'; public const EXTERNAL = 'external'; public const FALSE = 'false'; public const FAST_UPDATE = 'fastupdate'; @@ -81,11 +85,14 @@ class c_database_string { public const LANGUAGE = 'language'; public const LEAKPROOF = 'leakproof'; public const LOG_AUTOVACUUM_MIN_DURATION = 'log_autovacuum_min_duration'; + public const MAIN = 'main'; public const MATERIALIZED_VIEW = 'materialized view'; + public const N_DISTINCT = 'n_distinct'; + public const N_DISTINCT_INHERITED = 'n_distinct_inherited'; public const NO_HANDLER = 'no handler'; public const NO_INHERIT = 'no inherit'; public const NO_VALIDATOR = 'no validator'; - public const NO_WAIT = 'no wait'; + public const NO_WAIT = 'nowait'; public const NOT_LEAKPROOF = 'not leakproof'; public const NOT_NULL = 'not null'; public const NOT_VALID = 'not valid'; @@ -105,6 +112,7 @@ class c_database_string { public const PAGES_PER_RANGE = 'pages_per_range'; public const PARALLEL = 'parallel'; public const PARALLEL_WORKERS = 'parallel_workers'; + public const PLAIN = 'plain'; public const PROCEDURAL = 'procedural'; public const PUBLIC = 'public'; public const REFERENCES = 'references'; @@ -130,8 +138,11 @@ class c_database_string { public const SET = 'set'; public const SET_DEFAULT = 'set default'; public const SET_SCHEMA = 'set schema'; + public const SET_STATISTICS = 'set statistics'; + public const SET_STORAGE = 'set storage'; public const SET_TABLESPACE = 'set tablespace'; public const SET_WITH_OIDS = 'set with oids'; + public const SET_WITHOUT_CLUSTER = 'set without cluster'; public const SET_WITHOUT_OIDS = 'set without oids'; public const STABLE = 'stable'; public const STRICT = 'strict'; diff --git a/common/database/enumerations/database_attribute_option.php b/common/database/enumerations/database_attribute_option.php new file mode 100644 index 0000000..8e895a3 --- /dev/null +++ b/common/database/enumerations/database_attribute_option.php @@ -0,0 +1,17 @@ +add_user)) { - return NULL; - } - $values = []; foreach ($this->add_user['names'] as $name) { if ($name === e_database_user::CURRENT) { diff --git a/common/database/traits/database_argument_type.php b/common/database/traits/database_argument_type.php index 2db6c66..d2b431d 100644 --- a/common/database/traits/database_argument_type.php +++ b/common/database/traits/database_argument_type.php @@ -120,10 +120,6 @@ trait t_database_argument_type { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_argument_type() { - if (is_null($this->argument_type)) { - return NULL; - } - $values = []; foreach ($this->argument_type as $argument_type) { $value = ''; diff --git a/common/database/traits/database_cascade.php b/common/database/traits/database_cascade.php index eed1f6c..da05931 100644 --- a/common/database/traits/database_cascade.php +++ b/common/database/traits/database_cascade.php @@ -24,7 +24,7 @@ trait t_database_cascade { * Set the HANDLER settings. * * @param int|null $cascade - * The intege representing cascade/no-cascade. + * The integer representing cascade/no-cascade. * Set to NULL to disable. * * @return c_base_return_status @@ -77,10 +77,6 @@ trait t_database_cascade { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_cascade() { - if (is_null($this->cascade)) { - return NULL; - } - $value = NULL; if ($this->cascade['type'] === e_database_cascade::CASCADE) { if (isset($this->cascade['name'])) { diff --git a/common/database/traits/database_column_reset.php b/common/database/traits/database_column_reset.php new file mode 100644 index 0000000..53a3da7 --- /dev/null +++ b/common/database/traits/database_column_reset.php @@ -0,0 +1,137 @@ +column_reset = NULL; + return new c_base_return_true(); + } + + if (!is_string($name) && !isset($this->column_reset['name'])) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + switch ($attribute_option) { + case e_database_attribute_option::N_DISTINCT: + case e_database_attribute_option::N_DISTINCT_INHERITED: + break; + default: + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'attribute_option', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (is_string($name)) { + if (is_array($this->column_reset)) { + $this->column_reset['name'] = $name; + } + else { + $this->column_reset = [ + 'name' => $name, + 'values' => [], + ]; + } + } + + if (!is_null($attribute_option)) { + $this->column_reset['values'][] = $attribute_option; + } + + return new c_base_return_true(); + } + + /** + * Get the currently assigned COLUMN_RESET attribute option at the specified index. + * + * @param int|null $index + * (optional) Get the index attribute option type at the specified index. + * When NULL, all index attribute option types are returned. + * + * @return c_base_return_array|c_base_return_int|c_base_return_null + * A code or an array of codes representing the argument_type on success. + * NULL is returned if not set (column_reset tablespace is not to be used). + * NULL with the error bit set is returned on error. + */ + public function get_column_reset($index = NULL) { + if (is_null($this->column_reset)) { + return new c_base_return_null(); + } + + if (is_null($index)) { + if (is_array($this->column_reset)) { + return c_base_return_array::s_new($this->column_reset); + } + } + else { + if (is_int($index) && isset($this->column_reset['values'][$index]) && is_int($this->column_reset['values'][$index])) { + return c_base_return_int::s_new($this->column_reset['values'][$index]); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_reset[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_reset', ':{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_column_reset() { + $values = []; + foreach ($this->column_reset['values'] as $attribute_option) { + if ($attribute_option === e_database_attribute_option::N_DISTINCT) { + $values[] = c_database_string::N_DISTINCT; + } + else if ($attribute_option === e_database_attribute_option::N_DISTINCT_INHERITED) { + $values[] = c_database_string::N_DISTINCT_INHERITED; + } + } + unset($attribute_option); + + return c_database_string::COLUMN . ' ' . $this->column_reset['name'] . ' ' . c_database_string::RESET . ' ' . implode(', ', $values); + } +} diff --git a/common/database/traits/database_column_set.php b/common/database/traits/database_column_set.php new file mode 100644 index 0000000..dcf82b7 --- /dev/null +++ b/common/database/traits/database_column_set.php @@ -0,0 +1,149 @@ +column_set = NULL; + return new c_base_return_true(); + } + + if (!is_string($name) && !isset($this->column_set['name'])) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + switch ($attribute_option) { + case e_database_attribute_option::N_DISTINCT: + case e_database_attribute_option::N_DISTINCT_INHERITED: + break; + default: + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'attribute_option', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($attribute_option) && !is_string($value)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'value', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (is_string($name)) { + if (is_array($this->column_set)) { + $this->column_set['name'] = $name; + } + else { + $this->column_set = [ + 'name' => $name, + 'values' => [], + ]; + } + } + + if (!is_null($attribute_option)) { + $this->column_set['values'][] = [ + 'type' => $attribute_option, + 'value' => $value, + ]; + } + + return new c_base_return_true(); + } + + /** + * Get the currently assigned COLUMN .. SET index attribute option at the specified index. + * + * @param int|null $index + * (optional) Get the index attribute option type at the specified index. + * When NULL, all index attribute option types are returned. + * + * @return c_base_return_array|c_base_return_null + * An array containing the set index attribute option settings on success. + * NULL is returned if not set (set index attribute option not to be used). + * NULL with the error bit set is returned on error. + */ + public function get_column_set($index = NULL) { + if (is_null($this->column_set)) { + return new c_base_return_null(); + } + + if (is_null($index)) { + if (is_array($this->column_set)) { + return c_base_return_array::s_new($this->column_set); + } + } + else { + if (is_int($index) && isset($index, $this->column_set['values']) && is_array($this->column_set['values'][$index])) { + return c_base_return_array::s_new($this->column_set['values'][$index]); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_set[values][index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_set', ':{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_column_set() { + $values = []; + foreach ($this->column_set['values'] as $attribute_option => $value) { + if ($attribute_option === e_database_attribute_option::N_DISTINCT) { + $values[] = c_database_string::N_DISTINCT . ' = ' . $value; + } + else if ($attribute_option === e_database_attribute_option::N_DISTINCT_INHERITED) { + $values[] = c_database_string::N_DISTINCT_INHERITED . ' = ' . $value; + } + } + unset($attribute_option); + unset($value); + + return c_database_string::COLUMN . ' ' . $this->column_set['name'] . ' ' . c_database_string::SET . ' ' . implode(', ', $values); + } +} diff --git a/common/database/traits/database_column_set_statistics.php b/common/database/traits/database_column_set_statistics.php new file mode 100644 index 0000000..490ed65 --- /dev/null +++ b/common/database/traits/database_column_set_statistics.php @@ -0,0 +1,94 @@ +column_set_storage = NULL; + return new c_base_return_true(); + } + + if (!is_string($name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (is_int($column_set_statistics)) { + $this->column_set_statistics = [ + 'name' => $name, + 'value' => $value, + ]; + + return new c_base_return_true(); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'value', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + /** + * Get the currently assigned set statistics integer. + * + * @return c_base_return_array|c_base_return_null + * An array containing the column_set_statistics setting on success.on success. + * NULL is returned if not set (is not to be used). + * NULL with the error bit set is returned on error. + */ + public function get_column_set_statistics() { + if (is_null($this->column_set_statistics)) { + return new c_base_return_null(); + } + + if (is_array($this->column_set_statistics)) { + return c_base_return_array::s_new($this->column_set_statistics); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_set_statistics', ':{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_column_set_statistics() { + return c_database_string::COLUMN . ' ' . $this->column_set_statistics['name'] . ' ' . c_database_string::SET_STATISTICS . ' ' . $this->column_set_statistics['value']; + } +} diff --git a/common/database/traits/database_column_set_storage.php b/common/database/traits/database_column_set_storage.php new file mode 100644 index 0000000..103d921 --- /dev/null +++ b/common/database/traits/database_column_set_storage.php @@ -0,0 +1,115 @@ +column_set_storage = NULL; + return new c_base_return_true(); + } + + if (!is_string($name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + switch ($type) { + case e_database_set_storage::EXTENDED: + case e_database_set_storage::EXTERNAL: + case e_database_set_storage::MAIN: + case e_database_set_storage::PLAIN: + break; + default: + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->column_set_storage = [ + 'type' => $type, + 'name' => $name, + ]; + + return new c_base_return_true(); + } + + /** + * Get the currently assigned column_set_storage. + * + * @return c_base_return_array|c_base_return_null + * An array containing the column_set_storage setting on success. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_column_set_storage() { + if (is_null($this->column_set_storage)) { + return new c_base_return_null(); + } + + if (is_array($this->column_set_storage)) { + return c_base_return_array::s_new($this->column_set_storage); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_set_storage', ':{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_column_set_storage() { + $value = c_database_string::COLUMN . ' ' . $this->column_set_storage['name'] . ' ' . c_database_string::SET_STORAGE . ' '; + if ($this->column_set_storage['type'] === e_database_column_set_storage::EXTENDED) { + return $value . c_database_string::EXTENDED; + } + else if ($this->column_set_storage['type'] === e_database_column_set_storage::EXTERNAL) { + return $value . c_database_string::EXTERNAL; + } + else if ($this->column_set_storage['type'] === e_database_column_set_storage::MAIN) { + return $value . c_database_string::MAIN; + } + else if ($this->column_set_storage['type'] === e_database_column_set_storage::PLAIN) { + return $value . c_database_string::PLAIN; + } + unset($value); + + return NULL; + } +} diff --git a/common/database/traits/database_constraint.php b/common/database/traits/database_constraint.php index bc4655a..54789f0 100644 --- a/common/database/traits/database_constraint.php +++ b/common/database/traits/database_constraint.php @@ -134,10 +134,6 @@ trait t_database_constraint { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_constraint() { - if (is_null($this->constraint)) { - return NULL; - } - $value = NULL; if ($this->constraint['type'] === e_database_constraint::ADD) { if (is_string($this->constraint['name'])) { diff --git a/common/database/traits/database_depends_on_extension.php b/common/database/traits/database_depends_on_extension.php index 3f5141c..20449e6 100644 --- a/common/database/traits/database_depends_on_extension.php +++ b/common/database/traits/database_depends_on_extension.php @@ -72,10 +72,6 @@ trait t_database_depends_on_extension { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_depends_on_extension() { - if (is_null($this->depends_on_extension)) { - return NULL; - } - return c_database_string::DEPENDS_ON_EXTENSION . ' ' . $this->depends_on_extension; } } diff --git a/common/database/traits/database_enable_trigger.php b/common/database/traits/database_enable_trigger.php index 11640c5..7610db4 100644 --- a/common/database/traits/database_enable_trigger.php +++ b/common/database/traits/database_enable_trigger.php @@ -115,10 +115,6 @@ trait t_database_enable_trigger { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_enable_trigger() { - if (is_null($this->enable_trigger)) { - return NULL; - } - $value = NULL; switch ($this->enable_trigger['type']) { case e_database_enable_trigger::ALWAYS: diff --git a/common/database/traits/database_for_role.php b/common/database/traits/database_for_role.php index c1216dd..279acb4 100644 --- a/common/database/traits/database_for_role.php +++ b/common/database/traits/database_for_role.php @@ -96,10 +96,6 @@ trait t_database_for_role { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_for_role() { - if (is_null($this->for_role)) { - return NULL; - } - return c_database_string::FOR_ROLE . ' ' . implode(', ', $this->for_role); } } diff --git a/common/database/traits/database_function_action.php b/common/database/traits/database_function_action.php index 35b7a0a..9a3b262 100644 --- a/common/database/traits/database_function_action.php +++ b/common/database/traits/database_function_action.php @@ -153,10 +153,6 @@ trait t_database_function_action { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_function_action() { - if (is_null($this->function_action)) { - return NULL; - } - $values = []; foreach ($this->function_action as $function_action) { if ($function_action['type'] === e_database_function_action::CALLED_ON_NULL_INPUT) { diff --git a/common/database/traits/database_grant_option_for.php b/common/database/traits/database_grant_option_for.php index 01c3755..28eb80b 100644 --- a/common/database/traits/database_grant_option_for.php +++ b/common/database/traits/database_grant_option_for.php @@ -78,10 +78,6 @@ trait t_database_grant_option_for { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_grant_option_for() { - if (is_null($this->grant_option_for)) { - return NULL; - } - return $this->grant_option_for ? c_database_string::GRANT_OPTION_FOR : NULL; } } diff --git a/common/database/traits/database_handler.php b/common/database/traits/database_handler.php index 554f0df..0bd4b54 100644 --- a/common/database/traits/database_handler.php +++ b/common/database/traits/database_handler.php @@ -24,7 +24,7 @@ trait t_database_handler { * Set the HANDLER settings. * * @param int|null $handler - * The intege representing handler/no-handler. + * The integer representing handler/no-handler. * Set to NULL to disable. * @param string|null $handler_function * The handler function name or null when NO_HANDLER is specified. @@ -96,10 +96,6 @@ trait t_database_handler { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_handler() { - if (is_null($this->handler)) { - return NULL; - } - $value = NULL; if ($this->handler['type'] === e_database_handler::HANDLER) { if (isset($this->handler['name'])) { diff --git a/common/database/traits/database_in_schema.php b/common/database/traits/database_in_schema.php index b977774..edf041e 100644 --- a/common/database/traits/database_in_schema.php +++ b/common/database/traits/database_in_schema.php @@ -96,10 +96,6 @@ trait t_database_in_schema { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_in_schema() { - if (is_null($this->in_schema)) { - return NULL; - } - return c_database_string::IN_SCHEMA . ' ' . implode(', ', $this->in_schema); } } diff --git a/common/database/traits/database_inherit.php b/common/database/traits/database_inherit.php index 863c61a..ce2370c 100644 --- a/common/database/traits/database_inherit.php +++ b/common/database/traits/database_inherit.php @@ -84,10 +84,6 @@ trait t_database_inherit { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_inherit() { - if (is_null($this->inherit)) { - return NULL; - } - $value = $this->inherit['inherit'] ? c_database_string::INHERIT : c_database_string::NO_INHERIT; $value .= ' ' . $this->inherit['name']; return $value; diff --git a/common/database/traits/database_name.php b/common/database/traits/database_name.php index 2e0b162..401f59a 100644 --- a/common/database/traits/database_name.php +++ b/common/database/traits/database_name.php @@ -75,10 +75,6 @@ trait t_database_name { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_name() { - if (is_null($this->name)) { - return NULL; - } - return $this->name; } } diff --git a/common/database/traits/database_no_wait.php b/common/database/traits/database_no_wait.php index 3e0b274..666230d 100644 --- a/common/database/traits/database_no_wait.php +++ b/common/database/traits/database_no_wait.php @@ -78,10 +78,6 @@ trait t_database_no_wait { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_no_wait() { - if (is_null($this->no_wait)) { - return NULL; - } - return $this->no_wait ? c_database_string::NO_WAIT : NULL; } } diff --git a/common/database/traits/database_oid.php b/common/database/traits/database_oid.php new file mode 100644 index 0000000..c5c862e --- /dev/null +++ b/common/database/traits/database_oid.php @@ -0,0 +1,80 @@ +oid = NULL; + return new c_base_return_true(); + } + + if (is_string($oid)) { + $this->oid = $oid; + return new c_base_return_true(); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'oid', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + /** + * Get the currently assigned oid. + * + * @return c_base_return_string|c_base_return_null + * A oid on success. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_oid() { + if (is_null($this->oid)) { + return new c_base_return_null(); + } + + if (is_string($this->oid)) { + return c_base_return_string::s_new($this->oid); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'oid', ':{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_oid() { + return $this->oid; + } +} diff --git a/common/database/traits/database_on.php b/common/database/traits/database_on.php index b7b1477..37f5360 100644 --- a/common/database/traits/database_on.php +++ b/common/database/traits/database_on.php @@ -83,10 +83,6 @@ trait t_database_on { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_on() { - if (is_null($this->on)) { - return NULL; - } - $value = NULL; switch($this->on) { case e_database_on::TABLES_TO: diff --git a/common/database/traits/database_options.php b/common/database/traits/database_options.php index 389d00e..c3816ea 100644 --- a/common/database/traits/database_options.php +++ b/common/database/traits/database_options.php @@ -113,10 +113,6 @@ trait t_database_options { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_options() { - if (is_null($this->options)) { - return NULL; - } - $options = []; foreach ($this->options as $options_value) { if ($options_value['type'] == e_database_options::ADD) { diff --git a/common/database/traits/database_order_by.php b/common/database/traits/database_order_by.php index 9ef7404..80ee53e 100644 --- a/common/database/traits/database_order_by.php +++ b/common/database/traits/database_order_by.php @@ -78,10 +78,6 @@ trait t_database_order_by { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_order_by() { - if (is_null($this->order_by)) { - return NULL; - } - return c_database_string::ORDER_BY . ' ' . $this->order_by; } } diff --git a/common/database/traits/database_owned_by.php b/common/database/traits/database_owned_by.php index 196a953..b2dd055 100644 --- a/common/database/traits/database_owned_by.php +++ b/common/database/traits/database_owned_by.php @@ -23,8 +23,8 @@ trait t_database_owned_by { /** * Assigns the SQL owned_by. * - * @param int|null $owned_by - * Set a owned_by code. + * @param int|string|null $owned_by + * Set a owned_by code or name. * Set to NULL to disable. * When NULL, this will remove all values. * @@ -39,23 +39,18 @@ trait t_database_owned_by { } if (is_int($owned_by)) { - // no reason to add any owned_by once ALL is present. - if ($this->owned_by === e_database_owned_by::ALL) { - return new c_base_return_true(); - } + if ($owned_by === e_database_user::ALL) { + $this->owned_by = e_database_user::ALL; - if ($owned_by === e_database_owned_by::ALL) { - $this->owned_by = e_database_owned_by::ALL; + return new c_base_return_true(); } - else { - if (!is_array($this->owned_by)) { - $this->owned_by = []; - } - - $this->owned_by[] = $owned_by; + } + else if (is_string($owned_by)) { + if (!is_array($this->owned_by)) { + $this->owned_by = []; } - return new c_base_return_true(); + $this->owned_by[] = $owned_by; } $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'owned_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); @@ -69,7 +64,7 @@ trait t_database_owned_by { * (optional) Get the owned_by at the specified index. * When NULL, all owned_by are returned. * - * @return c_base_return_int|c_base_return_array|c_base_return_null + * @return c_base_return_int|c_base_return_string|c_base_return_array|c_base_return_null * An array of owned_by or NULL if not defined. * A single owned_by is returned if $index is an integer. * NULL with the error bit set is returned on error. @@ -80,20 +75,26 @@ trait t_database_owned_by { } if (is_null($index)) { - if ($this->owned_by === e_database_owned_by::ALL) { + if ($this->owned_by === e_database_user::ALL) { return c_base_return_array::s_new([$this->owned_by]); } else if (is_array($this->owned_by)) { return c_base_return_array::s_new($this->owned_by); } } - else { - if (is_int($index) && array_key_exists($index, $this->owned_by) && is_int($this->owned_by[$index])) { - return clone($this->owned_by[$index]); + else if (is_int($index)) { + if (array_key_exists($index, $this->owned_by)) { + if (is_int($this->owned_by[$index])) { + return c_base_return_int::s_new($this->owned_by[$index]); + } + else if (is_string($this->owned_by[$index])) { + return c_base_return_string::s_new($this->owned_by[$index]); + } + } + else { + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'owned_by[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'owned_by[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'owned_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); @@ -110,10 +111,15 @@ trait t_database_owned_by { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_owned_by() { - if (is_null($this->owned_by)) { - return NULL; + $owned_by = c_database_string::OWNED_BY . ' '; + + if ($this->owned_by === e_database_user::ALL) { + $owned_by .= c_database_string::ALL; + } + else { + $owned_by .= implode(', ', $this->owned_by); } - return c_database_string::OWNED_BY . ' ' . implode(', ', $this->owned_by); + return $owned_by; } } diff --git a/common/database/traits/database_owner_to.php b/common/database/traits/database_owner_to.php index 326aaaf..7d8770c 100644 --- a/common/database/traits/database_owner_to.php +++ b/common/database/traits/database_owner_to.php @@ -113,10 +113,6 @@ trait t_database_owner_to { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_owner_to() { - if (is_null($this->owner_to)) { - return NULL; - } - return c_database_string::OWNER_TO . ' ' . $this->owner_to['value']; } } diff --git a/common/database/traits/database_privilege.php b/common/database/traits/database_privilege.php index b1bc778..1908f02 100644 --- a/common/database/traits/database_privilege.php +++ b/common/database/traits/database_privilege.php @@ -110,10 +110,6 @@ trait t_database_privilege { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_privilege() { - if (is_null($this->privilege)) { - return NULL; - } - if ($this->privilege === e_database_privilege::ALL) { return c_database_string::ALL; } diff --git a/common/database/traits/database_procedural.php b/common/database/traits/database_procedural.php new file mode 100644 index 0000000..a6017db --- /dev/null +++ b/common/database/traits/database_procedural.php @@ -0,0 +1,83 @@ +procedural = NULL; + return new c_base_return_true(); + } + + if (!is_bool($procedural)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'procedural', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->procedural = $procedural; + return new c_base_return_true(); + } + + /** + * Get the currently assigned with grant option value. + * + * @return c_base_return_bool|c_base_return_null + * TRUE for PROCEDURAL on success. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_procedural() { + if (is_null($this->procedural)) { + return new c_base_return_null(); + } + + if (is_bool($this->procedural)) { + return c_base_return_bool::s_new($this->procedural); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'procedural', ':{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_procedural() { + return $this->procedural ? c_database_string::PROCEDURAL : NULL; + } +} diff --git a/common/database/traits/database_rename_column.php b/common/database/traits/database_rename_column.php index 29906af..eab1ca0 100644 --- a/common/database/traits/database_rename_column.php +++ b/common/database/traits/database_rename_column.php @@ -87,10 +87,6 @@ trait t_database_rename_column { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_rename_column() { - if (is_null($this->rename_column)) { - return NULL; - } - return c_database_string::RENAME_COLUMN . ' ' . $this->rename_column['from'] . ' ' . c_database_string::TO . $this->rename_column['to']; } } diff --git a/common/database/traits/database_rename_to.php b/common/database/traits/database_rename_to.php index ebfc6fb..009baab 100644 --- a/common/database/traits/database_rename_to.php +++ b/common/database/traits/database_rename_to.php @@ -72,10 +72,6 @@ trait t_database_rename_to { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_rename_to() { - if (is_null($this->rename_to)) { - return NULL; - } - return c_database_string::RENAME_TO . ' ' . $this->rename_to; } } diff --git a/common/database/traits/database_reset.php b/common/database/traits/database_reset.php index fb026af..6179936 100644 --- a/common/database/traits/database_reset.php +++ b/common/database/traits/database_reset.php @@ -104,10 +104,6 @@ trait t_database_reset { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_reset() { - if (is_null($this->reset)) { - return NULL; - } - $value = NULL; if ($this->reset['type'] === e_database_reset::PARAMETER) { if (is_string($this->reset['value'])) { diff --git a/common/database/traits/database_reset_storage_parameter.php b/common/database/traits/database_reset_storage_parameter.php index 660c855..8dcfe5d 100644 --- a/common/database/traits/database_reset_storage_parameter.php +++ b/common/database/traits/database_reset_storage_parameter.php @@ -106,10 +106,6 @@ trait t_database_reset_storage_parameter { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_reset_storage_parameter() { - if (is_null($this->reset_storage_parameter)) { - return NULL; - } - $values = []; foreach ($this->reset_storage_parameter as $storage_parameter) { if ($storage_parameter === e_database_storage_parameter::AUTOSUMMARIZE) { diff --git a/common/database/traits/database_restrict.php b/common/database/traits/database_restrict.php index 9e670e0..126f4b8 100644 --- a/common/database/traits/database_restrict.php +++ b/common/database/traits/database_restrict.php @@ -78,10 +78,6 @@ trait t_database_restrict { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_restrict() { - if (is_null($this->restrict)) { - return NULL; - } - return $this->restrict ? c_database_string::RESTRICT : NULL; } } diff --git a/common/database/traits/database_role_specification.php b/common/database/traits/database_role_specification.php index adb824e..b49f775 100644 --- a/common/database/traits/database_role_specification.php +++ b/common/database/traits/database_role_specification.php @@ -84,10 +84,6 @@ trait t_database_role_specification { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_role_specification() { - if (is_null($this->role_specification)) { - return NULL; - } - $value = NULL; if (is_string($this->role_specification)) { $value = $this->role_specification; diff --git a/common/database/traits/database_set.php b/common/database/traits/database_set.php index dbdf4bf..1c83d7c 100644 --- a/common/database/traits/database_set.php +++ b/common/database/traits/database_set.php @@ -113,10 +113,6 @@ trait t_database_set { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set() { - if (is_null($this->set)) { - return NULL; - } - $value = NULL; if ($this->set['type'] === e_database_set::TO) { if (is_null($this->set['parameter'])) { diff --git a/common/database/traits/database_set_schema.php b/common/database/traits/database_set_schema.php index bd99ec8..52df467 100644 --- a/common/database/traits/database_set_schema.php +++ b/common/database/traits/database_set_schema.php @@ -72,10 +72,6 @@ trait t_database_set_schema { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_schema() { - if (is_null($this->set_schema)) { - return NULL; - } - return c_database_string::SET_SCHEMA . ' ' . $this->set_schema; } } diff --git a/common/database/traits/database_set_storage_parameter.php b/common/database/traits/database_set_storage_parameter.php index 8679990..44f96b4 100644 --- a/common/database/traits/database_set_storage_parameter.php +++ b/common/database/traits/database_set_storage_parameter.php @@ -118,10 +118,6 @@ trait t_database_set_storage_parameter { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_storage_parameter() { - if (is_null($this->set_storage_parameter)) { - return NULL; - } - $values = []; foreach ($this->set_storage_parameter as $storage_parameter => $value) { if ($storage_parameter === e_database_storage_parameter::AUTOSUMMARIZE) { diff --git a/common/database/traits/database_set_tablespace.php b/common/database/traits/database_set_tablespace.php index ff8dfbc..98c13b4 100644 --- a/common/database/traits/database_set_tablespace.php +++ b/common/database/traits/database_set_tablespace.php @@ -72,10 +72,6 @@ trait t_database_set_tablespace { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_tablespace() { - if (is_null($this->set_tablespace)) { - return NULL; - } - return c_database_string::SET_TABLESPACE . ' ' . $this->set_tablespace; } } diff --git a/common/database/traits/database_set_with_oids.php b/common/database/traits/database_set_with_oids.php index c24aa86..e8dd20b 100644 --- a/common/database/traits/database_set_with_oids.php +++ b/common/database/traits/database_set_with_oids.php @@ -78,10 +78,6 @@ trait t_database_set_with_oids { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_with_oids() { - if (is_null($this->set_with_oids)) { - return NULL; - } - return $this->set_with_oids ? c_database_string::SET_WITH_OIDS : c_database_string::SET_WITHOUT_OIDS; } } diff --git a/common/database/traits/database_set_without_cluster.php b/common/database/traits/database_set_without_cluster.php new file mode 100644 index 0000000..766204d --- /dev/null +++ b/common/database/traits/database_set_without_cluster.php @@ -0,0 +1,83 @@ +set_without_cluster = NULL; + return new c_base_return_true(); + } + + if (!is_bool($set_without_cluster)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'set_without_cluster', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->set_without_cluster = $set_without_cluster; + return new c_base_return_true(); + } + + /** + * Get the currently assigned with grant option value. + * + * @return c_base_return_bool|c_base_return_null + * TRUE for SET WITHOUT CLUSTER on success. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_set_without_cluster() { + if (is_null($this->set_without_cluster)) { + return new c_base_return_null(); + } + + if (is_bool($this->set_without_cluster)) { + return c_base_return_bool::s_new($this->set_without_cluster); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_without_cluster', ':{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_without_cluster() { + return $this->set_without_cluster ? c_database_string::SET_WITHOUT_CLUSTER : NULL; + } +} diff --git a/common/database/traits/database_to_role.php b/common/database/traits/database_to_role.php index 93e6e82..724935c 100644 --- a/common/database/traits/database_to_role.php +++ b/common/database/traits/database_to_role.php @@ -113,10 +113,6 @@ trait t_database_to_role { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_to_role() { - if (is_null($this->to_role)) { - return NULL; - } - $values = []; foreach ($this->to_role as $to_role) { if ($this->to_role['type'] === e_database_role::PUBLIC) { diff --git a/common/database/traits/database_validator.php b/common/database/traits/database_validator.php index 823ec75..6a8ebb9 100644 --- a/common/database/traits/database_validator.php +++ b/common/database/traits/database_validator.php @@ -24,7 +24,7 @@ trait t_database_validator { * Set the VALIDATOR settings. * * @param int|null $validator - * The intege representing validator/no-validator. + * The integer representing validator/no-validator. * Set to NULL to disable. * @param string|null $validator_function * The validator function name or null when NO_VALIDATOR is specified. @@ -96,10 +96,6 @@ trait t_database_validator { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_validator() { - if (is_null($this->validator)) { - return NULL; - } - $value = NULL; if ($this->validator['type'] == e_database_validator::VALIDATOR) { if (isset($this->validator['name'])) { diff --git a/common/database/traits/database_with_grant_option.php b/common/database/traits/database_with_grant_option.php index 1e78dd1..70b60ab 100644 --- a/common/database/traits/database_with_grant_option.php +++ b/common/database/traits/database_with_grant_option.php @@ -15,7 +15,7 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_string.php'); /** - * Provide the sql WITH GANT OPTION functionality. + * Provide the sql WITH GRANT OPTION functionality. */ trait t_database_with_grant_option { protected $with_grant_option; @@ -24,7 +24,7 @@ trait t_database_with_grant_option { * Set the WITH GRANT OPTION value. * * @param bool|null $with_grant_option - * Set to TRUE for WITH GANT OPTION. + * Set to TRUE for WITH GRANT OPTION. * Set to FALSE for nothing. * Set to NULL to disable. * @@ -51,7 +51,7 @@ trait t_database_with_grant_option { * Get the currently assigned with grant option value. * * @return c_base_return_bool|c_base_return_null - * TRUE for WITH GANT OPTION on success. + * TRUE for WITH GRANT OPTION on success. * NULL is returned if not set. * NULL with the error bit set is returned on error. */ @@ -78,10 +78,6 @@ trait t_database_with_grant_option { * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_with_grant_option() { - if (is_null($this->with_grant_option)) { - return NULL; - } - return $this->with_grant_option ? c_database_string::WITH_GRANT_OPTION : NULL; } } -- 1.8.3.1