From e64efbc09ff2bef19a85c911f239db82018aabc2 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 9 Feb 2019 20:07:32 -0600 Subject: [PATCH] Progress: continue development on database abstraction --- .../database/classes/database_alter_aggregate.php | 66 ++----- .../classes/database_alter_default_privileges.php | 10 +- common/database/classes/database_alter_domain.php | 30 +-- .../classes/database_alter_event_trigger.php | 14 +- .../database/classes/database_alter_extension.php | 12 +- .../database_alter_foreign_data_wrapper.php | 4 +- common/database/classes/database_alter_user.php | 67 ++++++- .../classes/database_alter_user_mapping.php | 30 ++- common/database/classes/database_member_object.php | 4 +- common/database/classes/database_string.php | 11 +- ...e_action.php => database_action_deprecated.php} | 2 +- .../enumerations/database_attribute_action.php | 18 ++ .../database/enumerations/database_role_option.php | 2 +- .../enumerations/database_server_option.php | 18 ++ common/database/enumerations/database_user.php | 7 +- common/database/traits/database_action.php | 166 ++++------------ .../database_action_alter_column_options.php | 21 +- .../traits/database_action_alter_column_reset.php | 21 +- .../traits/database_action_alter_column_set.php | 21 +- .../database/traits/database_action_deprecated.php | 184 ++++++++++++++++++ common/database/traits/database_action_options.php | 21 +- .../traits/database_add_operator_family.php | 18 +- common/database/traits/database_add_value.php | 2 + common/database/traits/database_argument_type.php | 22 +-- common/database/traits/database_column_reset.php | 28 +-- common/database/traits/database_column_set.php | 22 +-- common/database/traits/database_drop_table.php | 6 +- common/database/traits/database_for_role.php | 23 +-- .../database/traits/database_function_action.php | 2 +- common/database/traits/database_group_by.php | 23 +-- common/database/traits/database_in_schema.php | 23 +-- common/database/traits/database_options.php | 21 +- common/database/traits/database_order_by.php | 23 +-- common/database/traits/database_owned_by.php | 35 +--- common/database/traits/database_privilege.php | 27 +-- .../traits/database_refresh_publication.php | 2 +- .../database/traits/database_rename_attribute.php | 130 +++++++++++++ common/database/traits/database_rename_value.php | 109 +++++++++++ .../traits/database_reset_storage_parameter.php | 22 +-- .../traits/database_role_specification.php | 2 +- common/database/traits/database_server_name.php | 85 ++++++++ common/database/traits/database_server_options.php | 161 +++++++++++++++ common/database/traits/database_set_operator.php | 21 +- .../traits/database_set_publication_name.php | 28 +-- .../traits/database_set_publication_parameter.php | 22 +-- .../traits/database_set_storage_parameter.php | 24 +-- common/database/traits/database_set_table.php | 8 +- common/database/traits/database_to_role.php | 21 +- common/database/traits/database_type_action.php | 215 +++++++++++++++++++++ common/database/traits/database_user_name.php | 121 ++++++++++++ .../traits/database_with_publication_option.php | 24 +-- .../traits/database_with_refresh_option.php | 24 +-- .../database/traits/database_with_role_option.php | 6 +- .../traits/database_with_storage_parameter.php | 22 +-- 54 files changed, 1336 insertions(+), 715 deletions(-) rename common/database/enumerations/{database_action.php => database_action_deprecated.php} (96%) create mode 100644 common/database/enumerations/database_attribute_action.php create mode 100644 common/database/enumerations/database_server_option.php create mode 100644 common/database/traits/database_action_deprecated.php create mode 100644 common/database/traits/database_rename_attribute.php create mode 100644 common/database/traits/database_rename_value.php create mode 100644 common/database/traits/database_server_name.php create mode 100644 common/database/traits/database_server_options.php create mode 100644 common/database/traits/database_type_action.php create mode 100644 common/database/traits/database_user_name.php diff --git a/common/database/classes/database_alter_aggregate.php b/common/database/classes/database_alter_aggregate.php index 75ac036..e86ec95 100644 --- a/common/database/classes/database_alter_aggregate.php +++ b/common/database/classes/database_alter_aggregate.php @@ -20,6 +20,8 @@ require_once('common/database/traits/database_set_schema.php'); * * When no argument mode is specified, then a wildcard * is auto-provided for the aggregate_signature parameter. * + * @todo: review this implementation, may be outdated. + * * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html */ class c_database_alter_aggregate extends c_database_query { @@ -151,32 +153,17 @@ class c_database_alter_aggregate extends c_database_query { /** * Get the aggregate signatures. * - * @param int|null $index - * (optional) Get the argument signature at the specified index. - * When NULL, all argument signatures are returned. - * - * @return c_database_argument_aggregate_signature|c_base_return_array|c_base_return_null + * @return c_base_return_array|c_base_return_null * An array of aggregate signatures or NULL if not defined. - * A single aggregate signature is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_aggregate_signature($index = NULL) { + public function get_aggregate_signature() { if (is_null($this->aggregate_signatures)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->aggregate_signatures)) { - return c_base_return_array::s_new($this->aggregate_signatures); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->aggregate_signatures) && $this->aggregate_signatures[$index] instanceof c_database_argument_aggregate_signature) { - return clone($this->aggregate_signatures[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'aggregate_signatures[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->aggregate_signatures)) { + return c_base_return_array::s_new($this->aggregate_signatures); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'aggregate_signatures', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); @@ -186,23 +173,16 @@ class c_database_alter_aggregate extends c_database_query { /** * Get the total aggregate signatures. * - * @param int|null $index - * (optional) Get the aggregate signature at the specified index. - * When NULL, all aggregate signatures are returned. - * * @return c_base_return_int * The total number of aggregate signatures. * 0 with the error bit set is returned on error. */ - public function get_aggregate_signature_count($index = NULL) { + public function get_aggregate_signature_count() { if (is_null($this->aggregate_signatures)) { return new c_base_return_null(); } - if (is_null($index)) { - return new c_base_return_int(0); - } - else if (is_array($this->aggregate_signatures)) { + if (is_array($this->aggregate_signatures)) { return new c_base_return_int(count($this->aggregate_signatures)); } @@ -213,32 +193,17 @@ class c_database_alter_aggregate extends c_database_query { /** * Get the order by aggregate signatures. * - * @param int|null $index - * (optional) Get the argument signature at the specified index. - * When NULL, all argument signatures are returned. - * - * @return c_database_argument_aggregate_signature|c_base_return_array|c_base_return_null + * @return c_base_return_array|c_base_return_null * An array of order by aggregate signatures or NULL if not defined. - * A single order by aggregate signature is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_order_by_signature($index = NULL) { + public function get_order_by_signature() { if (is_null($this->order_by_signatures)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->order_by_signatures)) { - return c_base_return_array::s_new($this->order_by_signatures); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->order_by_signatures) && $this->order_by_signatures[$index] instanceof c_database_argument_aggregate_signature_base) { - return clone($this->order_by_signatures[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'order_by_signatures[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->order_by_signatures)) { + return c_base_return_array::s_new($this->order_by_signatures); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'order_by_signatures', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); @@ -252,15 +217,12 @@ class c_database_alter_aggregate extends c_database_query { * The total number of aggregate signatures. * 0 with the error bit set is returned on error. */ - public function get_order_by_signature_count($index = NULL) { + public function get_order_by_signature_count() { if (is_null($this->order_by_signatures)) { return new c_base_return_null(); } - if (is_null($index)) { - return new c_base_return_int(0); - } - else if (is_array($this->aggregate_signatures)) { + if (is_array($this->aggregate_signatures)) { return new c_base_return_int(count($this->aggregate_signatures)); } diff --git a/common/database/classes/database_alter_default_privileges.php b/common/database/classes/database_alter_default_privileges.php index 478e75a..ecc3116 100644 --- a/common/database/classes/database_alter_default_privileges.php +++ b/common/database/classes/database_alter_default_privileges.php @@ -121,7 +121,7 @@ class c_database_alter_default_priveleges extends c_database_query { $value .= is_null($value) ? '' : ' '; $value .= $this->p_do_build_grant(); - if ($this->grant === e_database_action::ACTION_REVOKE) { + if ($this->grant === e_database_action_deprecated::ACTION_REVOKE) { if ($this->grant_option_for) { $value .= ' ' . $this->p_do_build_grant_option_for(); } @@ -135,10 +135,10 @@ class c_database_alter_default_priveleges extends c_database_query { $value .= ' ' . $this->p_do_build_on(); } - if ($this->grant === e_database_action::GRANT) { + if ($this->grant === e_database_action_deprecated::GRANT) { $value .= ' ' . c_database_string::TO; } - else if ($this->grant === e_database_action::REVOKE) { + else if ($this->grant === e_database_action_deprecated::REVOKE) { $value .= ' ' . c_database_string::FROM; } @@ -146,12 +146,12 @@ class c_database_alter_default_priveleges extends c_database_query { $value .= ' ' . $this->p_do_build_to_role(); } - if ($this->grant === e_database_action::GRANT) { + if ($this->grant === e_database_action_deprecated::GRANT) { if ($this->with_grant_option) { $value .= ' ' . $this->p_do_build_with_grant_option(); } } - else if ($this->grant === e_database_action::REVOKE) { + else if ($this->grant === e_database_action_deprecated::REVOKE) { if (is_int($this->cascade)) { $value .= ' ' . $this->p_do_build_cascade(); } diff --git a/common/database/classes/database_alter_domain.php b/common/database/classes/database_alter_domain.php index adefbd3..28e8f64 100644 --- a/common/database/classes/database_alter_domain.php +++ b/common/database/classes/database_alter_domain.php @@ -8,7 +8,7 @@ namespace n_koopa; require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); -require_once('common/database/enumerations/database_action.php'); +require_once('common/database/enumerations/database_action_deprecated.php'); require_once('common/database/enumerations/database_cascade.php'); require_once('common/database/classes/database_query.php'); @@ -17,19 +17,19 @@ require_once('common/database/traits/database_name.php'); require_once('common/database/traits/database_owner_to.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_action.php'); +require_once('common/database/traits/database_action_deprecated.php'); /** * The class for building and returning a Postgresql ALTER DOMAIN query string. * * @see: https://www.postgresql.org/docs/current/static/sql-alterdomain.html */ -class c_database_alter_coalation extends c_database_query { +class c_database_alter_domain extends c_database_query { use t_database_name; use t_database_owner_to; use t_database_rename_to; use t_database_set_schema; - use t_database_action; + use t_database_action_deprecated; protected const p_QUERY_COMMAND = 'alter domain'; @@ -239,7 +239,7 @@ class c_database_alter_coalation extends c_database_query { $value = $this->p_do_build_name() . ' '; switch ($this->action) { - case e_database_action::ADD: + case e_database_action_deprecated::ADD: if (!is_array($this->constraint)) { unset($value); return new c_base_return_false(); @@ -253,14 +253,14 @@ class c_database_alter_coalation extends c_database_query { } break; - case e_database_action::DROP: + case e_database_action_deprecated::DROP: $value .= c_database_string::DROP; if ($this->property === e_database_property::NOT_NULL) { $value .= ' ' . c_database_string::NOT_NULL; } break; - case e_database_action::DROP_CONSTRAINT: + case e_database_action_deprecated::DROP_CONSTRAINT: if (!is_array($this->constraint['name'])) { unset($value); return new c_base_return_false(); @@ -281,11 +281,11 @@ class c_database_alter_coalation extends c_database_query { } break; - case e_database_action::DROP_DEFAULT: + case e_database_action_deprecated::DROP_DEFAULT: $value .= c_database_string::DROP_DEFAULT; break; - case e_database_action::OWNER_TO: + case e_database_action_deprecated::OWNER_TO: if (!isset($this->owner_to)) { unset($value); return new c_base_return_false(); @@ -294,7 +294,7 @@ class c_database_alter_coalation extends c_database_query { $value .= $this->p_do_build_owner_to(); break; - case e_database_action::RENAME_CONSTRAINT: + case e_database_action_deprecated::RENAME_CONSTRAINT: if (!isset($this->constraint['name']) || !isset($this->constraint['name_new'])) { unset($value); return new c_base_return_false(); @@ -303,7 +303,7 @@ class c_database_alter_coalation extends c_database_query { $value .= c_database_string::RENAME_CONSTRAINT . ' ' . $this->constraint['name'] . ' ' . c_database_string::TO . ' ' . $this->constraint['name_new']; break; - case e_database_action::RENAME_TO: + case e_database_action_deprecated::RENAME_TO: if (!isset($this->rename_to)) { unset($value); return new c_base_return_false(); @@ -312,14 +312,14 @@ class c_database_alter_coalation extends c_database_query { $value .= $this->p_do_build_rename_to(); break; - case e_database_action::SET: + case e_database_action_deprecated::SET: $value = c_database_string::SET; if ($this->property === e_database_property::NOT_NULL) { $value .= ' ' . c_database_string::NOT_NULL; } break; - case e_database_action::SET_DEFAULT: + case e_database_action_deprecated::SET_DEFAULT: if (!isset($this->expression)) { unset($value); return new c_base_return_false(); @@ -328,7 +328,7 @@ class c_database_alter_coalation extends c_database_query { $value .= c_database_string::SET_DEFAULT . ' ' . $this->expression; break; - case e_database_action::SET_SCHEMA: + case e_database_action_deprecated::SET_SCHEMA: if (!isset($this->set_schema)) { unset($value); return new c_base_return_false(); @@ -337,7 +337,7 @@ class c_database_alter_coalation extends c_database_query { $value .= $this->p_do_build_set_schema(); break; - case e_database_action::VALIDATE_CONSTRAINT: + case e_database_action_deprecated::VALIDATE_CONSTRAINT: if (!is_array($this->constraint)) { unset($value); return new c_base_return_false(); diff --git a/common/database/classes/database_alter_event_trigger.php b/common/database/classes/database_alter_event_trigger.php index c609c53..98f4f38 100644 --- a/common/database/classes/database_alter_event_trigger.php +++ b/common/database/classes/database_alter_event_trigger.php @@ -10,7 +10,7 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); -require_once('common/database/traits/database_action.php'); +require_once('common/database/traits/database_action_deprecated.php'); require_once('common/database/traits/database_name.php'); require_once('common/database/traits/database_owner_to.php'); require_once('common/database/traits/database_rename_to.php'); @@ -21,8 +21,8 @@ require_once('common/database/traits/database_rename_to.php'); * @see: https://www.postgresql.org/docs/current/static/sql-altereventtrigger.html */ class c_database_alter_coalation extends c_database_query { - use t_database_action; - use t_database_action_property; + use t_database_action_deprecated; + use t_database_action_property_deprecated; use t_database_name; use t_database_owner_to; use t_database_rename_to; @@ -87,10 +87,10 @@ class c_database_alter_coalation extends c_database_query { $value = $this->p_do_build_name() . ' '; switch($this->action) { - case e_database_action::DISABLE: + case e_database_action_deprecated::DISABLE: $value .= c_database_string::DISABLE; break; - case e_database_action::ENABLE: + case e_database_action_deprecated::ENABLE: $value .= c_database_string::ENABLE; if ($this->action_property === e_database_property::REPLICA) { $value .= ' ' . c_database_string::REPLICA; @@ -103,7 +103,7 @@ class c_database_alter_coalation extends c_database_query { return new c_base_return_false(); } break; - case e_database_action::OWNER_TO: + case e_database_action_deprecated::OWNER_TO: if (isset($this->owner_to)) { $value .= $this->p_do_build_owner_to(); } @@ -112,7 +112,7 @@ class c_database_alter_coalation extends c_database_query { return new c_base_return_false(); } break; - case e_database_action::RENAME_TO: + case e_database_action_deprecated::RENAME_TO: if (isset($this->rename_to)) { $value .= $this->p_do_build_rename_to(); } diff --git a/common/database/classes/database_alter_extension.php b/common/database/classes/database_alter_extension.php index b926be8..248c499 100644 --- a/common/database/classes/database_alter_extension.php +++ b/common/database/classes/database_alter_extension.php @@ -11,7 +11,7 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); require_once('common/database/classes/database_member_object.php'); -require_once('common/database/traits/database_action.php'); +require_once('common/database/traits/database_action_deprecated.php'); require_once('common/database/traits/database_name.php'); @@ -21,7 +21,7 @@ require_once('common/database/traits/database_name.php'); * @see: https://www.postgresql.org/docs/current/static/sql-alterextension.html */ class c_database_alter_extension extends c_database_query { - use t_database_action; + use t_database_action_deprecated; use t_database_action_parameter; use t_database_name; @@ -85,7 +85,7 @@ class c_database_alter_extension extends c_database_query { $value = $this->p_do_build_name() . ' '; switch($this->action) { - case e_database_action::UPDATE: + case e_database_action_deprecated::UPDATE: $value .= c_database_string::UPDATE; if (isset($this->action_parameter)) { $value .= ' ' . c_database_string::TO . ' ' . $this->action_parameter; @@ -95,7 +95,7 @@ class c_database_alter_extension extends c_database_query { return new c_base_return_false(); } break; - case e_database_action::SET_SCHEMA: + case e_database_action_deprecated::SET_SCHEMA: if (isset($this->set_schema)) { $value = $this->p_do_build_set_schema(); } @@ -104,7 +104,7 @@ class c_database_alter_extension extends c_database_query { return new c_base_return_false(); } break; - case e_database_action::ADD: + case e_database_action_deprecated::ADD: $value .= c_database_string::ADD; if ($this->action_parameter instanceof c_database_member_object && $this->action_parameter->do_build() instanceof c_base_return_true) { $value .= ' ' . $this->action_parameter->get_value(); @@ -114,7 +114,7 @@ class c_database_alter_extension extends c_database_query { return new c_base_return_false(); } break; - case e_database_action::DROP: + case e_database_action_deprecated::DROP: $value .= c_database_string::DROP; if ($this->action_parameter instanceof c_database_member_object) { if ($this->action_parameter->do_build() instanceof c_base_return_true) { diff --git a/common/database/classes/database_alter_foreign_data_wrapper.php b/common/database/classes/database_alter_foreign_data_wrapper.php index fc5fd0e..b6cd718 100644 --- a/common/database/classes/database_alter_foreign_data_wrapper.php +++ b/common/database/classes/database_alter_foreign_data_wrapper.php @@ -92,7 +92,7 @@ class c_database_alter_foreign_data_wrapper extends c_database_query { // @fixme: rewrite this. $value = NULL; - if ($this->action === e_database_action::OWNER_TO) { + if ($this->action === e_database_action_deprecated::OWNER_TO) { if (isset($this->owner_to)) { $value = $this->p_do_build_owner_to(); } @@ -101,7 +101,7 @@ class c_database_alter_foreign_data_wrapper extends c_database_query { return new c_base_return_false(); } } - else if ($this->action === e_database_action::RENAME_TO) { + else if ($this->action === e_database_action_deprecated::RENAME_TO) { if (isset($this->rename_to)) { $value = $this->p_do_build_rename_to(); } diff --git a/common/database/classes/database_alter_user.php b/common/database/classes/database_alter_user.php index bf3857e..17359db 100644 --- a/common/database/classes/database_alter_user.php +++ b/common/database/classes/database_alter_user.php @@ -10,14 +10,29 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); +require_once('common/database/traits/database_in_database.php'); +require_once('common/database/traits/database_name.php'); +require_once('common/database/traits/database_rename_to.php'); +require_once('common/database/traits/database_reset_configuration_parameter.php'); +require_once('common/database/traits/database_role_specification.php'); +require_once('common/database/traits/database_set_configuration_parameter.php'); +require_once('common/database/traits/database_with_role_option.php'); /** - * The class for building and returning a Postgresql ALTER COALATION query string. + * The class for building and returning a Postgresql ALTER USER query string. * - * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html + * @see: https://www.postgresql.org/docs/current/static/sql-alteruser.html */ -class c_database_alter_coalation extends c_database_query { - protected const p_QUERY_COMMAND = 'alter coalation'; +class c_database_alter_user extends c_database_query { + use t_database_in_database; + use t_database_name; + use t_database_rename_to; + use t_database_reset_configuration_parameter; + use t_database_role_specification; + use t_database_set_configuration_parameter; + use t_database_with_role_option; + + protected const p_QUERY_COMMAND = 'alter user'; /** @@ -25,12 +40,29 @@ class c_database_alter_coalation extends c_database_query { */ public function __construct() { parent::__construct(); + + $this->in_database = NULL; + $this->name = NULL; + $this->rename_to = NULL; + $this->reset_configuration_parameter = NULL; + $this->role_specification = NULL; + $this->set_configuration_parameter = NULL; + $this->with_role_option = NULL; + } /** * Class destructor. */ public function __destruct() { + unset($this->in_database); + unset($this->name); + unset($this->rename_to); + unset($this->reset_configuration_parameter); + unset($this->role_specification); + unset($this->set_configuration_parameter); + unset($this->with_role_option); + parent::__destruct(); } @@ -59,11 +91,34 @@ class c_database_alter_coalation extends c_database_query { * Implements do_build(). */ public function do_build() { - if (is_null($this->name)) { + if (isset($this->name)) { + if (isset($this->rename_to)) { + $this->value = static::p_QUERY_COMMAND; + $this->value .= ' ' . $this->p_do_build_name(); + $this->value .= ' ' . $this->p_do_build_rename_to(); + return new c_base_return_true(); + } + + return new c_base_return_false(); + } + else if (!isset($this->role_specification)) { return new c_base_return_false(); } - $value = $this->p_do_build_name(); + $value = $this->p_do_build_role_specification(); + + if (isset($this->with_role_option)) { + $value .= ' ' . $this->p_do_build_with_role_option(); + } + else if (isset($this->set_configuration_parameter)) { + $value .= ' ' . $this->p_do_build_set_configuration_parameter(); + } + else if (isset($this->reset_configuration_parameter)) { + $value .= ' ' . $this->p_do_build_reset_configuration_parameter(); + } + else { + return new c_base_return_false(); + } $this->value = static::p_QUERY_COMMAND; $this->value .= ' ' . $value; diff --git a/common/database/classes/database_alter_user_mapping.php b/common/database/classes/database_alter_user_mapping.php index bf3857e..32b84ab 100644 --- a/common/database/classes/database_alter_user_mapping.php +++ b/common/database/classes/database_alter_user_mapping.php @@ -10,27 +10,41 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); +require_once('common/database/traits/database_server_name.php'); +require_once('common/database/traits/database_server_options.php'); +require_once('common/database/traits/database_user_name.php'); /** - * The class for building and returning a Postgresql ALTER COALATION query string. + * The class for building and returning a Postgresql ALTER USER MAPPING query string. * - * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html + * @see: https://www.postgresql.org/docs/current/static/sql-alterusermapping.html */ -class c_database_alter_coalation extends c_database_query { - protected const p_QUERY_COMMAND = 'alter coalation'; +class c_database_alter_user_mapping extends c_database_query { + use t_database_server_name; + use t_database_server_options; + use t_database_user_name; + protected const p_QUERY_COMMAND = 'alter user mapping for'; /** * Class constructor. */ public function __construct() { parent::__construct(); + + $this->server_name = NULL; + $this->server_options = NULL; + $this->user_name = NULL; } /** * Class destructor. */ public function __destruct() { + unset($this->server_name); + unset($this->server_options); + unset($this->user_name); + parent::__destruct(); } @@ -59,14 +73,14 @@ class c_database_alter_coalation extends c_database_query { * Implements do_build(). */ public function do_build() { - if (is_null($this->name)) { + if (!isset($this->user_name) || !isset($this->server_name) || !isset($this->server_options)) { return new c_base_return_false(); } - $value = $this->p_do_build_name(); - $this->value = static::p_QUERY_COMMAND; - $this->value .= ' ' . $value; + $this->value .= ' ' . $this->p_do_build_user_name(); + $this->value .= ' ' . $this->p_do_build_server_name(); + $this->value .= ' ' . $this->p_do_build_server_options(); unset($value); return new c_base_return_true(); diff --git a/common/database/classes/database_member_object.php b/common/database/classes/database_member_object.php index f8c445a..b045f8b 100644 --- a/common/database/classes/database_member_object.php +++ b/common/database/classes/database_member_object.php @@ -12,7 +12,7 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); -require_once('common/database/traits/database_action.php'); +require_once('common/database/traits/database_action_deprecated.php'); require_once('common/database/traits/database_name.php'); /** @@ -21,7 +21,7 @@ require_once('common/database/traits/database_name.php'); * @see: https://www.postgresql.org/docs/current/static/sql-alterextension.html */ class c_database_member_object extends c_database_query { - use t_database_action; + use t_database_action_deprecated; use t_database_action_parameter; use t_database_name; diff --git a/common/database/classes/database_string.php b/common/database/classes/database_string.php index b3359eb..2cd652d 100644 --- a/common/database/classes/database_string.php +++ b/common/database/classes/database_string.php @@ -13,6 +13,7 @@ namespace n_koopa; class c_database_string { public const ACCESS_METHOD = 'access method'; public const ADD = 'add'; + public const ADD_ATTRIBUTE = 'add attribute'; public const ADD_COLUMN = 'add column'; public const ADD_TABLE = 'add table'; public const ADD_VALUE = 'add value'; @@ -21,6 +22,7 @@ class c_database_string { public const ALL = 'all'; public const ALLOW_CONNECTIONS = 'allow_connections'; public const ALTER = 'alter'; + public const ALTER_ATTRIBUTE = 'alter attribute'; public const ALTER_CONSTRAINT = 'alter constraint'; public const AS = 'as'; public const ASCEND = 'asc'; @@ -71,6 +73,7 @@ class c_database_string { public const DISABLE_TRIGGER = 'disable trigger'; public const DOMAIN = 'domain'; public const DROP = 'drop'; + public const DROP_ATTRIBUTE = 'drop attribute'; public const DROP_CONSTRAINT = 'drop constraint'; public const DROP_DEFAULT = 'drop default'; public const DROP_MAPPING = 'drop mapping'; @@ -90,9 +93,9 @@ class c_database_string { public const FALSE = 'false'; public const FASTUPDATE = 'fastupdate'; public const FILLFACTOR = 'fillfactor'; + public const FOR = 'for'; public const FOREIGN_DATA_WRAPPER = 'foreign data wrapper'; public const FOREIGN_TABLE = 'foreign table'; - public const FOR = 'for'; public const FOR_ORDER_BY = 'for order by'; public const FOR_ROLE = 'for role'; public const FOR_SEARCH = 'for search'; @@ -176,9 +179,10 @@ class c_database_string { public const REFRESH = 'refresh'; public const REFRESH_PUBLICATION = 'refresh publication'; public const REFRESH_VERSION = 'refresh version'; - public const RENAME_TO = 'rename to'; + public const RENAME_ATTRIBUTE = 'rename attribute'; public const RENAME_COLUMN = 'rename column'; public const RENAME_CONSTRAINT = 'rename constraint'; + public const RENAME_TO = 'rename to'; public const REPLICA_IDENTITY = 'replica identity'; public const REPLICATION = 'replication'; public const RESET = 'reset'; @@ -202,6 +206,7 @@ class c_database_string { public const SESSION_USER = 'session user'; public const SET = 'set'; public const SET_DATA = 'set data'; + public const SET_DATA_TYPE = 'set data type'; public const SET_DEFAULT = 'set default'; public const SET_LOGGED = 'set logged'; public const SET_PUBLICATION = 'set publication'; @@ -243,7 +248,7 @@ class c_database_string { public const USING_INDEX = 'using index'; public const VALIDATOR = 'validator'; public const VALIDATE_CONSTRAINT = 'validate constraint'; - public const VALIDUNTIL = 'validuntil'; + public const VALID_UNTIL = 'valid until'; public const VARIADIC = 'variadic'; public const VERSION = 'version'; public const VOLATILE = 'volatile'; diff --git a/common/database/enumerations/database_action.php b/common/database/enumerations/database_action_deprecated.php similarity index 96% rename from common/database/enumerations/database_action.php rename to common/database/enumerations/database_action_deprecated.php index b2b722a..52c7e0f 100644 --- a/common/database/enumerations/database_action.php +++ b/common/database/enumerations/database_action_deprecated.php @@ -10,7 +10,7 @@ namespace n_koopa; /** * Codes associated with database actions. */ -class e_database_action { +class e_database_action_deprecated { public const NONE = 0; public const ADD = 1; public const DISABLE = 2; diff --git a/common/database/enumerations/database_attribute_action.php b/common/database/enumerations/database_attribute_action.php new file mode 100644 index 0000000..ad1be60 --- /dev/null +++ b/common/database/enumerations/database_attribute_action.php @@ -0,0 +1,18 @@ +action = NULL; return new c_base_return_true(); } - if (is_int($action)) { - $this->action = $action; - return new c_base_return_true(); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'action', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } - - /** - * Get the currently assigned action. - * - * @return c_base_return_int|c_base_return_null - * Integer representing the action is returned. - * NULL is returned if undefined. - * FALSE with error bit set is returned on error. - */ - protected function get_action() { - if (is_null($this->action)) { - return new c_base_return_null(); + 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); } - return c_base_return_int::s_new($this->action); - } -} - -/** - * Provide action property support for an SQL query. - * - * A single property that is associated with a particular action. - */ -trait t_database_action_property { - protected $action_property; - - /** - * Assigns this query action property. - * - * @param int|null $action_property - * Whether or not to use a action property associated. - * 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_action_property($action_property) { - if (is_null($action_property)) { - $this->action_property = NULL; - return new c_base_return_true(); - } - - if (is_int($action_property)) { - $this->action_property = $action_property; - return new c_base_return_true(); + if (!is_array($this->action)) { + $this->action = []; } - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'action_property', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + $this->action[] = $name; + return new c_base_return_true(); } /** - * Get the currently assigned action property. + * Get the currently assigned settings. * - * @return c_base_return_int|c_base_return_null - * Integer representing the action property is returned. - * NULL is returned if undefined. - * FALSE with error bit set is returned on error. + * @return c_base_return_array|c_base_return_null + * An array of type action names. + * NULL is returned if not set (publication name not to be used). + * NULL with the error bit set is returned on error. */ - protected function get_action_property() { - if (is_null($this->action_property)) { + public function get_action() { + if (is_null($this->action)) { return new c_base_return_null(); } - return c_base_return_int::s_new($this->action_property); - } -} - -/** - * Provide parameter(s) associated with an action or action property support for an SQL query. - * - * A single parameter, a database query object, or an array of parameters that are associated with a particular action or action property. - */ -trait t_database_action_parameter { - protected $action_parameter; - - /** - * Assigns this query action parameter(s). - * - * @param c_base_return_string|c_base_return_array|c_database_query|null $action_parameter - * Whether or not to use a specified action parameter or array of parameters. - * 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_action_parameter($action_parameter) { - if (is_null($action_parameter)) { - $this->action_parameter = NULL; - return new c_base_return_true(); - } - - if (is_string($action_parameter)) { - $this->action_parameter = $action_parameter; - return new c_base_return_true(); - } - - if (is_array($action_parameter)) { - $this->action_parameter = $action_parameter; - return new c_base_return_true(); + if (is_array($this->action)) { + return c_base_return_array::s_new($this->action); } - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'action_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); } /** - * Get the currently assigned action parameter. + * Perform the common build process for this trait. + * + * As an internal trait method, the caller is expected to perform any appropriate validation. * - * @return c_base_return_string|c_base_return_array|c_database_query|c_base_return_null - * String or array representing the action parameters are returned. - * NULL is returned if undefined. - * FALSE with error bit set is returned on error. + * @return string|null + * A string is returned. + * NULL is returned if there is nothing to process or there is an error. */ - protected function get_action_parameter() { - if (is_null($this->action_parameter)) { - return new c_base_return_null(); - } - - if (is_array($this->action_parameter)) { - return c_base_return_array::s_new($this->action_parameter); - } - - if ($this->action_parameter instanceof c_database_query) { - return clone($this->action_parameter); - } - - return c_base_return_string::s_new($this->action_parameter); + protected function p_do_build_action() { + return implode(', ', $this->action); } } diff --git a/common/database/traits/database_action_alter_column_options.php b/common/database/traits/database_action_alter_column_options.php index 3e289a4..600398d 100644 --- a/common/database/traits/database_action_alter_column_options.php +++ b/common/database/traits/database_action_alter_column_options.php @@ -106,32 +106,17 @@ trait t_database_action_alter_column_options { /** * Get the currently assigned settings. * - * @param int|null $index - * (optional) Get the settings at the specified index. - * When NULL, all settings are returned. - * * @return c_base_return_array|c_base_return_null * An array of settings or NULL if not defined. - * A single settings is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_action_alter_column_options($index = NULL) { + public function get_action_alter_column_options() { if (is_null($this->action_alter_column_options)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->action_alter_column_options)) { - return c_base_return_array::s_new($this->action_alter_column_options); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->action_alter_column_options)) { - return c_base_return_array::s_new($this->action_alter_column_options[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_options[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->action_alter_column_options)) { + return c_base_return_array::s_new($this->action_alter_column_options); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_options', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_action_alter_column_reset.php b/common/database/traits/database_action_alter_column_reset.php index 528f2ae..48fb46a 100644 --- a/common/database/traits/database_action_alter_column_reset.php +++ b/common/database/traits/database_action_alter_column_reset.php @@ -73,32 +73,17 @@ trait t_database_action_alter_column_reset { /** * Get the currently assigned settings. * - * @param int|null $index - * (optional) Get the settings at the specified index. - * When NULL, all settings are returned. - * * @return c_base_return_array|c_base_return_null * An array of settings or NULL if not defined. - * A single settings is returned if $index is an integer. * NULL with the error bit reset is returned on error. */ - public function get_action_alter_column_reset($index = NULL) { + public function get_action_alter_column_reset() { if (is_null($this->action_alter_column_reset)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->action_alter_column_reset)) { - return c_base_return_array::s_new($this->action_alter_column_reset); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->action_alter_column_reset)) { - return c_base_return_array::s_new($this->action_alter_column_reset[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_reset[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->action_alter_column_reset)) { + return c_base_return_array::s_new($this->action_alter_column_reset); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_reset', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_action_alter_column_set.php b/common/database/traits/database_action_alter_column_set.php index c744fc1..40725c8 100644 --- a/common/database/traits/database_action_alter_column_set.php +++ b/common/database/traits/database_action_alter_column_set.php @@ -90,32 +90,17 @@ trait t_database_action_alter_column_set { /** * Get the currently assigned settings. * - * @param int|null $index - * (optional) Get the settings at the specified index. - * When NULL, all settings are returned. - * * @return c_base_return_array|c_base_return_null * An array of settings or NULL if not defined. - * A single settings is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_action_alter_column_set($index = NULL) { + public function get_action_alter_column_set() { if (is_null($this->action_alter_column_set)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->action_alter_column_set)) { - return c_base_return_array::s_new($this->action_alter_column_set); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->action_alter_column_set)) { - return c_base_return_array::s_new($this->action_alter_column_set[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_set[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->action_alter_column_set)) { + return c_base_return_array::s_new($this->action_alter_column_set); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_set', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_action_deprecated.php b/common/database/traits/database_action_deprecated.php new file mode 100644 index 0000000..f16850f --- /dev/null +++ b/common/database/traits/database_action_deprecated.php @@ -0,0 +1,184 @@ +action = NULL; + return new c_base_return_true(); + } + + if (is_int($action)) { + $this->action = $action; + return new c_base_return_true(); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'action', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + /** + * Get the currently assigned action. + * + * @return c_base_return_int|c_base_return_null + * Integer representing the action is returned. + * NULL is returned if undefined. + * FALSE with error bit set is returned on error. + */ + protected function get_action() { + if (is_null($this->action)) { + return new c_base_return_null(); + } + + return c_base_return_int::s_new($this->action); + } +} + +/** + * Provide action property support for an SQL query. + * + * A single property that is associated with a particular action. + */ +trait t_database_action_property_deprecated { + protected $action_property; + + /** + * Assigns this query action property. + * + * @param int|null $action_property + * Whether or not to use a action property associated. + * 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_action_property($action_property) { + if (is_null($action_property)) { + $this->action_property = NULL; + return new c_base_return_true(); + } + + if (is_int($action_property)) { + $this->action_property = $action_property; + return new c_base_return_true(); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'action_property', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + /** + * Get the currently assigned action property. + * + * @return c_base_return_int|c_base_return_null + * Integer representing the action property is returned. + * NULL is returned if undefined. + * FALSE with error bit set is returned on error. + */ + protected function get_action_property() { + if (is_null($this->action_property)) { + return new c_base_return_null(); + } + + return c_base_return_int::s_new($this->action_property); + } +} + +/** + * Provide parameter(s) associated with an action or action property support for an SQL query. + * + * A single parameter, a database query object, or an array of parameters that are associated with a particular action or action property. + */ +trait t_database_action_parameter { + protected $action_parameter; + + /** + * Assigns this query action parameter(s). + * + * @param c_base_return_string|c_base_return_array|c_database_query|null $action_parameter + * Whether or not to use a specified action parameter or array of parameters. + * 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_action_parameter($action_parameter) { + if (is_null($action_parameter)) { + $this->action_parameter = NULL; + return new c_base_return_true(); + } + + if (is_string($action_parameter)) { + $this->action_parameter = $action_parameter; + return new c_base_return_true(); + } + + if (is_array($action_parameter)) { + $this->action_parameter = $action_parameter; + return new c_base_return_true(); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'action_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + /** + * Get the currently assigned action parameter. + * + * @return c_base_return_string|c_base_return_array|c_database_query|c_base_return_null + * String or array representing the action parameters are returned. + * NULL is returned if undefined. + * FALSE with error bit set is returned on error. + */ + protected function get_action_parameter() { + if (is_null($this->action_parameter)) { + return new c_base_return_null(); + } + + if (is_array($this->action_parameter)) { + return c_base_return_array::s_new($this->action_parameter); + } + + if ($this->action_parameter instanceof c_database_query) { + return clone($this->action_parameter); + } + + return c_base_return_string::s_new($this->action_parameter); + } +} diff --git a/common/database/traits/database_action_options.php b/common/database/traits/database_action_options.php index a3af7d3..953fc0d 100644 --- a/common/database/traits/database_action_options.php +++ b/common/database/traits/database_action_options.php @@ -93,32 +93,17 @@ trait t_database_action_options { /** * Get the action_options. * - * @param int|null $index - * (optional) Get the action_options at the specified index. - * When NULL, all action_options are returned. - * * @return c_base_return_array|c_base_return_null * An array of action_options arrays or NULL if not defined. - * A single action_options array is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_action_options($index = NULL) { + public function get_action_options() { if (is_null($this->action_options)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->action_options)) { - return c_base_return_array::s_new($this->action_options); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->action_options) && is_array($this->action_options[$index])) { - return c_base_return_array::s_new($this->action_options[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_options[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->action_options)) { + return c_base_return_array::s_new($this->action_options); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_options', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_add_operator_family.php b/common/database/traits/database_add_operator_family.php index efb8e12..f73ca78 100644 --- a/common/database/traits/database_add_operator_family.php +++ b/common/database/traits/database_add_operator_family.php @@ -188,31 +188,19 @@ trait t_database_add_operator_family { /** * Get the add/drop user settings. * - * @param int|null $index - * (optional) Get the argument type array at the specified index. - * When NULL, all argument type are returned. - * * @return c_base_return_array|c_base_return_null - * An array representing the add/drop operator settings at the $index. - * An array representing all add/drop operator settings when $index is NULL. + * An array representing the add/drop operator settings. * NULL is returned if not set (add/drop operator is not to be used). * NULL with the error bit set is returned on error. */ - public function get_add_operator_family($index = NULL) { + public function get_add_operator_family() { if (is_null($this->add_operator_family)) { return new c_base_return_null(); } - if (is_null($index)) { + if (is_array($this->add_operator_family)) { return c_base_return_array::s_new($this->add_operator_family); } - else if (isset($this->add_operator_family['values'][$index]) && is_array($this->add_operator_family['values'][$index])) { - return c_base_return_array::s_new($this->add_operator_family['values'][$index]); - } - else { - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'argument_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_null($error); - } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'add_operator_family', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); return c_base_return_error::s_null($error); diff --git a/common/database/traits/database_add_value.php b/common/database/traits/database_add_value.php index 319ab4c..fd4ed3a 100644 --- a/common/database/traits/database_add_value.php +++ b/common/database/traits/database_add_value.php @@ -131,6 +131,7 @@ trait t_database_add_value { */ protected function p_do_build_add_value() { $value = c_database_string::ADD_VALUE; + // @todo: confirm/deny whether or not the placeholder will be auto-quoted by PDO. $value .= ' \'' . $this->add_value['new_enum_value'] . '\''; if ($this->add_value['if_not_exists']) { @@ -145,6 +146,7 @@ trait t_database_add_value { $value .= ' ' . c_database_string::BEFORE; } + // @todo: confirm/deny whether or not the placeholder will be auto-quoted by PDO. $value .= ' \'' . $this->add_value['neighbor_enum_value'] . '\''; } diff --git a/common/database/traits/database_argument_type.php b/common/database/traits/database_argument_type.php index eceb7e6..6444d6d 100644 --- a/common/database/traits/database_argument_type.php +++ b/common/database/traits/database_argument_type.php @@ -90,33 +90,21 @@ trait t_database_argument_type { } /** - * Get the currently assigned sql argument type at the specified index. - * - * @param int|null $index - * (optional) Get the argument type array at the specified index. - * When NULL, all argument type are returned. + * Get the currently assigned sql argument type. * * @return c_base_return_array|c_base_return_null - * An array representing the argument type at the $index. - * An array representing all argument types when $index is NULL. - * NULL is returned if not set (argument type tablespace is not to be used). + * An array representing all argument types. + * NULL is returned if not set. * NULL with the error bit set is returned on error. */ - public function get_argument_type($index = NULL) { + public function get_argument_type() { if (is_null($this->argument_type)) { return new c_base_return_null(); } - if (is_null($index)) { + if (is_array($this->argument_type)) { return c_base_return_array::s_new($this->argument_type); } - else if (isset($this->argument_type[$index]) && is_array($this->argument_type[$index])) { - return c_base_return_array::s_new($this->argument_type[$index]); - } - else { - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'argument_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_null($error); - } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'argument_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); return c_base_return_error::s_null($error); diff --git a/common/database/traits/database_column_reset.php b/common/database/traits/database_column_reset.php index 38a1285..2167fd3 100644 --- a/common/database/traits/database_column_reset.php +++ b/common/database/traits/database_column_reset.php @@ -83,34 +83,20 @@ trait t_database_column_reset { } /** - * Get the currently assigned COLUMN_RESET attribute option at the specified index. + * Get the currently assigned COLUMN_RESET attribute option. * - * @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). + * @return c_base_return_array|c_base_return_null + * An array of codes representing the argument_type on success. + * NULL is returned if not set. * NULL with the error bit set is returned on error. */ - public function get_column_reset($index = NULL) { + public function get_column_reset() { 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[values][index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->column_reset)) { + return c_base_return_array::s_new($this->column_reset); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_reset', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_column_set.php b/common/database/traits/database_column_set.php index adc7f89..915d1bc 100644 --- a/common/database/traits/database_column_set.php +++ b/common/database/traits/database_column_set.php @@ -92,34 +92,20 @@ trait t_database_column_set { } /** - * 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. + * Get the currently assigned COLUMN .. SET index attribute option. * * @return c_base_return_array|c_base_return_null * An array containing the set index attribute option settings. * 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) { + public function get_column_set() { 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); + if (is_array($this->column_set)) { + return c_base_return_array::s_new($this->column_set); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'column_set', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_drop_table.php b/common/database/traits/database_drop_table.php index 2cb0c7b..d79d380 100644 --- a/common/database/traits/database_drop_table.php +++ b/common/database/traits/database_drop_table.php @@ -78,10 +78,6 @@ trait t_database_drop_value { /** * Get the currently assigned add table settings. * - * @param int|null $index - * (optional) Get the add table settings at the specified index. - * When NULL, all add table settings are returned. - * * @return c_base_return_array|c_base_return_null * An array containing the add table settings. * NULL is returned if not set (add table not to be used). @@ -92,7 +88,7 @@ trait t_database_drop_value { return new c_base_return_null(); } - if (isset($this->drop_value)) { + if (is_array($this->drop_value)) { return c_base_return_array::s_new($this->drop_value); } diff --git a/common/database/traits/database_for_role.php b/common/database/traits/database_for_role.php index 3e97d07..058000f 100644 --- a/common/database/traits/database_for_role.php +++ b/common/database/traits/database_for_role.php @@ -58,32 +58,17 @@ trait t_database_for_role { /** * Get the currently assigned for role value. * - * @param int|null $index - * (optional) Get the for role at the specified index. - * When NULL, all for role values are returned. - * - * @return i_database_query_placeholder|c_base_return_array|c_base_return_null + * @return c_base_return_array|c_base_return_null * An array of for roles or NULL if not defined. - * A single for role query placeholder is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_for_role($index = NULL) { + public function get_for_role() { if (is_null($this->for_role)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->for_role)) { - return c_base_return_array::s_new($this->for_role); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->for_role) && isset($this->for_role[$index])) { - return clone($this->for_role[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'for_role[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->for_role)) { + return c_base_return_array::s_new($this->for_role); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'for_role', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_function_action.php b/common/database/traits/database_function_action.php index db43908..61af3a4 100644 --- a/common/database/traits/database_function_action.php +++ b/common/database/traits/database_function_action.php @@ -149,7 +149,7 @@ trait t_database_function_action { * NULL is returned if not set (function action tablespace is not to be used). * NULL with the error bit set is returned on error. */ - public function get_function_action($index = NULL) { + public function get_function_action() { if (is_null($this->function_action)) { return new c_base_return_null(); } diff --git a/common/database/traits/database_group_by.php b/common/database/traits/database_group_by.php index 6fa16c2..862c541 100644 --- a/common/database/traits/database_group_by.php +++ b/common/database/traits/database_group_by.php @@ -60,32 +60,17 @@ trait t_database_group_by { /** * Get the currently assigned for group by value. * - * @param int|null $index - * (optional) Get the group by at the specified index. - * When NULL, all group by values are returned. - * - * @return i_database_query_placeholder|c_base_return_array|c_base_return_null + * @return c_base_return_array|c_base_return_null * An array of group by values or NULL if not defined. - * A single group by query placeholder is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_group_by($index = NULL) { + public function get_group_by() { if (is_null($this->group_by)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->group_by)) { - return c_base_return_array::s_new($this->group_by); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->group_by) && isset($this->group_by[$index])) { - return clone($this->group_by[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'group_by[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->group_by)) { + return c_base_return_array::s_new($this->group_by); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'group_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_in_schema.php b/common/database/traits/database_in_schema.php index 6481158..574c824 100644 --- a/common/database/traits/database_in_schema.php +++ b/common/database/traits/database_in_schema.php @@ -59,32 +59,17 @@ trait t_database_in_schema { /** * Get the in schema, schema names. * - * @param int|null $index - * (optional) Get the schema name at the specified index. - * When NULL, all schema names are returned. - * - * @return i_database_query_placeholder|c_base_return_array|c_base_return_null + * @return c_base_return_array|c_base_return_null * An array of schema names or NULL if not defined. - * A single schema name query placeholder is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_in_schema($index = NULL) { + public function get_in_schema() { if (is_null($this->in_schema)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->in_schema)) { - return c_base_return_array::s_new($this->in_schema); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->in_schema) && isset($this->in_schema[$index])) { - return clone($this->in_schema[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'in_schema[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->in_schema)) { + return c_base_return_array::s_new($this->in_schema); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'in_schema', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_options.php b/common/database/traits/database_options.php index 16633c1..185b67b 100644 --- a/common/database/traits/database_options.php +++ b/common/database/traits/database_options.php @@ -93,32 +93,17 @@ trait t_database_options { /** * Get the options. * - * @param int|null $index - * (optional) Get the options at the specified index. - * When NULL, all options are returned. - * * @return c_base_return_array|c_base_return_null * An array of options arrays or NULL if not defined. - * A single options array is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_options($index = NULL) { + public function get_options() { if (is_null($this->options)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->options)) { - return c_base_return_array::s_new($this->options); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->options) && is_array($this->options[$index])) { - return c_base_return_array::s_new($this->options[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'options[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->options)) { + return c_base_return_array::s_new($this->options); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'options', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_order_by.php b/common/database/traits/database_order_by.php index 7fb7ff0..59e1241 100644 --- a/common/database/traits/database_order_by.php +++ b/common/database/traits/database_order_by.php @@ -58,32 +58,17 @@ trait t_database_order_by { /** * Get the currently assigned for group by value. * - * @param int|null $index - * (optional) Get the group by at the specified index. - * When NULL, all group by values are returned. - * - * @return i_database_query_placeholder|c_base_return_array|c_base_return_null + * @return c_base_return_array|c_base_return_null * An array of group by values or NULL if not defined. - * A single group by query placeholder is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_order_by($index = NULL) { + public function get_order_by() { if (is_null($this->order_by)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->order_by)) { - return c_base_return_array::s_new($this->order_by); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->order_by) && isset($this->order_by[$index])) { - return clone($this->order_by[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'order_by[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->order_by)) { + return c_base_return_array::s_new($this->order_by); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'order_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_owned_by.php b/common/database/traits/database_owned_by.php index b96a8b7..d963783 100644 --- a/common/database/traits/database_owned_by.php +++ b/common/database/traits/database_owned_by.php @@ -62,43 +62,22 @@ trait t_database_owned_by { } /** - * Get the owned_by. + * Get the owned by settings. * - * @param int|null $index - * (optional) Get the owned_by at the specified index. - * When NULL, all owned_by are returned. - * - * @return c_base_return_int|i_database_query_placeholder|c_base_return_array|c_base_return_null + * @return 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. */ - public function get_owned_by($index = NULL) { + public function get_owned_by() { if (is_null($this->owned_by)) { return new c_base_return_null(); } - if (is_null($index)) { - if ($this->owned_by === e_database_user::ALL || $this->owned_by === e_database_user::NONE) { - 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); - } + if ($this->owned_by === e_database_user::ALL || $this->owned_by === e_database_user::NONE) { + return c_base_return_array::s_new([$this->owned_by]); } - 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 (isset($this->owned_by[$index])) { - return clone($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); - } + else if (is_array($this->owned_by)) { + return c_base_return_array::s_new($this->owned_by); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'owned_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_privilege.php b/common/database/traits/database_privilege.php index 9cf3c48..5e4cc96 100644 --- a/common/database/traits/database_privilege.php +++ b/common/database/traits/database_privilege.php @@ -63,35 +63,20 @@ trait t_database_privilege { /** * Get the privileges. * - * @param int|null $index - * (optional) Get the privilege at the specified index. - * When NULL, all privileges are returned. - * - * @return c_base_return_int|c_base_return_array|c_base_return_null + * @return c_base_return_array|c_base_return_null * An array of privileges or NULL if not defined. - * A single privilege is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_privilege($index = NULL) { + public function get_privilege() { if (is_null($this->privilege)) { return new c_base_return_null(); } - if (is_null($index)) { - if ($this->privilege === e_database_privilege::ALL) { - return c_base_return_array::s_new([$this->privilege]); - } - else if (is_array($this->privilege)) { - return c_base_return_array::s_new($this->privilege); - } + if ($this->privilege === e_database_privilege::ALL) { + return c_base_return_array::s_new([$this->privilege]); } - else { - if (is_int($index) && array_key_exists($index, $this->privilege) && is_int($this->privilege[$index])) { - return clone($this->privilege[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'privilege[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + else if (is_array($this->privilege)) { + return c_base_return_array::s_new($this->privilege); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'privilege', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_refresh_publication.php b/common/database/traits/database_refresh_publication.php index 9133168..08e227b 100644 --- a/common/database/traits/database_refresh_publication.php +++ b/common/database/traits/database_refresh_publication.php @@ -52,7 +52,7 @@ trait t_database_refresh_publication { * NULL is returned if not set (refresh publication not to be used). * NULL with the error bit set is returned on error. */ - public function get_refresh_publication($index = NULL) { + public function get_refresh_publication() { if (is_null($this->refresh_publication)) { return new c_base_return_null(); } diff --git a/common/database/traits/database_rename_attribute.php b/common/database/traits/database_rename_attribute.php new file mode 100644 index 0000000..c7f6268 --- /dev/null +++ b/common/database/traits/database_rename_attribute.php @@ -0,0 +1,130 @@ +rename_attribute = NULL; + return new c_base_return_true(); + } + + if (!is_string($from)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'from', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($to)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'to', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + switch ($cascade) { + case e_database_cascade::CASCADE: + case e_database_cascade::RESTRICT: + case NULL: + break; + default: + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'cascade', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $placeholder_from = $this->add_placeholder($from); + if ($placeholder_from->has_error()) { + return c_base_return_error::s_false($placeholder_from->get_error()); + } + + $placeholder_to = $this->add_placeholder($to); + if ($placeholder_to->has_error()) { + unset($placeholder_from); + return c_base_return_error::s_false($placeholder_to->get_error()); + } + + $this->rename_attribute = [ + 'from' => $placeholder_from, + 'to' => $placeholder_to, + 'cascade' => $cascade, + ]; + unset($placeholder_from); + unset($placeholder_to); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned nsettings. + * + * @return c_database_return_array|c_base_return_null + * An array containing the settings. + * NULL is returned if not set (rename to is not to be used). + * NULL with the error bit set is returned on error. + */ + public function get_rename_attribute() { + if (is_null($this->rename_attribute)) { + return new c_base_return_null(); + } + + if (is_array($this->rename_attribute)) { + return c_database_return_array::s_new($this->rename_attribute); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'rename_attribute', ':{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. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_rename_attribute() { + $value = c_database_string::RENAME_ATTRIBUTE; + $value .= ' ' . $this->rename_attribute['from']; + $value .= ' ' . c_database_string::TO; + $value .= ' ' . $this->rename_attribute['to']; + + if ($this->rename_attribute['cascade'] === e_database_cascade::CASCADE) { + $value .= ' ' . c_database_string::CASCADE; + } + else if ($this->rename_attribute['cascade'] === e_database_cascade::RESTRICT) { + $value .= ' ' . c_database_string::RESTRICT; + } + + return $value; + } +} diff --git a/common/database/traits/database_rename_value.php b/common/database/traits/database_rename_value.php new file mode 100644 index 0000000..dacd220 --- /dev/null +++ b/common/database/traits/database_rename_value.php @@ -0,0 +1,109 @@ +rename_value = NULL; + return new c_base_return_true(); + } + + if (!is_string($from)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'from', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($to)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'to', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $placeholder_from = $this->add_placeholder($from); + if ($placeholder_from->has_error()) { + return c_base_return_error::s_false($placeholder_from->get_error()); + } + + $placeholder_to = $this->add_placeholder($to); + if ($placeholder_to->has_error()) { + unset($placeholder_from); + return c_base_return_error::s_false($placeholder_to->get_error()); + } + + $this->rename_value = [ + 'from' => $placeholder_from, + 'to' => $placeholder_to, + ]; + unset($placeholder_from); + unset($placeholder_to); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned nsettings. + * + * @return c_database_return_array|c_base_return_null + * An array containing the settings. + * NULL is returned if not set (rename to is not to be used). + * NULL with the error bit set is returned on error. + */ + public function get_rename_value() { + if (is_null($this->rename_value)) { + return new c_base_return_null(); + } + + if (is_array($this->rename_value)) { + return c_database_return_array::s_new($this->rename_value); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'rename_value', ':{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. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_rename_value() { + $value = c_database_string::RENAME_ATTRIBUTE; + $value .= ' ' . $this->rename_value['from']; + $value .= ' ' . c_database_string::TO; + $value .= ' ' . $this->rename_value['to']; + return $value; + } +} diff --git a/common/database/traits/database_reset_storage_parameter.php b/common/database/traits/database_reset_storage_parameter.php index cb4fcbf..24feada 100644 --- a/common/database/traits/database_reset_storage_parameter.php +++ b/common/database/traits/database_reset_storage_parameter.php @@ -60,34 +60,20 @@ trait t_database_reset_storage_parameter { } /** - * Get the currently assigned RESET storage parameter at the specified index. - * - * @param int|null $index - * (optional) Get the index storage parameter type at the specified index. - * When NULL, all index storage parameter types are returned. + * Get the currently assigned RESET storage parameter. * * @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 (reset_storage_parameter tablespace is not to be used). * NULL with the error bit set is returned on error. */ - public function get_reset_storage_parameter($index = NULL) { + public function get_reset_storage_parameter() { if (is_null($this->reset_storage_parameter)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->reset_storage_parameter)) { - return c_base_return_array::s_new($this->reset_storage_parameter); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->reset_storage_parameter) && is_int($this->reset_storage_parameter[$index])) { - return c_base_return_int::s_new($this->reset_storage_parameter[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'reset_storage_parameter[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->reset_storage_parameter)) { + return c_base_return_array::s_new($this->reset_storage_parameter); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'reset_storage_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_role_specification.php b/common/database/traits/database_role_specification.php index 186621b..79a782c 100644 --- a/common/database/traits/database_role_specification.php +++ b/common/database/traits/database_role_specification.php @@ -66,7 +66,7 @@ trait t_database_role_specification { * NULL is returned if not set. * NULL with the error bit set is returned on error. */ - public function get_role_specification($index = NULL) { + public function get_role_specification() { if (is_null($this->role_specification)) { return new c_base_return_null(); } diff --git a/common/database/traits/database_server_name.php b/common/database/traits/database_server_name.php new file mode 100644 index 0000000..44da055 --- /dev/null +++ b/common/database/traits/database_server_name.php @@ -0,0 +1,85 @@ +server_name = NULL; + return new c_base_return_true(); + } + + if (is_string($name)) { + $placeholder = $this->add_placeholder($name); + if ($placeholder->has_error()) { + return c_base_return_error::s_false($placeholder->get_error()); + } + + $this->server_name = $placeholder; + unset($placeholder); + + return new c_base_return_true(); + } + + $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); + } + + /** + * Get the currently assigned server name. + * + * @return i_database_query_placeholder|c_base_return_null + * A server name query placeholder on success. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_server_name() { + if (is_null($this->server_name)) { + return new c_base_return_null(); + } + + if (isset($this->server_name)) { + return clone($this->server_name); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'server_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. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_server_name() { + return c_database_string::SERVER . ' ' . $this->server_name; + } +} diff --git a/common/database/traits/database_server_options.php b/common/database/traits/database_server_options.php new file mode 100644 index 0000000..01d9f32 --- /dev/null +++ b/common/database/traits/database_server_options.php @@ -0,0 +1,161 @@ +server_options = NULL; + return new c_base_return_true(); + } + + switch ($option) { + case server_option::ADD: + case server_option::DROP: + case server_option::SET: + break; + default: + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'option', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + 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); + } + + $placeholder_name = $this->add_placeholder($value); + if ($placeholder_name->has_error()) { + return c_base_return_error::s_false($placeholder_name->get_error()); + } + + $placeholder_value = NULL; + if (!is_null($value)) { + if (!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); + } + + $placeholder_value = $this->add_placeholder($value); + if ($placeholder_value->has_error()) { + return c_base_return_error::s_false($placeholder_value->get_error()); + } + } + + if (!is_array($this->server_options)) { + $this->server_options = []; + } + + $this->server_options[] = [ + 'option' => $option, + 'name' => $placeholder_name, + 'value' => $placeholder_value, + ]; + unset($placeholder_name); + unset($placeholder_value); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned WITH refresh option. + * + * @return c_base_return_array|c_base_return_null + * An array containing the with server option settings. + * NULL is returned if not set (with refresh option not to be used). + * NULL with the error bit set is returned on error. + */ + public function get_server_options() { + if (is_null($this->server_options)) { + return new c_base_return_null(); + } + + if (is_array($this->server_options)) { + return c_base_return_array::s_new($this->server_options); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'server_options', ':{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. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_server_options() { + $values = []; + foreach ($this->server_options as $option) { + if ($parameter === server_option::ADD) { + $value = c_database_string::ADD . ' ='; + $value .= ' ' . $option['name']; + + if (isset($option['value'])) { + $value .= ' ' . $option['value']; + } + + $values[] = $value; + } + else if ($parameter === server_option::DROP) { + $value = c_database_string::DROP; + $value .= ' ' . $option['name']; + $values[] = $value; + } + else if ($parameter === server_option::SET) { + $value = c_database_string::SET . ' ='; + $value .= ' ' . $option['name']; + + if (isset($option['value'])) { + $value .= ' ' . $option['value']; + } + + $values[] = $value; + } + } + unset($option); + unset($value); + + return c_database_string::OPTIONS . ' (' . implode(', ', $values) . ')'; + } +} diff --git a/common/database/traits/database_set_operator.php b/common/database/traits/database_set_operator.php index 952802d..60af5a0 100644 --- a/common/database/traits/database_set_operator.php +++ b/common/database/traits/database_set_operator.php @@ -80,32 +80,17 @@ trait t_database_set_operator { /** * Get the (operator) SET values. * - * @param int|null $index - * (optional) Get the set parameter and value at the specified index. - * When NULL, all parameters and values are returned. - * * @return c_base_return_array|c_base_return_null * An array of parameters and values or NULL if not defined. - * A single parameters and value array is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_set_operator($index = NULL) { + public function get_set_operator() { if (is_null($this->set_operator)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->set_operator)) { - return c_base_return_array::s_new($this->set_operator); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->set_operator)) { - return c_base_return_array::s_new($this->set_operator[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_operator[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->set_operator)) { + return c_base_return_array::s_new($this->set_operator); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_operator', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_set_publication_name.php b/common/database/traits/database_set_publication_name.php index 72e0326..06f993d 100644 --- a/common/database/traits/database_set_publication_name.php +++ b/common/database/traits/database_set_publication_name.php @@ -49,34 +49,20 @@ trait t_database_set_publication_name { } /** - * Get the currently assigned SET PUBLICATION name at the specified index. + * Get the currently assigned SET PUBLICATION name. * - * @param int|null $index - * (optional) Get the publication name at the specified index. - * When NULL, all publication names are returned. - * - * @return c_base_return_array|c_base_return_string|c_base_return_null - * An array of publication names or a string representing the publication name at $index.. - * NULL is returned if not set (publication name not to be used). + * @return c_base_return_array|c_base_return_null + * An array of publication names. + * NULL is returned if not set. * NULL with the error bit set is returned on error. */ - public function get_set_publication_name($index = NULL) { + public function get_set_publication_name() { if (is_null($this->set_publication_name)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->set_publication_name)) { - return c_base_return_array::s_new($this->set_publication_name); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->set_publication_name)) { - return c_base_return_string::s_new($this->set_publication_name[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_publication_name[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->set_publication_name)) { + return c_base_return_array::s_new($this->set_publication_name); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_publication_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_set_publication_parameter.php b/common/database/traits/database_set_publication_parameter.php index 6f3629a..040efe0 100644 --- a/common/database/traits/database_set_publication_parameter.php +++ b/common/database/traits/database_set_publication_parameter.php @@ -74,34 +74,20 @@ trait t_database_set_publication_parameter { } /** - * Get the currently assigned SET publication parameter at the specified index. - * - * @param int|null $index - * (optional) Get the publication parameter type at the specified index. - * When NULL, all publication parameter types are returned. + * Get the currently assigned SET publication parameter. * * @return c_base_return_array|c_base_return_null * An array containing the set publication parameter settings. * NULL is returned if not set (publication parameter not to be used). * NULL with the error bit set is returned on error. */ - public function get_set_publication_parameter($index = NULL) { + public function get_set_publication_parameter() { if (is_null($this->set_publication_parameter)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->set_publication_parameter)) { - return c_base_return_array::s_new($this->set_publication_parameter); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->set_publication_parameter)) { - return c_base_return_array::s_new($this->set_publication_parameter[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_publication_parameter[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->set_publication_parameter)) { + return c_base_return_array::s_new($this->set_publication_parameter); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_publication_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_set_storage_parameter.php b/common/database/traits/database_set_storage_parameter.php index 4c04a4e..48e002a 100644 --- a/common/database/traits/database_set_storage_parameter.php +++ b/common/database/traits/database_set_storage_parameter.php @@ -79,34 +79,20 @@ trait t_database_set_storage_parameter { } /** - * Get the currently assigned SET index storage parameter at the specified index. - * - * @param int|null $index - * (optional) Get the index storage parameter type at the specified index. - * When NULL, all index storage parameter types are returned. + * Get the currently assigned SET index storage parameter. * * @return c_base_return_array|c_base_return_null * An array containing the set index storage parameter settings. - * NULL is returned if not set (set index storage parameter not to be used). + * NULL is returned if not set. * NULL with the error bit set is returned on error. */ - public function get_set_storage_parameter($index = NULL) { + public function get_set_storage_parameter() { if (is_null($this->set_storage_parameter)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->set_storage_parameter)) { - return c_base_return_array::s_new($this->set_storage_parameter); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->set_storage_parameter)) { - return c_base_return_array::s_new($this->set_storage_parameter[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_storage_parameter[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->set_storage_parameter)) { + return c_base_return_array::s_new($this->set_storage_parameter); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_storage_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_set_table.php b/common/database/traits/database_set_table.php index 63aaa32..89f761b 100644 --- a/common/database/traits/database_set_table.php +++ b/common/database/traits/database_set_table.php @@ -78,13 +78,9 @@ trait t_database_set_table { /** * Get the currently assigned add table settings. * - * @param int|null $index - * (optional) Get the add table settings at the specified index. - * When NULL, all add table settings are returned. - * * @return c_base_return_array|c_base_return_null * An array containing the add table settings. - * NULL is returned if not set (add table not to be used). + * NULL is returned if not set. * NULL with the error bit set is returned on error. */ public function get_set_table() { @@ -92,7 +88,7 @@ trait t_database_set_table { return new c_base_return_null(); } - if (isset($this->set_table)) { + if (is_array($this->set_table)) { return c_base_return_array::s_new($this->set_table); } diff --git a/common/database/traits/database_to_role.php b/common/database/traits/database_to_role.php index 7bbfff7..6ef7499 100644 --- a/common/database/traits/database_to_role.php +++ b/common/database/traits/database_to_role.php @@ -76,32 +76,17 @@ trait t_database_to_role { /** * Get the in schema, to roles. * - * @param int|null $index - * (optional) Get the schema name at the specified index. - * When NULL, all to roles are returned. - * * @return c_base_return_array|c_base_return_null * An array of to role arrays or NULL if not defined. - * A single to role array is returned if $index is an integer. * NULL with the error bit set is returned on error. */ - public function get_to_role($index = NULL) { + public function get_to_role() { if (is_null($this->to_role)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->to_role)) { - return c_base_return_array::s_new($this->to_role); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->to_role)) { - return c_base_return_array::s_new($this->to_role[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'to_role[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->to_role)) { + return c_base_return_array::s_new($this->to_role); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'to_role', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_type_action.php b/common/database/traits/database_type_action.php new file mode 100644 index 0000000..ed2a4c9 --- /dev/null +++ b/common/database/traits/database_type_action.php @@ -0,0 +1,215 @@ +type_action = NULL; + return new c_base_return_true(); + } + + $placeholder = $this->add_placeholder($name); + if ($placeholder->has_error()) { + return c_base_return_error::s_false($placeholder->get_error()); + } + + $type_action = [ + 'attribute' => $attribute, + 'name' => $placeholder, + 'cascade' => NULL, + 'type' => NULL, + 'collation' => NULL, + 'if_exists' => NULL, + ]; + unset($placeholder); + + if ($attribute === e_database_attribute_action::ADD) { + if (is_null($collation)) { + $placeholder = NULL; + } + else if (is_string($collation)) { + $placeholder = $this->add_placeholder($collation); + if ($placeholder->has_error()) { + unset($type_action); + return c_base_return_error::s_false($placeholder->get_error()); + } + } + else { + unset($type_action); + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'collation', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $type_action['collation'] = $placeholder; + } + else if ($attribute === e_database_attribute_action::ALTER) { + if (is_null($collation)) { + $placeholder = NULL; + } + else if (is_string($collation)) { + $placeholder = $this->add_placeholder($collation); + if ($placeholder->has_error()) { + unset($type_action); + return c_base_return_error::s_false($placeholder->get_error()); + } + } + else { + unset($type_action); + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'collation', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $type_action['collation'] = $placeholder; + } + else if ($attribute === e_database_attribute_action::DROP) { + if (!is_null($if_exists) && !is_bool($if_exists)) { + unset($type_action); + $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); + } + + $type_action['if_exists'] = $if_exists; + } + else { + unset($type_action); + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'attribute', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + 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($cascade) { + case e_database_cascade::CASCADE: + case e_database_cascade::RESTRICT: + break; + default: + unset($type_action); + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'cascade', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->type_action = $type_action; + + return new c_base_return_true(); + } + + /** + * Get the currently assigned settings. + * + * @return c_base_return_array|c_base_return_null + * An array of type settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_type_action() { + if (is_null($this->type_action)) { + return new c_base_return_null(); + } + + if (is_array($this->type_action)) { + return c_base_return_array::s_new($this->type_action); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'type_action', ':{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. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_type_action() { + $value = NULL; + + if ($this->type_action['attribute'] === e_database_attribute_action::ADD) { + $value = c_database_string::ADD_ATTRIBUTE; + $value .= ' ' . $this->type_action['name']; + $value .= ' ' . $this->type_action['data_type']; + + if (isset($this->type_action['collation'])) { + $value .= ' ' . c_database_string::COLLATE; + $value .= ' ' . $this->type_action['collation']; + } + } + else if ($this->type_action['attribute'] === e_database_attribute_action::ALTER) { + $value = c_database_string::ALTER_ATTRIBUTE; + $value .= ' ' . $this->type_action['name']; + $value .= ' ' . c_database_string::SET_DATA_TYPE; + $value .= ' ' . $this->type_action['data_type']; + + if (isset($this->type_action['collation'])) { + $value .= ' ' . c_database_string::COLLATE; + $value .= ' ' . $this->type_action['collation']; + } + } + else if ($this->type_action['attribute'] === e_database_attribute_action::DROP) { + $value = c_database_string::DROP_ATTRIBUTE; + if ($this->type_action['if_exists']) { + $value .= ' ' . c_database_string::IF_EXISTS; + } + + $value .= ' ' . $this->type_action['name']; + } + + if ($this->type_action['cascade'] === c_database_string::CASCADE) { + $value .= ' ' . c_database_string::CASCADE; + } + else if ($this->type_action['cascade'] === c_database_string::RESTRICT) { + $value .= ' ' . c_database_string::RESTRICT; + } + + return $value; + } +} diff --git a/common/database/traits/database_user_name.php b/common/database/traits/database_user_name.php new file mode 100644 index 0000000..936e87a --- /dev/null +++ b/common/database/traits/database_user_name.php @@ -0,0 +1,121 @@ +user_name = NULL; + return new c_base_return_true(); + } + + switch ($type) { + case e_database_user::CURRENT: + case e_database_user::PUBLIC: + case e_database_user::SESSION: + $placeholder = NULL; + break; + case e_database_user::NAME: + 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); + } + + $placeholder = $this->add_placeholder($name); + if ($placeholder->has_error()) { + return c_base_return_error::s_false($placeholder->get_error()); + } + 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->user_name = [ + 'type' => $type, + 'name' => $placeholder, + ]; + unset($placeholder); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned settings. + * + * @return c_base_return_array|c_base_return_null + * An array of type settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_user_name() { + if (is_null($this->user_name)) { + return new c_base_return_null(); + } + + if (is_array($this->user_name)) { + return c_base_return_array::s_new($this->user_name); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'user_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. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_user_name() { + $value = NULL; + + if ($this->user_name['type'] === e_database_user::CURRENT) { + $value = c_database_string::CURRENT_USER; + } + else if ($this->user_name['type'] === e_database_user::PUBLIC) { + $value = c_database_string::PUBLIC; + } + else if ($this->user_name['type'] === e_database_user::SESSION) { + $value = c_database_string::SESSION_USER; + } + else if ($this->user_name['type'] === e_database_user::NAME) { + $value = $this->user_name['name']; + } + + return $value; + } +} diff --git a/common/database/traits/database_with_publication_option.php b/common/database/traits/database_with_publication_option.php index 48eb368..34610fc 100644 --- a/common/database/traits/database_with_publication_option.php +++ b/common/database/traits/database_with_publication_option.php @@ -68,34 +68,20 @@ trait t_database_with_publication_option { } /** - * Get the currently assigned WITH publication option at the specified index. - * - * @param int|null $index - * (optional) Get the publication options at the specified index. - * When NULL, all publication options are returned. + * Get the currently assigned WITH publication option. * * @return c_base_return_array|c_base_return_null * An array containing the with publication option settings. - * NULL is returned if not set (with publication option not to be used). + * NULL is returned if not set. * NULL with the error bit set is returned on error. */ - public function get_with_publication_option($index = NULL) { + public function get_with_publication_option() { if (is_null($this->with_publication_option)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->with_publication_option)) { - return c_base_return_array::s_new($this->with_publication_option); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->with_publication_option)) { - return c_base_return_array::s_new($this->with_publication_option[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_publication_option[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->with_publication_option)) { + return c_base_return_array::s_new($this->with_publication_option); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_publication_option', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_with_refresh_option.php b/common/database/traits/database_with_refresh_option.php index 8c0cfed..48bc402 100644 --- a/common/database/traits/database_with_refresh_option.php +++ b/common/database/traits/database_with_refresh_option.php @@ -68,34 +68,20 @@ trait t_database_with_refresh_option { } /** - * Get the currently assigned WITH refresh option at the specified index. - * - * @param int|null $index - * (optional) Get the refresh options at the specified index. - * When NULL, all refresh options are returned. + * Get the currently assigned WITH refresh option. * * @return c_base_return_array|c_base_return_null * An array containing the with refresh option settings. - * NULL is returned if not set (with refresh option not to be used). + * NULL is returned if not set. * NULL with the error bit set is returned on error. */ - public function get_with_refresh_option($index = NULL) { + public function get_with_refresh_option() { if (is_null($this->with_refresh_option)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->with_refresh_option)) { - return c_base_return_array::s_new($this->with_refresh_option); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->with_refresh_option)) { - return c_base_return_array::s_new($this->with_refresh_option[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_refresh_option[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->with_refresh_option)) { + return c_base_return_array::s_new($this->with_refresh_option); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_refresh_option', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); diff --git a/common/database/traits/database_with_role_option.php b/common/database/traits/database_with_role_option.php index cede4b1..8ea1c07 100644 --- a/common/database/traits/database_with_role_option.php +++ b/common/database/traits/database_with_role_option.php @@ -76,7 +76,7 @@ trait t_database_with_role_option { case e_database_role_option::PASSWORD: case e_database_role_option::PASSWORD_ENCRYPTED: - case e_database_role_option::VALIDUNTIL: + case e_database_role_option::VALID_UNTIL: if (is_string($value)) { $placeholder = $this->add_placeholder($value); if ($placeholder->has_error()) { @@ -194,8 +194,8 @@ trait t_database_with_role_option { else if ($role_option['type'] === e_database_role_option::PASSWORD_ENCRYPTED) { $values[] = c_database_string::PASSWORD_ENCRYPTED . ' ' . $role_option['value']; } - else if ($role_option['type'] === e_database_role_option::VALIDUNTIL) { - $values[] = c_database_string::VALIDUNTIL . ' ' . $role_option['value']; + else if ($role_option['type'] === e_database_role_option::VALID_UNTIL) { + $values[] = c_database_string::VALID_UNTIL . ' ' . $role_option['value']; } } unset($role_option); diff --git a/common/database/traits/database_with_storage_parameter.php b/common/database/traits/database_with_storage_parameter.php index 5fca01f..e2eb5a9 100644 --- a/common/database/traits/database_with_storage_parameter.php +++ b/common/database/traits/database_with_storage_parameter.php @@ -79,34 +79,20 @@ trait t_database_with_storage_parameter { } /** - * Get the currently assigned WITH index storage parameter at the specified index. - * - * @param int|null $index - * (optional) Get the index storage parameter type at the specified index. - * When NULL, all index storage parameter types are returned. + * Get the currently assigned WITH index storage parameter. * * @return c_base_return_array|c_base_return_null * An array containing the set index storage parameter settings. * NULL is returned if not set (set index storage parameter not to be used). * NULL with the error bit set is returned on error. */ - public function get_with_storage_parameter($index = NULL) { + public function get_with_storage_parameter() { if (is_null($this->with_storage_parameter)) { return new c_base_return_null(); } - if (is_null($index)) { - if (is_array($this->with_storage_parameter)) { - return c_base_return_array::s_new($this->with_storage_parameter); - } - } - else { - if (is_int($index) && array_key_exists($index, $this->with_storage_parameter)) { - return c_base_return_array::s_new($this->with_storage_parameter[$index]); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_storage_parameter[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + if (is_array($this->with_storage_parameter)) { + return c_base_return_array::s_new($this->with_storage_parameter); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_storage_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); -- 1.8.3.1