From: Kevin Day Date: Thu, 17 Jan 2019 05:12:45 +0000 (-0600) Subject: Progress: continue development on database abstraction X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=eec4dcabf3c494a43a09d5a1b017f9fba9435785;p=koopa Progress: continue development on database abstraction --- diff --git a/common/base/classes/base_database.php b/common/base/classes/base_database.php index 4b5ba9e..ca79c73 100644 --- a/common/base/classes/base_database.php +++ b/common/base/classes/base_database.php @@ -1494,7 +1494,7 @@ class c_base_database extends c_base_return { * Instead, use pg_escape_bytea() or a large object function. * * @return c_base_database_result - * Query resource is returned on success. + * Query resource is returned. * Query resource with the error bit set is returned on error. * * @see: self::execute() @@ -1596,7 +1596,7 @@ class c_base_database extends c_base_return { * The query statement to execute. * * @return c_base_database_result - * Query resource is returned on success. + * Query resource is returned. * Query resource with error bit set is returned on error. * * @see: self::execute() @@ -1666,7 +1666,7 @@ class c_base_database extends c_base_return { * This is only useful when a query is asynchronous. * * @return c_base_database_result - * A database result is returned on success. + * A database result is returned. * A database result with the error bit set is returned on error. */ public function get_result() { @@ -1726,7 +1726,7 @@ class c_base_database extends c_base_return { * This design, however, means that only a single a synchronous query operation may be performed at any given time. * * @return c_base_return_status - * TRUE is returned on success. + * TRUE is returned. * FALSE is returned on failure. * When asynchronous is not enabled, FALSE is returned without an error flag set. * @@ -1785,7 +1785,7 @@ class c_base_database extends c_base_return { * * @return c_base_return_status|c_base_return_string * TRUE on success, FALSE on failure. - * If PGSQL_DML_STRING is set, a string is returned on success. + * If PGSQL_DML_STRING is set, a string is returned. * * Its unclear as to what the returned string is, but it can be assumed to be a value, such as an serialized number that was incremented by this operation. * @@ -1870,7 +1870,7 @@ class c_base_database extends c_base_return { * * @return c_base_return_status|c_base_return_string * TRUE on success, FALSE on failure. - * If PGSQL_DML_STRING is set, a string is returned on success. + * If PGSQL_DML_STRING is set, a string is returned. * * Its unclear as to what the returned string is, but it can be assumed to be a value, such as an serialized number that was incremented by this operation. * @@ -1957,7 +1957,7 @@ class c_base_database extends c_base_return { * * @return c_base_return_status|c_base_return_string|c_base_return_array * TRUE or an array on success, FALSE on failure. - * If PGSQL_DML_STRING is set, a string is returned on success. + * If PGSQL_DML_STRING is set, a string is returned. * * Its unclear as to what the returned string is, but it can be assumed to be a value, such as an serialized number that was incremented by this operation. * @@ -2045,7 +2045,7 @@ class c_base_database extends c_base_return { * * @return c_base_return_status|c_base_return_string|c_base_return_array * TRUE on success, FALSE on failure. - * If PGSQL_DML_STRING is set, a string is returned on success. + * If PGSQL_DML_STRING is set, a string is returned. * * Its unclear as to what the returned string is, but it can be assumed to be a value, such as an serialized number that was incremented by this operation. * diff --git a/common/base/classes/base_path.php b/common/base/classes/base_path.php index b3aa64c..3786c63 100644 --- a/common/base/classes/base_path.php +++ b/common/base/classes/base_path.php @@ -257,7 +257,7 @@ class c_base_path extends c_base_return_string { * Default setting is assigned on parameter error. * * @return c_base_markup_tag|c_base_return_status - * A newly created tag is returned on success. + * A newly created tag is returned. * FALSE with the error bit set is returned on error. */ public static function s_create_alias($id_group, $field_path, $field_destination, $is_private = TRUE) { @@ -313,7 +313,7 @@ class c_base_path extends c_base_return_string { * Default setting is assigned on parameter error. * * @return c_base_markup_tag|c_base_return_status - * A newly created tag is returned on success. + * A newly created tag is returned. * FALSE with the error bit set is returned on error. */ public static function s_create_redirect($field_destination, $field_response_code, $is_private = TRUE) { @@ -1194,7 +1194,7 @@ class c_base_path extends c_base_return_string { * (optional) An array of additional settings that are usually site-specific. * * @return c_base_path_executed|int - * An executed array object is returned on success. + * An executed array object is returned. * An executed array object with error bit set is returned on error. */ public function do_execute(&$http, &$database, &$session, $settings = []) { @@ -1491,7 +1491,7 @@ class c_base_path_executed extends c_base_array { * When NULL, the cookies array is reset to an empty array. * * @return c_base_return_status - * TRUE is returned on success. + * TRUE is returned. * FALSE with error bit set is returned on error. */ public function set_cookies($cookie) { @@ -1521,7 +1521,7 @@ class c_base_path_executed extends c_base_array { * NULL may be specified to remove any output. * * @return c_base_return_status - * TRUE is returned on success. + * TRUE is returned. * FALSE with error bit set is returned on error. */ public function set_output($output) { @@ -1605,7 +1605,7 @@ class c_base_path_tree extends c_base_array { * The group id to assign. * * @return c_base_return_status - * TRUE is returned on success. + * TRUE is returned. * FALSE with error bit set is returned on error. */ public function set_id_group($id_group) { diff --git a/common/database/classes/database_alter_foreign_data_wrapper.php b/common/database/classes/database_alter_foreign_data_wrapper.php index 4a2c7ed..fc5fd0e 100644 --- a/common/database/classes/database_alter_foreign_data_wrapper.php +++ b/common/database/classes/database_alter_foreign_data_wrapper.php @@ -10,7 +10,6 @@ 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_handler.php'); require_once('common/database/traits/database_name.php'); require_once('common/database/traits/database_options.php'); @@ -24,7 +23,6 @@ require_once('common/database/traits/database_validator.php'); * @see: https://www.postgresql.org/docs/current/static/sql-alterforeigndatawrapper.html */ class c_database_alter_foreign_data_wrapper extends c_database_query { - use t_database_action; use t_database_handler; use t_database_name; use t_database_options; @@ -41,7 +39,6 @@ class c_database_alter_foreign_data_wrapper extends c_database_query { public function __construct() { parent::__construct(); - $this->action = NULL; $this->handler = NULL; $this->name = NULL; $this->options = NULL; @@ -54,7 +51,6 @@ class c_database_alter_foreign_data_wrapper extends c_database_query { * Class destructor. */ public function __destruct() { - unset($this->action); unset($this->handler); unset($this->name); unset($this->options); @@ -94,6 +90,7 @@ class c_database_alter_foreign_data_wrapper extends c_database_query { return new c_base_return_false(); } + // @fixme: rewrite this. $value = NULL; if ($this->action === e_database_action::OWNER_TO) { if (isset($this->owner_to)) { diff --git a/common/database/classes/database_alter_foreign_table.php b/common/database/classes/database_alter_foreign_table.php index f4578e9..29dd114 100644 --- a/common/database/classes/database_alter_foreign_table.php +++ b/common/database/classes/database_alter_foreign_table.php @@ -8,13 +8,30 @@ namespace n_koopa; require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); -require_once('common/database/classes/database_alter_foeign_table_action.php'); require_once('common/database/classes/database_query.php'); +require_once('common/database/traits/database_action_add_column.php'); +require_once('common/database/traits/database_action_add_constraint.php'); +require_once('common/database/traits/database_action_alter_column.php'); +require_once('common/database/traits/database_action_alter_column_options.php'); +require_once('common/database/traits/database_action_alter_column_reset.php'); +require_once('common/database/traits/database_action_alter_column_set.php'); +require_once('common/database/traits/database_action_disable_trigger.php'); +require_once('common/database/traits/database_action_drop_columm.php'); +require_once('common/database/traits/database_action_drop_constraint.php'); +require_once('common/database/traits/database_action_enable_trigger.php'); +require_once('common/database/traits/database_action_inherit.php'); +require_once('common/database/traits/database_action_options.php'); +require_once('common/database/traits/database_action_owner_to.php'); +require_once('common/database/traits/database_action_set_oids.php'); +require_once('common/database/traits/database_action_validate_constraint.php'); +require_once('common/database/traits/database_if_exists.php'); require_once('common/database/traits/database_name.php'); +require_once('common/database/traits/database_only.php'); require_once('common/database/traits/database_rename_column.php'); require_once('common/database/traits/database_rename_to.php'); require_once('common/database/traits/database_set_schema.php'); +require_once('common/database/traits/database_wildcard.php'); /** * The class for building and returning a Postgresql ALTER FOREIGN TABLE query string. @@ -22,17 +39,32 @@ require_once('common/database/traits/database_set_schema.php'); * @see: https://www.postgresql.org/docs/current/static/sql-alterforeigntable.html */ class c_database_alter_foreign_table extends c_database_query { + use t_database_action_add_column; + use t_database_action_add_constraint; + use t_database_action_alter_column; + use t_database_action_alter_column_options; + use t_database_action_alter_column_reset; + use t_database_action_alter_column_set; + use t_database_action_alter_constraint; + use t_database_action_disable_trigger; + use t_database_action_drop_columm; + use t_database_action_drop_constraint; + use t_database_action_enable_trigger; + use t_database_action_inherit; + use t_database_action_options; + use t_database_action_owner_to; + use t_database_action_set_oids; + use t_database_action_validate_constraint; + use t_database_if_exists; use t_database_name; + use t_database_only; use t_database_rename_column; use t_database_rename_to; use t_database_set_schema; + use t_database_wildcard; protected const p_QUERY_COMMAND = 'alter foreign table'; - protected $actions; - protected $if_exists; - protected $include_descendents; // The '*' following 'name' - protected $only; /** * Class constructor. @@ -40,15 +72,29 @@ class c_database_alter_foreign_table extends c_database_query { public function __construct() { parent::__construct(); - $this->name = NULL; - $this->rename_column = NULL; - $this->rename_to = NULL; - $this->set_schema = NULL; - - $this->actions = NULL; - $this->if_exists = NULL; - $this->include_descendents = NULL; - $this->only = NULL; + $this->action_add_column = NULL; + $this->action_add_constraint = NULL; + $this->action_alter_column = NULL; + $this->action_alter_column_options = NULL; + $this->action_alter_column_reset = NULL; + $this->action_alter_column_set = NULL; + $this->action_alter_constraint = NULL; + $this->action_disable_trigger = NULL; + $this->action_drop_columm = NULL; + $this->action_drop_constraint = NULL; + $this->action_enable_trigger = NULL; + $this->action_inherit = NULL; + $this->action_options = NULL; + $this->action_owner_to = NULL; + $this->action_set_oids = NULL; + $this->action_validate_constraint = NULL; + $this->if_exists = NULL; + $this->name = NULL; + $this->only = NULL; + $this->rename_column = NULL; + $this->rename_to = NULL; + $this->set_schema = NULL; + $this->wildcard = NULL; } /** @@ -57,15 +103,29 @@ class c_database_alter_foreign_table extends c_database_query { public function __destruct() { parent::__destruct(); + unset($this->action_add_column); + unset($this->action_add_constraint); + unset($this->action_alter_column); + unset($this->action_alter_column_options); + unset($this->action_alter_column_reset); + unset($this->action_alter_column_set); + unset($this->action_alter_constraint); + unset($this->action_disable_trigger); + unset($this->action_drop_columm); + unset($this->action_drop_constraint); + unset($this->action_enable_trigger); + unset($this->action_inherit); + unset($this->action_options); + unset($this->action_owner_to); + unset($this->action_set_oids); + unset($this->action_validate_constraint); + unset($this->if_exists); unset($this->name); + unset($this->only); unset($this->rename_column); unset($this->rename_to); unset($this->set_schema); - - unset($this->actions); - unset($this->if_exists); - unset($this->include_descendents); - unset($this->only); + unset($this->wildcard); } /** @@ -90,275 +150,101 @@ class c_database_alter_foreign_table extends c_database_query { } /** - * Set or append and action. - * - * @param c_database_alter_foreign_table_action|null $action - * A specific action to this class. - * Set to NULL to disable. - * When NULL, this will remove all actions. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * FALSE with error bit set is returned on error. + * Implements do_build(). */ - public function set_action($action) { - if (is_null($action)) { - $this->actions = NULL; - return new c_base_return_true(); + public function do_build() { + if (is_null($this->name)) { + return new c_base_return_false(); } - if (is_string($action)) { - if (!is_array($this->actions)) { - $this->actions = []; - } - - $this->actions[] = $action; - } - else { - $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); + $if_exists = NULL; + if ($this->if_exists) { + $if_exists = $this->p_do_build_if_exists() . ' '; } - return new c_base_return_true(); - } - - /** - * Assigns IF EXISTS. - * - * @param bool|null $if_exists - * Set to TRUE to enable IF EXISTS, FALSE to disable. - * Set to NULL to disable. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * FALSE with error bit set is returned on error. - */ - public function set_if_exists($if_exists) { - if (is_null($if_exists)) { - $this->if_exists = NULL; - return new c_base_return_true(); + $only = NULL; + if ($this->only) { + $only = $this->p_do_build_only() . ' '; } - if (is_bool($if_exists)) { - $this->if_exists = $if_exists; - return new c_base_return_true(); + $wildcard = NULL; + if ($this->wildcard) { + $wildcard = ' ' . $this->p_do_build_wildcard(); } - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'if_exists', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } - - /** - * Assigns wildcard '*' after the table name. - * - * @param bool|null $include_decendents - * Set to TRUE to enable wildcard '*', FALSE to disable. - * Set to NULL to disable. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * FALSE with error bit set is returned on error. - */ - public function set_include_decendents($include_decendents) { - if (is_null($include_decendents)) { - $this->include_decendents = NULL; - return new c_base_return_true(); + $value = $this->p_do_build_name(); + if (isset($this->rename_column)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_rename_column(); } - - if (is_bool($include_decendents)) { - $this->include_decendents = $include_decendents; - return new c_base_return_true(); + else if (isset($this->rename_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_rename_constraint(); } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'include_decendents', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } - - /** - * Assigns ONLY. - * - * @param bool|null $only - * Set to TRUE to enable ONLY, FALSE to disable. - * Set to NULL to disable. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * FALSE with error bit set is returned on error. - */ - public function set_only($only) { - if (is_null($only)) { - $this->only = NULL; - return new c_base_return_true(); + else if (isset($this->rename_to)) { + $value = $if_exists . $value . ' ' . $this->p_do_build_rename_to(); } - - if (is_bool($only)) { - $this->only = $only; - return new c_base_return_true(); + else if (isset($this->set_schema)) { + $value = $if_exists . $value . ' ' . $this->p_do_build_set_schema(); } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'only', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } - - /** - * Get an action or all actions. - * - * @param int|null $index - * (optional) Get the action at the specified index. - * When NULL, all actions are returned. - * - * @return c_database_alter_foreign_table_action|c_base_return_array|c_base_return_null - * An array of actions or NULL if not defined. - * A single action is returned if $index is an integer. - * NULL with the error bit set is returned on error. - */ - public function get_action($index = NULL) { - if (is_null($this->actions)) { - return new c_base_return_null(); + else if (isset($this->action_add_column)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_add_column(); } - - if (is_null($index)) { - if (is_array($this->actions)) { - return c_base_return_array::s_new($this->actions); - } + else if (isset($this->action_add_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_add_constraint(); } - else { - if (is_int($index) && array_key_exists($index, $this->actions) && $this->actions[$index] instanceof c_database_alter_foreign_table_action) { - return $this->actions[$index]; - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'actions[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); + else if (isset($this->action_alter_column)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column(); } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'actions', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); - } - - /** - * Get the if exists setting. - * - * @return c_base_return_bool|c_base_return_null - * A boolean representing the IF EXISTS setting. - * NULL is returned if not defined. - * NULL with the error bit set is returned on error. - */ - public function get_if_exists($index = NULL) { - if (is_null($this->if_exists)) { - return new c_base_return_null(); + else if (isset($this->action_alter_column_options)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column_options(); } - - if (is_bool($index)) { - return c_base_return_bool::s_new($this->if_exists); + else if (isset($this->action_alter_column_reset)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column_reset(); } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'if_exists', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); - } - - /** - * Get the include decendents setting. - * - * @return c_base_return_bool|c_base_return_null - * A boolean representing the '*' setting. - * NULL is returned if not defined. - * NULL with the error bit set is returned on error. - */ - public function get_include_decendents($index = NULL) { - if (is_null($this->include_decendents)) { - return new c_base_return_null(); + else if (isset($this->action_alter_column_set)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column_set(); } - - if (is_bool($index)) { - return c_base_return_bool::s_new($this->include_decendents); + else if (isset($this->action_alter_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_constraint(); } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'include_decendents', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); - } - - /** - * Get the set only setting. - * - * @return c_base_return_bool|c_base_return_null - * A boolean representing the ONLY setting. - * NULL is returned if not defined. - * NULL with the error bit set is returned on error. - */ - public function get_set_only($index = NULL) { - if (is_null($this->set_only)) { - return new c_base_return_null(); + else if (isset($this->action_disable_trigger)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_disable_trigger(); } - - if (is_bool($index)) { - return c_base_return_bool::s_new($this->set_only); + else if (isset($this->action_drop_columm)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_drop_columm(); } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_only', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); - } - - /** - * Implements do_build(). - */ - public function do_build() { - if (is_null($this->name)) { - return new c_base_return_false(); + else if (isset($this->action_drop_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_drop_constraint(); } - - $value = NULL; - if ($this->if_exists) { - $value = ' ' . c_database_string::IF_EXISTS; + else if (isset($this->action_enable_trigger)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_enable_trigger(); } - - if (is_array($this->rename_column)) { - if ($this->only) { - $value .= is_null($value) ? '' : ' '; - $value .= c_database_string::ONLY; - } - - $value .= ' ' . $this->p_do_build_rename_column(); + else if (isset($this->action_inherit)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_inherit(); } - else if (isset($this->rename_to)) { - $value .= is_null($value) ? '' : ' '; - $value .= $this->p_do_build_rename_to(); + else if (isset($this->action_options)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_options(); + } + else if (isset($this->action_owner_to)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_owner_to(); + } + else if (isset($this->action_set_oids)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_set_oids(); } - else if (is_array($this->set_schema)) { - $value .= is_null($value) ? '' : ' '; - $value .= $this->p_do_build_set_schema(); + else if (isset($this->action_validate_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_validate_constraint(); } else { - if ($this->only) { - $value .= is_null($value) ? '' : ' '; - $value .= c_database_string::ONLY; - } - - $value .= is_null($value) ? '' : ' '; - if (is_array($this->actions) && !empty($this->actions)) { - $actions = []; - foreach ($this->actions as $action) { - if ($action instanceof c_database_alter_foreign_table_action && $action->do_build() instanceof c_base_return_true) { - $actions[] = $action->get_value_exact(); - } - } - unset($action); - - $value .= implode(', ', $actions); - unset($actions); - } - else { - unset($value); - return new c_base_return_false(); - } + unset($value); + unset($if_exists); + unset($only); + unset($wildcard); + return new c_base_return_false(); } + unset($if_exists); + unset($only); + unset($wildcard); $this->value = static::p_QUERY_COMMAND; - $this->value .= ' ' . $this->p_do_build_name(); - - if ($this->include_descendents) { - $this->value .' *'; - } - $this->value .= ' ' . $value; unset($value); diff --git a/common/database/classes/database_alter_materialized_view.php b/common/database/classes/database_alter_materialized_view.php index e613ed1..52b91f8 100644 --- a/common/database/classes/database_alter_materialized_view.php +++ b/common/database/classes/database_alter_materialized_view.php @@ -10,7 +10,6 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); -require_once('common/database/traits/database_all_in_tablespace.php'); require_once('common/database/traits/database_cluster_on.php'); require_once('common/database/traits/database_column_reset.php'); require_once('common/database/traits/database_column_set.php'); @@ -37,7 +36,6 @@ require_once('common/database/traits/database_set_without_cluster.php'); * @see: https://www.postgresql.org/docs/current/static/sql-altermaterializedview.html */ class c_database_alter_materialized_view extends c_database_query { - use t_database_all_in_tablespace; use t_database_cluster_on; use t_database_column_reset; use t_database_column_set; @@ -66,7 +64,6 @@ class c_database_alter_materialized_view extends c_database_query { public function __construct() { parent::__construct(); - $this->all_in_tablespace = NULL; $this->cluster_on = NULL; $this->column_reset = NULL; $this->column_set = NULL; @@ -91,7 +88,6 @@ class c_database_alter_materialized_view extends c_database_query { * Class destructor. */ public function __destruct() { - unset($this->all_in_tablespace); unset($this->cluster_on); unset($this->column_reset); unset($this->column_set); diff --git a/common/database/classes/database_alter_system.php b/common/database/classes/database_alter_system.php index bf3857e..7258d80 100644 --- a/common/database/classes/database_alter_system.php +++ b/common/database/classes/database_alter_system.php @@ -10,14 +10,20 @@ require_once('common/base/classes/base_return.php'); require_once('common/database/classes/database_query.php'); +require_once('common/database/traits/database_reset_configuration_parameter.php'); +require_once('common/database/traits/database_set_configuration_parameter.php'); + /** - * The class for building and returning a Postgresql ALTER COALATION query string. + * The class for building and returning a Postgresql ALTER SYSTEM query string. * - * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html + * @see: https://www.postgresql.org/docs/current/static/sql-altersystem.html */ -class c_database_alter_coalation extends c_database_query { - protected const p_QUERY_COMMAND = 'alter coalation'; +class c_database_alter_system extends c_database_query { + use t_database_reset_configuration_parameter; + use t_database_set_configuration_parameter; + + protected const p_QUERY_COMMAND = 'alter system'; /** @@ -25,12 +31,19 @@ class c_database_alter_coalation extends c_database_query { */ public function __construct() { parent::__construct(); + + $this->action_validate_constraint = NULL; + $this->reset_configuration_parameter = NULL; + $this->set_configuration_parameter = NULL; } /** * Class destructor. */ public function __destruct() { + unset($this->reset_configuration_parameter); + unset($this->set_configuration_parameter); + parent::__destruct(); } @@ -59,12 +72,18 @@ class c_database_alter_coalation extends c_database_query { * Implements do_build(). */ public function do_build() { - if (is_null($this->name)) { + $value = NULL; + if (isset($this->set_configuration_parameter)) { + $value = $this->p_do_build_set_configuration_parameter(); + } + else if (isset($this->set_configuration_parameter)) { + $value = $this->p_do_build_set_configuration_parameter(); + } + else { + unset($value); return new c_base_return_false(); } - $value = $this->p_do_build_name(); - $this->value = static::p_QUERY_COMMAND; $this->value .= ' ' . $value; unset($value); diff --git a/common/database/classes/database_alter_table.php b/common/database/classes/database_alter_table.php index bf3857e..3a1dc78 100644 --- a/common/database/classes/database_alter_table.php +++ b/common/database/classes/database_alter_table.php @@ -1,7 +1,7 @@ action_add_column = NULL; + $this->action_add_constraint = NULL; + $this->action_alter_column = NULL; + $this->action_alter_column_options = NULL; + $this->action_alter_column_reset = NULL; + $this->action_alter_column_set = NULL; + $this->action_alter_constraint = NULL; + $this->action_disable_trigger = NULL; + $this->action_drop_columm = NULL; + $this->action_drop_constraint = NULL; + $this->action_enable_trigger = NULL; + $this->action_inherit = NULL; + $this->action_options = NULL; + $this->action_owner_to = NULL; + $this->action_set_oids = NULL; + $this->attach_partition = NULL; + $this->detach_partition = NULL; + $this->if_exists = NULL; + $this->name = NULL; + $this->no_wait = NULL; + $this->only = NULL; + $this->owned_by = NULL; + $this->rename_column = NULL; + $this->rename_constraint = NULL; + $this->rename_to = NULL; + $this->set_schema = NULL; + $this->set_tablespace = NULL; + $this->wildcard = NULL; } /** * Class destructor. */ public function __destruct() { + unset($this->action_add_column); + unset($this->action_add_constraint); + unset($this->action_alter_column); + unset($this->action_alter_column_options); + unset($this->action_alter_column_reset); + unset($this->action_alter_column_set); + unset($this->action_alter_constraint); + unset($this->action_disable_trigger); + unset($this->action_drop_columm); + unset($this->action_drop_constraint); + unset($this->action_enable_trigger); + unset($this->action_inherit); + unset($this->action_options); + unset($this->action_owner_to); + unset($this->action_set_oids); + unset($this->action_validate_constraint); + unset($this->attach_partition); + unset($this->detach_partition); + unset($this->if_exists); + unset($this->name); + unset($this->no_wait); + unset($this->only); + unset($this->owned_by); + unset($this->rename_column); + unset($this->rename_constraint); + unset($this->rename_to); + unset($this->set_schema); + unset($this->set_tablespace); + unset($this->wildcard); + parent::__destruct(); } @@ -63,7 +180,111 @@ class c_database_alter_coalation extends c_database_query { return new c_base_return_false(); } + $if_exists = NULL; + if ($this->if_exists) { + $if_exists = $this->p_do_build_if_exists() . ' '; + } + + $only = NULL; + if ($this->only) { + $only = $this->p_do_build_only() . ' '; + } + + $wildcard = NULL; + if ($this->wildcard) { + $wildcard = ' ' . $this->p_do_build_wildcard(); + } + $value = $this->p_do_build_name(); + if (isset($this->rename_column)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_rename_column(); + } + else if (isset($this->rename_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_rename_constraint(); + } + else if (isset($this->rename_to)) { + $value = $if_exists . $wildcard . $this->p_do_build_rename_to(); + } + else if (isset($this->set_schema)) { + $value = $if_exists . $wildcard . $this->p_do_build_set_schema(); + } + else if (isset($this->set_tablespace)) { + $value = c_database_string::ALL_IN_TABLESPACE . ' ' . $value; + + if (!is_null($this->owned_by)) { + $value .= ' ' . $this->p_do_build_owned_by(); + } + + $value .= ' ' . $this->p_do_build_set_tablespace(); + + if (is_bool($this->no_wait)) { + $value .= ' ' . $this->p_do_build_no_wait(); + } + } + else if (isset($this->attach_partition)) { + $value =$if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_attach_partition(); + } + else if (isset($this->detach_partition)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_detach_partition(); + } + else if (isset($this->action_add_column)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_add_column(); + } + else if (isset($this->action_add_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_add_constraint(); + } + else if (isset($this->action_alter_column)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column(); + } + else if (isset($this->action_alter_column_options)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column_options(); + } + else if (isset($this->action_alter_column_reset)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column_reset(); + } + else if (isset($this->action_alter_column_set)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_column_set(); + } + else if (isset($this->action_alter_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_alter_constraint(); + } + else if (isset($this->action_disable_trigger)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_disable_trigger(); + } + else if (isset($this->action_drop_columm)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_drop_columm(); + } + else if (isset($this->action_drop_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_drop_constraint(); + } + else if (isset($this->action_enable_trigger)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_enable_trigger(); + } + else if (isset($this->action_inherit)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_inherit(); + } + else if (isset($this->action_options)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_options(); + } + else if (isset($this->action_owner_to)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_owner_to(); + } + else if (isset($this->action_set_oids)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_set_oids(); + } + else if (isset($this->action_validate_constraint)) { + $value = $if_exists . $only . $value . ' ' . $wildcard . $this->p_do_build_action_validate_constraint(); + } + else { + unset($value); + unset($if_exists); + unset($only); + unset($wildcard); + return new c_base_return_false(); + } + unset($if_exists); + unset($only); + unset($wildcard); $this->value = static::p_QUERY_COMMAND; $this->value .= ' ' . $value; diff --git a/common/database/classes/database_query.php b/common/database/classes/database_query.php index a9e538b..0689f6c 100644 --- a/common/database/classes/database_query.php +++ b/common/database/classes/database_query.php @@ -134,7 +134,7 @@ abstract class c_database_query extends c_base_return_string implements i_databa * When NULL, the placeholder is appended. * * @return i_database_query_placeholder|c_base_return_false - * A query placeholder representing is returned on success. + * A query placeholder representing is returned. * FALSE with the error bit set is returned on error. */ public function add_placeholder($value, $placeholder = NULL) { diff --git a/common/database/classes/database_string.php b/common/database/classes/database_string.php index 73e0b42..f0225af 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_COLUMN = 'add column'; public const ADD_TABLE = 'add table'; public const AGGREGATE = 'aggregate'; public const ALL = 'all'; @@ -20,6 +21,7 @@ class c_database_string { public const ALTER = 'alter'; public const AS = 'as'; public const ASCEND = 'asc'; + public const ATTACH_PARTITION = 'attach partition'; public const AUTOSUMMARIZE = 'autosummarize'; public const AUTOVACUUM_ANALYZE_SCALE_FACTOR = 'autovacuum_analyze_scale_factor'; public const AUTOVACUUM_ANALYZE_THRESHOLD = 'autovacuum_analyze_threshold'; @@ -40,6 +42,7 @@ class c_database_string { public const CASCADE = 'cascade'; public const CAST = 'cast'; public const CLUSTER_ON = 'cluster on'; + public const COLLATE = 'collate'; public const COLLATION = 'collation'; public const COLUMN = 'column'; public const CONNECT = 'connect'; @@ -61,9 +64,9 @@ class c_database_string { public const DISABLE_TRIGGER = 'disable trigger'; public const DOMAIN = 'domain'; public const DROP = 'drop'; - public const DROP_TABLE = 'drop table'; public const DROP_CONSTRAINT = 'drop constraint'; public const DROP_DEFAULT = 'drop default'; + public const DROP_TABLE = 'drop table'; public const ENABLE = 'enable'; public const ENABLED = 'enabled'; public const ENABLE_ALWAYS_TRIGGER = 'enable always trigger'; @@ -82,6 +85,7 @@ class c_database_string { public const FOR_ORDER_BY = 'for order by'; public const FOR_ROLE = 'for role'; public const FOR_SEARCH = 'for search'; + public const FOR_VALUES = 'for values'; public const FROM_CURRENT = 'from current'; public const FUNCTION = 'function'; public const GRANT = 'grant'; @@ -173,6 +177,7 @@ class c_database_string { public const SEQUENCE = 'sequence'; public const SERVER = 'server'; public const SET = 'set'; + public const SET_DATA = 'set data'; public const SET_DEFAULT = 'set default'; public const SET_PUBLICATION = 'set publication'; public const SET_SCHEMA = 'set schema'; diff --git a/common/database/enumerations/database_alter_column.php b/common/database/enumerations/database_alter_column.php new file mode 100644 index 0000000..79d082c --- /dev/null +++ b/common/database/enumerations/database_alter_column.php @@ -0,0 +1,22 @@ +action_add_column = NULL; + return new c_base_return_true(); + } + + if (!is_string($column_name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'column_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($data_type)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'data_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($collate) && !is_string($collate)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'collate', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($column_constraints) && !is_array($column_constraints)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'column_constraints', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $placeholder_column_name = $this->add_placeholder($column_name); + if ($placeholder_column_name->has_error()) { + return c_base_return_error::s_false($placeholder_column_name->get_error()); + } + + $placeholder_data_type = NULL; + if (!is_null($data_type)) { + $placeholder_data_type = $this->add_placeholder($data_type); + if ($placeholder_data_type->has_error()) { + unset($placeholder_column_name); + return c_base_return_error::s_false($placeholder_data_type->get_error()); + } + } + + $placeholder_collate = NULL; + if (!is_null($collate)) { + $placeholder_collate = $this->add_placeholder($collate); + if ($placeholder_collate->has_error()) { + unset($placeholder_column_name); + unset($placeholder_data_type); + return c_base_return_error::s_false($placeholder_collate->get_error()); + } + } + + $placeholder_constraints = NULL; + if (!is_null($column_constraint)) { + $placeholder_constraints = []; + foreach ($column_constraint as $column_constraint) { + if (!is_string($column_constraint)) { + unset($column_constraint); + unset($placeholder_column_name); + unset($placeholder_data_type); + unset($placeholder_collate); + unset($placeholder_constraints); + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'column_constraints', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $placeholder_constraint = $this->add_placeholder($column_constraint); + if ($placeholder_constraint->has_error()) { + unset($column_constraint); + unset($placeholder_column_name); + unset($placeholder_data_type); + unset($placeholder_collate); + return c_base_return_error::s_false($placeholder_constraint->get_error()); + } + + $placeholder_constraints[] = $placeholder_constraint; + } + unset($column_constraint); + } + + $this->action_add_column = [ + 'column_name' => $placeholder_column_name, + 'data_type' => $placeholder_data_type, + 'collate' => $placeholder_collate, + 'column_constraints' => $placeholder_constraints, + ]; + unset($placeholder_column_name); + unset($placeholder_data_type); + unset($placeholder_collate); + unset($placeholder_constraints); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned action add column settings. + * + * @return c_base_return_array|c_base_return_null + * An array containing the settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_action_add_column() { + if (is_null($this->action_add_column)) { + return new c_base_return_null(); + } + + if (is_array($this->action_add_column)) { + return c_base_return_array::s_new($this->action_add_column); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_add_column', ':{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_action_add_column() { + $value = c_database_string::ADD_COLUMN . ' ' . $this->action_add_column['column_name'] . ' ' . $this->action_add_column['data_type']; + if (!is_null($this->action_add_column['collate'])) { + $value .= ' ' . $this->action_add_column['collate']; + } + + if (isset($this->action_add_column['column_constraints'])) { + $value .= ' ' . implode(' ', $this->action_add_column['column_constraints']); + } + + return $value; + } +} diff --git a/common/database/traits/database_action_alter_column.php b/common/database/traits/database_action_alter_column.php new file mode 100644 index 0000000..19aa2ac --- /dev/null +++ b/common/database/traits/database_action_alter_column.php @@ -0,0 +1,235 @@ +action_alter_column = NULL; + return new c_base_return_true(); + } + + if (!is_string($column_name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'column_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $valid_value = false; + switch ($type) { + case e_database_alter_column::DROP: + case e_database_alter_column::SET: + $valid_value = is_null($value) || is_bool($value); + break; + + case e_database_alter_column::DROP_DEFAULT: + break; + + case e_database_alter_column::SET_DATA: + $valid_value = is_string($value); + + if (!is_null($value2) && !is_string($value2)) { + unset($valid_value); + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'value2', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + break; + + case e_database_alter_column::SET_DEFAULT: + $valid_value = is_string($value); + break; + + case e_database_alter_column::SET_STATISTICS: + $valid_value = is_int($value); + break; + + case e_database_alter_column::SET_STORAGE: + switch($value) { + case e_database_set_storage::EXTENDED: + case e_database_set_storage::EXTERNAL: + case e_database_set_storage::MAIN: + case e_database_set_storage::PLAIN: + $valid_value = true; + break; + } + break; + + default: + unset($valid_value); + $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); + } + + if (!$valid_value) { + unset($valid_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); + } + unset($invalid_value); + + $placeholder_column_name = $this->add_placeholder($column_name); + if ($placeholder_column_name->has_error()) { + return c_base_return_error::s_false($placeholder_column_name->get_error()); + } + + $placeholder_value = $value; + if (is_string($value)) { + $placeholder_value = $this->add_placeholder($value); + if ($placeholder_value->has_error()) { + unset($placeholder_column_name); + return c_base_return_error::s_false($placeholder_value->get_error()); + } + } + + $placeholder_value2 = NULL; + if ($type === e_database_alter_column::SET_DATA) { + $placeholder_value2 = $this->add_placeholder($value2); + if ($placeholder_value2->has_error()) { + unset($placeholder_column_name); + unset($placeholder_value); + return c_base_return_error::s_false($placeholder_value2->get_error()); + } + } + + $this->action_alter_column = [ + 'column_name' => $placeholder_column_name, + 'type' => $type, + 'value' => $placeholder_value, + 'value2' => $placeholder_value2, + ]; + unset($placeholder_column_name); + unset($placeholder_value); + unset($placeholder_value2); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned action alter column settings. + * + * @return c_base_return_array|c_base_return_null + * An array containing the settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_action_alter_column() { + if (is_null($this->action_alter_column)) { + return new c_base_return_null(); + } + + if (is_array($this->action_alter_column)) { + return c_base_return_array::s_new($this->action_alter_column); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column', ':{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_action_alter_column() { + $value = c_database_string::ALTER_COLUMN . ' ' . $this->action_alter_column['column_name']; + + switch ($this->action_alter_column['type']) { + case e_database_alter_column::DROP: + $value .= ' ' . c_database_string::DROP; + if ($this->action_alter_column['value']) { + $value .= ' ' . c_database_string::NOT_NULL; + } + break; + + case e_database_alter_column::SET: + $value .= ' ' . c_database_string::SET; + if ($this->action_alter_column['value']) { + $value .= ' ' . c_database_string::NOT_NULL; + } + break; + + case e_database_alter_column::DROP_DEFAULT: + $value .= ' ' . c_database_string::DROP_DEFAULT; + break; + + case e_database_alter_column::SET_DATA: + $value .= ' ' . c_database_string::SET_DATA; + $value .= ' ' . c_database_string::TYPE; + $value .= ' ' . strval($this->action_alter_column['value']); + if (isset($this->action_alter_column['value2'])) { + $value .= ' ' . c_database_string::COLLATE; + $value .= ' ' . strval($this->action_alter_column['value2']); + } + break; + + case e_database_alter_column::SET_DEFAULT: + $value .= ' ' . c_database_string::SET_DEFAULT; + $value .= ' ' . strval($this->action_alter_column['value']); + break; + + case e_database_alter_column::SET_STATISTICS: + $value .= ' ' . c_database_string::SET_STATISTICS; + $value .= ' ' . $this->action_alter_column['value']; + break; + + case e_database_alter_column::SET_STORAGE: + $value .= ' ' . c_database_string::SET_STORAGE; + if ($this->action_alter_column['value'] === e_database_set_storage::EXTENDED) { + $value .= ' ' . c_database_string::EXTENDED; + } + else if ($this->action_alter_column['value'] === e_database_set_storage::EXTERNAL) { + $value .= ' ' . c_database_string::EXTERNAL; + } + else if ($this->action_alter_column['value'] === e_database_set_storage::MAIN) { + $value .= ' ' . c_database_string::MAIN; + } + else if ($this->action_alter_column['value'] === e_database_set_storage::PLAIN) { + $value .= ' ' . c_database_string::PLAIN; + } + break; + } + + return $value; + } +} diff --git a/common/database/traits/database_action_alter_column_options.php b/common/database/traits/database_action_alter_column_options.php new file mode 100644 index 0000000..3e289a4 --- /dev/null +++ b/common/database/traits/database_action_alter_column_options.php @@ -0,0 +1,176 @@ +action_alter_column_options = NULL; + return new c_base_return_true(); + } + + switch($type) { + case e_database_options::ADD: + case e_database_options::DROP: + case e_database_options::SET: + break; + default: + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($option)) { + $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($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_name = $this->add_placeholder($name); + if ($placeholder_name->has_error()) { + return c_base_return_error::s_false($placeholder_name->get_error()); + } + + $placeholder_option = $this->add_placeholder($option); + if ($placeholder_option->has_error()) { + unset($placeholder_name); + return c_base_return_error::s_false($placeholder_option->get_error()); + } + + $placeholder_value = $this->add_placeholder($value); + if ($placeholder_value->has_error()) { + unset($placeholder_name); + unset($placeholder_option); + return c_base_return_error::s_false($placeholder_value->get_error()); + } + + if (!is_array($this->action_alter_column_options)) { + $this->action_alter_column_options = [ + 'column_name' => $placeholder_name, + 'values' => [], + ]; + } + + $this->action_alter_column_options[] = [ + 'type' => $type, + 'option' => $placeholder_option, + 'value' => $placeholder_value, + ]; + unset($placeholder_name); + unset($placeholder_option); + unset($placeholder_value); + + return new c_base_return_true(); + } + + /** + * 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) { + 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); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_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_action_alter_column_options() { + $value = c_database_string::ALTER_COLUMN . ' ' . $this->action_alter_column_options['column_name'] . ' ' . c_database_string::OPTIONS; + + $values = []; + foreach ($this->action_alter_column_options['values'] as $set) { + if ($set['type'] === e_database_options::ADD) { + $set_value = c_database_string::ADD; + } + else if ($set['type'] === e_database_options::DROP) { + $set_value = c_database_string::DROP; + } + else if ($set['type'] === e_database_options::SET) { + $set_value = c_database_string::SET; + } + else { + continue; + } + + $set_value .= ' ' . $set['option'] . ' ' . $set['value']; + $values[] = $set_value; + } + unset($set); + unset($set_value); + + return $value . ' ' . implode(', ', $values); + } +} diff --git a/common/database/traits/database_action_alter_column_reset.php b/common/database/traits/database_action_alter_column_reset.php new file mode 100644 index 0000000..528f2ae --- /dev/null +++ b/common/database/traits/database_action_alter_column_reset.php @@ -0,0 +1,128 @@ +action_alter_column_reset = NULL; + return new c_base_return_true(); + } + + if (!is_string($option)) { + $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); + } + + $placeholder_name = $this->add_placeholder($name); + if ($placeholder_name->has_error()) { + return c_base_return_error::s_false($placeholder_name->get_error()); + } + + $placeholder_option = $this->add_placeholder($option); + if ($placeholder_option->has_error()) { + unset($placeholder_name); + return c_base_return_error::s_false($placeholder_option->get_error()); + } + + if (!is_array($this->action_alter_column_reset)) { + $this->action_alter_column_reset = [ + 'column_name' => $placeholder_name, + 'values' => [], + ]; + } + + $this->action_alter_column_reset[] = [ + 'option' => $placeholder_option, + ]; + unset($placeholder_name); + unset($placeholder_option); + + return new c_base_return_true(); + } + + /** + * 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) { + 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); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_reset', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); + } + + /** + * Perform the common build process for this trait. + * + * As an internal trait method, the caller is expected to perform any appropriate validation. + * + * @return string|null + * A string is returned. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_action_alter_column_reset() { + $value = c_database_string::ALTER_COLUMN . ' ' . $this->action_alter_column_reset['column_name'] . ' ' . c_database_string::RESET; + + $values = []; + foreach ($this->action_alter_column_reset['values'] as $reset) { + $values[] = $reset['option']; + } + unset($reset); + + return $value . ' ' . implode(', ', $values); + } +} diff --git a/common/database/traits/database_action_alter_column_set.php b/common/database/traits/database_action_alter_column_set.php new file mode 100644 index 0000000..c744fc1 --- /dev/null +++ b/common/database/traits/database_action_alter_column_set.php @@ -0,0 +1,145 @@ +action_alter_column_set = NULL; + return new c_base_return_true(); + } + + if (!is_string($option)) { + $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($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_name = $this->add_placeholder($name); + if ($placeholder_name->has_error()) { + return c_base_return_error::s_false($placeholder_name->get_error()); + } + + $placeholder_option = $this->add_placeholder($option); + if ($placeholder_option->has_error()) { + unset($placeholder_name); + return c_base_return_error::s_false($placeholder_option->get_error()); + } + + $placeholder_value = $this->add_placeholder($value); + if ($placeholder_value->has_error()) { + unset($placeholder_name); + unset($placeholder_option); + return c_base_return_error::s_false($placeholder_value->get_error()); + } + + if (!is_array($this->action_alter_column_set)) { + $this->action_alter_column_set = [ + 'column_name' => $placeholder_name, + 'values' => [], + ]; + } + + $this->action_alter_column_set[] = [ + 'option' => $placeholder_option, + 'value' => $placeholder_value, + ]; + unset($placeholder_name); + unset($placeholder_option); + unset($placeholder_value); + + return new c_base_return_true(); + } + + /** + * 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) { + 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); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_alter_column_set', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); + } + + /** + * Perform the common build process for this trait. + * + * As an internal trait method, the caller is expected to perform any appropriate validation. + * + * @return string|null + * A string is returned. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_action_alter_column_set() { + $value = c_database_string::ALTER_COLUMN . ' ' . $this->action_alter_column_set['column_name'] . ' ' . c_database_string::SET; + + $values = []; + foreach ($this->action_alter_column_set['values'] as $set) { + $values[] = $set['option'] . ' = ' . $set['value']; + } + unset($set); + + return $value . ' ' . implode(', ', $values); + } +} diff --git a/common/database/traits/database_action_drop_column.php b/common/database/traits/database_action_drop_column.php new file mode 100644 index 0000000..195d717 --- /dev/null +++ b/common/database/traits/database_action_drop_column.php @@ -0,0 +1,127 @@ +action_drop_column = NULL; + return new c_base_return_true(); + } + + if (!is_string($column_name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'column_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($if_exists) && !is_bool($if_exists)) { + $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); + } + + switch ($cascade) { + case e_database_cascade::CASCADE: + case e_database_cascade::RESTRICT: + 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_column_name = $this->add_placeholder($column_name); + if ($placeholder_column_name->has_error()) { + return c_base_return_error::s_false($placeholder_column_name->get_error()); + } + + $this->action_drop_column = [ + 'column_name' => $placeholder_column_name, + 'if_exists' => $if_exists, + 'cascade' => $cascade, + ]; + unset($placeholder_column_name); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned action drop column settings. + * + * @return c_base_return_array|c_base_return_null + * An array containing the settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_action_drop_column() { + if (is_null($this->action_drop_column)) { + return new c_base_return_null(); + } + + if (is_array($this->action_drop_column)) { + return c_base_return_array::s_new($this->action_drop_column); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_drop_column', ':{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_action_drop_column() { + $value = c_database_string::DROP_COLUMN . ' ' . $this->action_drop_column['column_name']; + if ($this->action_drop_column['if_exists']) { + $value = c_database_string::IF_EXISTS . ' ' . $value; + } + + switch ($this->action_drop_column['cascade']) { + case e_database_cascade::CASCADE: + $value .= ' ' . c_database_string::CASCADE; + break; + case e_database_cascade::RESTRICT: + $value .= ' ' . c_database_string::RESTRICT; + break; + } + + return $value; + } +} diff --git a/common/database/traits/database_action_options.php b/common/database/traits/database_action_options.php new file mode 100644 index 0000000..a3af7d3 --- /dev/null +++ b/common/database/traits/database_action_options.php @@ -0,0 +1,163 @@ +action_options = NULL; + return new c_base_return_true(); + } + + if (!is_string($option)) { + $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($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); + } + + switch ($type) { + case e_database_options::ADD: + case e_database_options::DROP: + case e_database_options::SET: + break; + default: + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'schema_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + }; + + if (!is_array($this->action_options)) { + $this->action_options = []; + } + + $placeholder_option = $this->add_placeholder($option); + if ($placeholder_option->has_error()) { + return c_base_return_error::s_false($placeholder_option->get_error()); + } + + $placeholder_value = $this->add_placeholder($value); + if ($placeholder_value->has_error()) { + unset($placeholder_option); + return c_base_return_error::s_false($placeholder_value->get_error()); + } + + $this->action_options[] = [ + 'type' => $type, + 'option' => $placeholder_option, + 'value' => $placeholder_value, + ]; + unset($placeholder_option); + unset($placeholder_value); + + return new c_base_return_true(); + } + + /** + * 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) { + 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); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_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_action_options() { + $value = c_database_string::OPTIONS; + + $values = []; + foreach ($this->action_options['values'] as $set) { + if ($set['type'] === e_database_options::ADD) { + $set_value = c_database_string::ADD; + } + else if ($set['type'] === e_database_options::DROP) { + $set_value = c_database_string::DROP; + } + else if ($set['type'] === e_database_options::SET) { + $set_value = c_database_string::SET; + } + else { + continue; + } + + $set_value .= ' ' . $set['option'] . ' ' . $set['value']; + $values[] = $set_value; + } + unset($set); + unset($set_value); + + return $value . ' ' . implode(', ', $values); + } +} diff --git a/common/database/traits/database_add_operator_family.php b/common/database/traits/database_add_operator_family.php index 76fd2e5..efb8e12 100644 --- a/common/database/traits/database_add_operator_family.php +++ b/common/database/traits/database_add_operator_family.php @@ -224,7 +224,7 @@ trait t_database_add_operator_family { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_add_operator_family() { diff --git a/common/database/traits/database_add_table.php b/common/database/traits/database_add_table.php index 58fcd34..a84b2be 100644 --- a/common/database/traits/database_add_table.php +++ b/common/database/traits/database_add_table.php @@ -83,7 +83,7 @@ trait t_database_add_table { * When NULL, all add table settings are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the add table settings on success. + * An array containing the add table settings. * NULL is returned if not set (add table not to be used). * NULL with the error bit set is returned on error. */ @@ -106,7 +106,7 @@ trait t_database_add_table { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_add_table() { diff --git a/common/database/traits/database_add_user.php b/common/database/traits/database_add_user.php index d230563..c92d243 100644 --- a/common/database/traits/database_add_user.php +++ b/common/database/traits/database_add_user.php @@ -73,7 +73,7 @@ trait t_database_add_user { * Get the add/drop user settings. * * @return c_base_return_array|c_base_return_null - * An array of add/drop user settings on success. + * An array of add/drop user settings. * NULL is returned if not set (add/drop user is not to be used). * NULL with the error bit set is returned on error. */ @@ -96,7 +96,7 @@ trait t_database_add_user { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_add_user() { diff --git a/common/database/traits/database_argument_type.php b/common/database/traits/database_argument_type.php index 87214bf..eceb7e6 100644 --- a/common/database/traits/database_argument_type.php +++ b/common/database/traits/database_argument_type.php @@ -128,7 +128,7 @@ trait t_database_argument_type { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_argument_type() { diff --git a/common/database/traits/database_as_data_type.php b/common/database/traits/database_as_data_type.php index 16abfba..c418da1 100644 --- a/common/database/traits/database_as_data_type.php +++ b/common/database/traits/database_as_data_type.php @@ -76,7 +76,7 @@ trait t_database_as_data_type { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_as_data_type() { diff --git a/common/database/traits/database_attach_partition.php b/common/database/traits/database_attach_partition.php new file mode 100644 index 0000000..b4645bc --- /dev/null +++ b/common/database/traits/database_attach_partition.php @@ -0,0 +1,104 @@ +attach_partition = NULL; + return new c_base_return_true(); + } + + if (!is_string($name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($bound_spec)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'bound_spec', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $placeholder_name = $this->add_placeholder($name); + if ($placeholder_name->has_error()) { + return c_base_return_error::s_false($placeholder_name->get_error()); + } + + $placeholder_bound_spec = $this->add_placeholder($bound_spec); + if ($placeholder_bound_spec->has_error()) { + unset($placeholder_name); + return c_base_return_error::s_false($placeholder_bound_spec->get_error()); + } + + $this->attach_partition = [ + 'name' => $placeholder_name, + 'bound_spec' => $placeholder_bound_spec, + ]; + unset($placeholder_name); + unset($placeholder_bound_spec); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned rename from settings. + * + * @return c_base_return_array|c_base_return_null + * An array containing attach partition settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_attach_partition() { + if (is_null($this->attach_partition)) { + return new c_base_return_null(); + } + + if (is_array($this->attach_partition)) { + return c_base_return_array::s_new($this->attach_partition); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'attach_partition', ':{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_attach_partition() { + return c_database_string::ATTACH_PARTITION . ' ' . $this->attach_partition['name'] . ' ' . c_database_string::FOR_VALUES . ' ' . $this->attach_partition['bound_spec']; + } +} diff --git a/common/database/traits/database_cache.php b/common/database/traits/database_cache.php index 14a1d4f..c2d8a7c 100644 --- a/common/database/traits/database_cache.php +++ b/common/database/traits/database_cache.php @@ -70,7 +70,7 @@ trait t_database_cache { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_cache() { diff --git a/common/database/traits/database_cascade.php b/common/database/traits/database_cascade.php index e99bf5d..cb49b55 100644 --- a/common/database/traits/database_cascade.php +++ b/common/database/traits/database_cascade.php @@ -71,7 +71,7 @@ trait t_database_cascade { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_cascade() { diff --git a/common/database/traits/database_cluster_on.php b/common/database/traits/database_cluster_on.php index 2a0ee79..190d95d 100644 --- a/common/database/traits/database_cluster_on.php +++ b/common/database/traits/database_cluster_on.php @@ -76,7 +76,7 @@ trait t_database_cluster_on { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_cluster_on() { diff --git a/common/database/traits/database_column_reset.php b/common/database/traits/database_column_reset.php index ce7dcdc..38a1285 100644 --- a/common/database/traits/database_column_reset.php +++ b/common/database/traits/database_column_reset.php @@ -123,7 +123,7 @@ trait t_database_column_reset { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_column_reset() { diff --git a/common/database/traits/database_column_set.php b/common/database/traits/database_column_set.php index acb3ff0..adc7f89 100644 --- a/common/database/traits/database_column_set.php +++ b/common/database/traits/database_column_set.php @@ -99,7 +99,7 @@ trait t_database_column_set { * When NULL, all index attribute option types are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the set index attribute option settings on success. + * 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. */ @@ -132,7 +132,7 @@ trait t_database_column_set { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_column_set() { diff --git a/common/database/traits/database_column_set_statistics.php b/common/database/traits/database_column_set_statistics.php index deb6ecd..870fa57 100644 --- a/common/database/traits/database_column_set_statistics.php +++ b/common/database/traits/database_column_set_statistics.php @@ -89,7 +89,7 @@ trait t_database_column_set_statistics { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_column_set_statistics() { diff --git a/common/database/traits/database_column_set_storage.php b/common/database/traits/database_column_set_storage.php index 544499e..320bd19 100644 --- a/common/database/traits/database_column_set_storage.php +++ b/common/database/traits/database_column_set_storage.php @@ -95,7 +95,7 @@ trait t_database_column_set_storage { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_column_set_storage() { diff --git a/common/database/traits/database_connection.php b/common/database/traits/database_connection.php index d5d8060..06c44de 100644 --- a/common/database/traits/database_connection.php +++ b/common/database/traits/database_connection.php @@ -76,10 +76,10 @@ trait t_database_connection { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_connection() { - return c_database_string::CONNECTION . ' ' . $this->connection; + return c_database_string::CONNECTION . ' ' . strval($this->connection); } } diff --git a/common/database/traits/database_constraint.php b/common/database/traits/database_constraint.php index 38e4ed8..911d545 100644 --- a/common/database/traits/database_constraint.php +++ b/common/database/traits/database_constraint.php @@ -111,7 +111,7 @@ trait t_database_constraint { * Get the currently assigned constraint settings. * * @return c_base_return_array|c_base_return_null - * An array of constraint settings on success. + * An array of constraint settings. * NULL is returned if not set (constraint is not to be used). * NULL with the error bit set is returned on error. */ @@ -134,7 +134,7 @@ trait t_database_constraint { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_constraint() { diff --git a/common/database/traits/database_cycle.php b/common/database/traits/database_cycle.php index d32376c..ccb7921 100644 --- a/common/database/traits/database_cycle.php +++ b/common/database/traits/database_cycle.php @@ -70,7 +70,7 @@ trait t_database_cycle { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_cycle() { diff --git a/common/database/traits/database_depends_on_extension.php b/common/database/traits/database_depends_on_extension.php index 334addf..ffc7d38 100644 --- a/common/database/traits/database_depends_on_extension.php +++ b/common/database/traits/database_depends_on_extension.php @@ -71,7 +71,7 @@ trait t_database_depends_on_extension { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_depends_on_extension() { diff --git a/common/database/traits/database_detach_partition.php b/common/database/traits/database_detach_partition.php new file mode 100644 index 0000000..13572a0 --- /dev/null +++ b/common/database/traits/database_detach_partition.php @@ -0,0 +1,104 @@ +detach_partition = NULL; + return new c_base_return_true(); + } + + if (!is_string($name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($bound_spec)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'bound_spec', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $placeholder_name = $this->add_placeholder($name); + if ($placeholder_name->has_error()) { + return c_base_return_error::s_false($placeholder_name->get_error()); + } + + $placeholder_bound_spec = $this->add_placeholder($bound_spec); + if ($placeholder_bound_spec->has_error()) { + unset($placeholder_name); + return c_base_return_error::s_false($placeholder_bound_spec->get_error()); + } + + $this->detach_partition = [ + 'name' => $placeholder_name, + 'bound_spec' => $placeholder_bound_spec, + ]; + unset($placeholder_name); + unset($placeholder_bound_spec); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned rename from settings. + * + * @return c_base_return_array|c_base_return_null + * An array containing detach partition settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_detach_partition() { + if (is_null($this->detach_partition)) { + return new c_base_return_null(); + } + + if (is_array($this->detach_partition)) { + return c_base_return_array::s_new($this->detach_partition); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'detach_partition', ':{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_detach_partition() { + return c_database_string::ATTACH_PARTITION . ' ' . $this->detach_partition['name'] . ' ' . c_database_string::FOR_VALUES . ' ' . $this->detach_partition['bound_spec']; + } +} diff --git a/common/database/traits/database_disable.php b/common/database/traits/database_disable.php index affa0b1..2297286 100644 --- a/common/database/traits/database_disable.php +++ b/common/database/traits/database_disable.php @@ -69,7 +69,7 @@ trait t_database_disable { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_disable() { diff --git a/common/database/traits/database_drop_table.php b/common/database/traits/database_drop_table.php index 5ac08ea..2cb0c7b 100644 --- a/common/database/traits/database_drop_table.php +++ b/common/database/traits/database_drop_table.php @@ -83,7 +83,7 @@ trait t_database_drop_value { * When NULL, all add table settings are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the add table settings on success. + * An array containing the add table settings. * NULL is returned if not set (add table not to be used). * NULL with the error bit set is returned on error. */ @@ -106,7 +106,7 @@ trait t_database_drop_value { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_drop_value() { diff --git a/common/database/traits/database_enable.php b/common/database/traits/database_enable.php index a446aff..131b2a5 100644 --- a/common/database/traits/database_enable.php +++ b/common/database/traits/database_enable.php @@ -69,7 +69,7 @@ trait t_database_enable { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_enable() { diff --git a/common/database/traits/database_enable_trigger.php b/common/database/traits/database_enable_trigger.php index 3350fdf..039e8d2 100644 --- a/common/database/traits/database_enable_trigger.php +++ b/common/database/traits/database_enable_trigger.php @@ -91,7 +91,7 @@ trait t_database_enable_trigger { * Get the currently assigned enable trigger settings. * * @return c_base_return_array|c_base_return_null - * An array containing the enable trigger settings on success. + * An array containing the enable trigger settings. * NULL is returned if not set (not to be confused with DISABLE TRIGGER). * NULL with the error bit set is returned on error. */ @@ -114,7 +114,7 @@ trait t_database_enable_trigger { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_enable_trigger() { diff --git a/common/database/traits/database_for_role.php b/common/database/traits/database_for_role.php index eb9f933..3e97d07 100644 --- a/common/database/traits/database_for_role.php +++ b/common/database/traits/database_for_role.php @@ -96,7 +96,7 @@ trait t_database_for_role { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_for_role() { diff --git a/common/database/traits/database_function_action.php b/common/database/traits/database_function_action.php index ab72f78..db43908 100644 --- a/common/database/traits/database_function_action.php +++ b/common/database/traits/database_function_action.php @@ -168,7 +168,7 @@ trait t_database_function_action { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_function_action() { diff --git a/common/database/traits/database_grant.php b/common/database/traits/database_grant.php index 84e7139..c863e2f 100644 --- a/common/database/traits/database_grant.php +++ b/common/database/traits/database_grant.php @@ -74,7 +74,7 @@ trait t_database_grant { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_grant() { diff --git a/common/database/traits/database_grant_option_for.php b/common/database/traits/database_grant_option_for.php index 5904180..ed8a935 100644 --- a/common/database/traits/database_grant_option_for.php +++ b/common/database/traits/database_grant_option_for.php @@ -72,7 +72,7 @@ trait t_database_grant_option_for { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_grant_option_for() { diff --git a/common/database/traits/database_group_by.php b/common/database/traits/database_group_by.php index 2345eef..6fa16c2 100644 --- a/common/database/traits/database_group_by.php +++ b/common/database/traits/database_group_by.php @@ -98,7 +98,7 @@ trait t_database_group_by { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_group_by() { diff --git a/common/database/traits/database_handler.php b/common/database/traits/database_handler.php index 46fcca6..89a0db0 100644 --- a/common/database/traits/database_handler.php +++ b/common/database/traits/database_handler.php @@ -97,7 +97,7 @@ trait t_database_handler { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_handler() { diff --git a/common/database/traits/database_if_exists.php b/common/database/traits/database_if_exists.php new file mode 100644 index 0000000..01f2dd8 --- /dev/null +++ b/common/database/traits/database_if_exists.php @@ -0,0 +1,81 @@ +if_exists = NULL; + return new c_base_return_true(); + } + + if (!is_bool($if_exists)) { + $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); + } + + $this->if_exists = $if_exists; + return new c_base_return_true(); + } + + /** + * Get the currently assigned set with oids status. + * + * @return c_base_return_bool|c_base_return_null + * TRUE for 'IF EXISTS' and FALSE for not using 'IF EXISTS'. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_if_exists() { + if (is_null($this->if_exists)) { + return new c_base_return_null(); + } + + if (is_bool($this->if_exists)) { + return c_base_return_bool::s_new($this->if_exists); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'if_exists', ':{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_if_exists() { + return $this->if_exists ? c_database_string::IF_EXISTS : NULL; + } +} diff --git a/common/database/traits/database_if_not_exists.php b/common/database/traits/database_if_not_exists.php new file mode 100644 index 0000000..cad6345 --- /dev/null +++ b/common/database/traits/database_if_not_exists.php @@ -0,0 +1,81 @@ +if_not_exists = NULL; + return new c_base_return_true(); + } + + if (!is_bool($if_not_exists)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'if_not_exists', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->if_not_exists = $if_not_exists; + return new c_base_return_true(); + } + + /** + * Get the currently assigned set with oids status. + * + * @return c_base_return_bool|c_base_return_null + * TRUE for 'IF NOT EXISTS' and FALSE for not using 'IF NOT EXISTS'. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_if_not_exists() { + if (is_null($this->if_not_exists)) { + return new c_base_return_null(); + } + + if (is_bool($this->if_not_exists)) { + return c_base_return_bool::s_new($this->if_not_exists); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'if_not_exists', ':{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_if_not_exists() { + return $this->if_not_exists ? c_database_string::IF_NOT_EXISTS : NULL; + } +} diff --git a/common/database/traits/database_in_database.php b/common/database/traits/database_in_database.php index d1757ee..8129fb3 100644 --- a/common/database/traits/database_in_database.php +++ b/common/database/traits/database_in_database.php @@ -76,7 +76,7 @@ trait t_database_in_database { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_in_database() { diff --git a/common/database/traits/database_in_schema.php b/common/database/traits/database_in_schema.php index bfd899a..6481158 100644 --- a/common/database/traits/database_in_schema.php +++ b/common/database/traits/database_in_schema.php @@ -97,7 +97,7 @@ trait t_database_in_schema { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_in_schema() { diff --git a/common/database/traits/database_increment_by.php b/common/database/traits/database_increment_by.php index 2ab5a87..7dc754d 100644 --- a/common/database/traits/database_increment_by.php +++ b/common/database/traits/database_increment_by.php @@ -69,7 +69,7 @@ trait t_database_increment_by { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_increment_by() { diff --git a/common/database/traits/database_inherit.php b/common/database/traits/database_inherit.php index b6a0d4a..3a0f5bf 100644 --- a/common/database/traits/database_inherit.php +++ b/common/database/traits/database_inherit.php @@ -61,7 +61,7 @@ trait t_database_inherit { * Get the currently assigned inherit settings. * * @return c_base_return_array|c_base_return_null - * An array containing the inherit settings on success. + * An array containing the inherit settings. * NULL is returned if not set. * NULL with the error bit set is returned on error. */ @@ -84,7 +84,7 @@ trait t_database_inherit { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_inherit() { diff --git a/common/database/traits/database_max_value.php b/common/database/traits/database_max_value.php index ac43fed..2b7360b 100644 --- a/common/database/traits/database_max_value.php +++ b/common/database/traits/database_max_value.php @@ -74,7 +74,7 @@ trait t_database_max_value { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_max_value() { diff --git a/common/database/traits/database_min_value.php b/common/database/traits/database_min_value.php index f2045cb..6b4194b 100644 --- a/common/database/traits/database_min_value.php +++ b/common/database/traits/database_min_value.php @@ -74,7 +74,7 @@ trait t_database_min_value { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_min_value() { diff --git a/common/database/traits/database_name.php b/common/database/traits/database_name.php index dc3fa77..6295191 100644 --- a/common/database/traits/database_name.php +++ b/common/database/traits/database_name.php @@ -76,7 +76,7 @@ trait t_database_name { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_name() { diff --git a/common/database/traits/database_no_wait.php b/common/database/traits/database_no_wait.php index 2046f0e..025d2c0 100644 --- a/common/database/traits/database_no_wait.php +++ b/common/database/traits/database_no_wait.php @@ -72,7 +72,7 @@ trait t_database_no_wait { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_no_wait() { diff --git a/common/database/traits/database_oid.php b/common/database/traits/database_oid.php index 63a9e9c..09cca75 100644 --- a/common/database/traits/database_oid.php +++ b/common/database/traits/database_oid.php @@ -76,7 +76,7 @@ trait t_database_oid { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_oid() { diff --git a/common/database/traits/database_on.php b/common/database/traits/database_on.php index 5172bab..94e8a26 100644 --- a/common/database/traits/database_on.php +++ b/common/database/traits/database_on.php @@ -59,7 +59,7 @@ trait t_database_on { * Get the ON operation status. * * @return c_base_return_int|c_base_return_null - * Integer representing the on operation is returned on success. + * Integer representing the on operation is returned. * NULL is returned if undefined. * FALSE with error bit set is returned on error. */ @@ -77,7 +77,7 @@ trait t_database_on { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_on() { diff --git a/common/database/traits/database_on_table.php b/common/database/traits/database_on_table.php index cbaa659..62f63a1 100644 --- a/common/database/traits/database_on_table.php +++ b/common/database/traits/database_on_table.php @@ -76,7 +76,7 @@ trait t_database_on_table { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_on_table() { diff --git a/common/database/traits/database_operand_left.php b/common/database/traits/database_operand_left.php index ce76d72..9a16244 100644 --- a/common/database/traits/database_operand_left.php +++ b/common/database/traits/database_operand_left.php @@ -92,7 +92,7 @@ trait t_database_operand_left { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_operand_left() { diff --git a/common/database/traits/database_operand_right.php b/common/database/traits/database_operand_right.php index c5619b9..be83e0b 100644 --- a/common/database/traits/database_operand_right.php +++ b/common/database/traits/database_operand_right.php @@ -92,7 +92,7 @@ trait t_database_operand_right { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_operand_right() { diff --git a/common/database/traits/database_options.php b/common/database/traits/database_options.php index ef936a9..16633c1 100644 --- a/common/database/traits/database_options.php +++ b/common/database/traits/database_options.php @@ -21,30 +21,40 @@ trait t_database_options { /** * Set the in options. * - * @param string|null $options_type + * @param string|null $type * The option type to use. * Set to NULL to disable. * When NULL, this will remove all values. - * @param string $value - * The value to associate with the options_type. - * When options_type is NULL, this is ignored. + * @param string|null $option + * (optional) The option name to use. + * When type is NULL, this is ignored. + * Required when $type is not NULL. + * @param string|null $value + * (optional) The value to associate with the type. + * When type is NULL, this is ignored. + * Required when $type is not NULL. * * @return c_base_return_status * TRUE on success, FALSE otherwise. * FALSE with error bit set is returned on error. */ - public function set_options($options_type, $value) { - if (is_null($options_type)) { + public function set_options($type, $option = NULL, $value = NULL) { + if (is_null($type)) { $this->options = NULL; return new c_base_return_true(); } + if (!is_string($option)) { + $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($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); } - switch ($options_type) { + switch ($type) { case e_database_options::ADD: case e_database_options::DROP: case e_database_options::SET: @@ -58,16 +68,24 @@ trait t_database_options { $this->options = []; } - $placeholder = $this->add_placeholder($value); - if ($placeholder->has_error()) { - return c_base_return_error::s_false($placeholder->get_error()); + $placeholder_option = $this->add_placeholder($option); + if ($placeholder_option->has_error()) { + return c_base_return_error::s_false($placeholder_option->get_error()); + } + + $placeholder_value = $this->add_placeholder($value); + if ($placeholder_value->has_error()) { + unset($placeholder_option); + return c_base_return_error::s_false($placeholder_value->get_error()); } $this->options[] = [ - 'type' => $options_type, - 'value' => $placeholder, + 'type' => $type, + 'option' => $placeholder_option, + 'value' => $placeholder_value, ]; - unset($placeholder); + unset($placeholder_option); + unset($placeholder_value); return new c_base_return_true(); } @@ -113,24 +131,33 @@ trait t_database_options { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_options() { - $options = []; - foreach ($this->options as $options_value) { - if ($options_value['type'] == e_database_options::ADD) { - $options[] = c_database_string::ADD . ' ' . $options_value['value']; + $value = c_database_string::OPTIONS; + + $values = []; + foreach ($this->options['values'] as $set) { + if ($set['type'] === e_database_options::ADD) { + $set_value = c_database_string::ADD; } - else if ($options_value['type'] == e_database_options::DROP) { - $options[] = c_database_string::DROP . ' ' . $options_value['value']; + else if ($set['type'] === e_database_options::DROP) { + $set_value = c_database_string::DROP; } - else if ($options_value['type'] == e_database_options::SET) { - $options[] = c_database_string::SET . ' ' . $options_value['value']; + else if ($set['type'] === e_database_options::SET) { + $set_value = c_database_string::SET; } + else { + continue; + } + + $set_value .= ' ' . $set['option'] . ' ' . $set['value']; + $values[] = $set_value; } - unset($options_value); + unset($set); + unset($set_value); - return empty($options) ? NULL : c_database_string::OPTIONS . ' ' . implode(', ', $options); + return $value . ' ' . implode(', ', $values); } } diff --git a/common/database/traits/database_order_by.php b/common/database/traits/database_order_by.php index 523f55d..7fb7ff0 100644 --- a/common/database/traits/database_order_by.php +++ b/common/database/traits/database_order_by.php @@ -96,7 +96,7 @@ trait t_database_order_by { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_order_by() { diff --git a/common/database/traits/database_owned_by.php b/common/database/traits/database_owned_by.php index 34e96e4..b96a8b7 100644 --- a/common/database/traits/database_owned_by.php +++ b/common/database/traits/database_owned_by.php @@ -111,7 +111,7 @@ trait t_database_owned_by { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_owned_by() { diff --git a/common/database/traits/database_owner_to.php b/common/database/traits/database_owner_to.php index 20e7fdd..bc064b7 100644 --- a/common/database/traits/database_owner_to.php +++ b/common/database/traits/database_owner_to.php @@ -90,7 +90,7 @@ trait t_database_owner_to { * Get the currently assigned owner to settings. * * @return c_base_return_array|c_base_return_null - * An array containing the owner to settings on success. + * An array containing the owner to settings. * NULL without error bit set is returned if not assigned. * NULL with the error bit set is returned on error. */ @@ -113,7 +113,7 @@ trait t_database_owner_to { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_owner_to() { diff --git a/common/database/traits/database_privilege.php b/common/database/traits/database_privilege.php index 1261782..9cf3c48 100644 --- a/common/database/traits/database_privilege.php +++ b/common/database/traits/database_privilege.php @@ -104,7 +104,7 @@ trait t_database_privilege { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_privilege() { diff --git a/common/database/traits/database_procedural.php b/common/database/traits/database_procedural.php index 07dac9e..293af91 100644 --- a/common/database/traits/database_procedural.php +++ b/common/database/traits/database_procedural.php @@ -72,7 +72,7 @@ trait t_database_procedural { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_procedural() { diff --git a/common/database/traits/database_refresh_publication.php b/common/database/traits/database_refresh_publication.php index 53c1dfe..9133168 100644 --- a/common/database/traits/database_refresh_publication.php +++ b/common/database/traits/database_refresh_publication.php @@ -66,7 +66,7 @@ trait t_database_refresh_publication { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_refresh_publication() { diff --git a/common/database/traits/database_rename_column.php b/common/database/traits/database_rename_column.php index ec3aa41..aaea751 100644 --- a/common/database/traits/database_rename_column.php +++ b/common/database/traits/database_rename_column.php @@ -72,7 +72,7 @@ trait t_database_rename_column { * Get the currently assigned rename from settings. * * @return c_base_return_array|c_base_return_null - * An array containing rename from settings on success. + * An array containing rename from settings. * NULL is returned if not set. * NULL with the error bit set is returned on error. */ @@ -82,7 +82,7 @@ trait t_database_rename_column { } if (is_array($this->rename_column)) { - return c_base_return_array::s_new($this->rename_column['from']); + return c_base_return_array::s_new($this->rename_column); } $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'rename_column', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); @@ -95,7 +95,7 @@ trait t_database_rename_column { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_rename_column() { diff --git a/common/database/traits/database_rename_constraint.php b/common/database/traits/database_rename_constraint.php new file mode 100644 index 0000000..fa844ae --- /dev/null +++ b/common/database/traits/database_rename_constraint.php @@ -0,0 +1,104 @@ +rename_constraint = NULL; + return new c_base_return_true(); + } + + if (!is_string($from_name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'from_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($to_name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'to_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $placeholder_from = $this->add_placeholder($from_name); + if ($placeholder_from->has_error()) { + return c_base_return_error::s_false($placeholder_from->get_error()); + } + + $placeholder_to = $this->add_placeholder($to_name); + if ($placeholder_to->has_error()) { + unset($placeholder_from); + return c_base_return_error::s_false($placeholder_to->get_error()); + } + + $this->rename_constraint = [ + 'from' => $placeholder_from, + 'to' => $placeholder_to, + ]; + unset($placeholder_from); + unset($placeholder_to); + + return new c_base_return_true(); + } + + /** + * Get the currently assigned rename from settings. + * + * @return c_base_return_array|c_base_return_null + * An array containing rename from settings. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_rename_constraint() { + if (is_null($this->rename_constraint)) { + return new c_base_return_null(); + } + + if (is_array($this->rename_constraint)) { + return c_base_return_array::s_new($this->rename_constraint); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'rename_constraint', ':{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_constraint() { + return c_database_string::RENAME_CONSTRAINT . ' ' . $this->rename_constraint['from'] . ' ' . c_database_string::TO . ' ' . $this->rename_constraint['to']; + } +} diff --git a/common/database/traits/database_rename_to.php b/common/database/traits/database_rename_to.php index 9a14549..c8da2b7 100644 --- a/common/database/traits/database_rename_to.php +++ b/common/database/traits/database_rename_to.php @@ -73,7 +73,7 @@ trait t_database_rename_to { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_rename_to() { diff --git a/common/database/traits/database_reset_configuration_parameter.php b/common/database/traits/database_reset_configuration_parameter.php index 688ba4f..cf399c7 100644 --- a/common/database/traits/database_reset_configuration_parameter.php +++ b/common/database/traits/database_reset_configuration_parameter.php @@ -81,7 +81,7 @@ trait t_database_reset_configuration_parameter { * Get the currently assigned reset configuration_parameter settings. * * @return c_base_return_array|c_base_return_null - * An array containing reset settings on success. + * An array containing reset settings. * NULL is returned if not set (reset tablespace is not to be used). * NULL with the error bit set is returned on error. */ @@ -104,7 +104,7 @@ trait t_database_reset_configuration_parameter { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_reset_configuration_parameter() { diff --git a/common/database/traits/database_reset_storage_parameter.php b/common/database/traits/database_reset_storage_parameter.php index 142a66b..cb4fcbf 100644 --- a/common/database/traits/database_reset_storage_parameter.php +++ b/common/database/traits/database_reset_storage_parameter.php @@ -100,7 +100,7 @@ trait t_database_reset_storage_parameter { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_reset_storage_parameter() { diff --git a/common/database/traits/database_restart_with.php b/common/database/traits/database_restart_with.php index c4f162d..06b8dd9 100644 --- a/common/database/traits/database_restart_with.php +++ b/common/database/traits/database_restart_with.php @@ -74,7 +74,7 @@ trait t_database_restart_with { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_restart_with() { diff --git a/common/database/traits/database_restrict.php b/common/database/traits/database_restrict.php index 9c306e9..6b43eaa 100644 --- a/common/database/traits/database_restrict.php +++ b/common/database/traits/database_restrict.php @@ -72,7 +72,7 @@ trait t_database_restrict { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_restrict() { diff --git a/common/database/traits/database_role_specification.php b/common/database/traits/database_role_specification.php index d54d9da..186621b 100644 --- a/common/database/traits/database_role_specification.php +++ b/common/database/traits/database_role_specification.php @@ -88,7 +88,7 @@ trait t_database_role_specification { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_role_specification() { diff --git a/common/database/traits/database_set_configuration_parameter.php b/common/database/traits/database_set_configuration_parameter.php index ae5a225..520597b 100644 --- a/common/database/traits/database_set_configuration_parameter.php +++ b/common/database/traits/database_set_configuration_parameter.php @@ -80,8 +80,8 @@ trait t_database_set_configuration_parameter { } $set['value'] = $placeholder; - unset($placeholder); } + unset($placeholder); $this->set_configuration_parameter = $configuration_parameter; unset($configuration_parameter); @@ -105,7 +105,7 @@ trait t_database_set_configuration_parameter { * Get the currently assigned set configuration parameter settings. * * @return c_base_return_array|c_base_return_null - * An array containing set configuration parameter settings on success. + * An array containing set configuration parameter settings. * NULL is returned if not set (set tablespace is not to be used). * NULL with the error bit set is returned on error. */ @@ -128,7 +128,7 @@ trait t_database_set_configuration_parameter { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_configuration_parameter() { diff --git a/common/database/traits/database_set_operator.php b/common/database/traits/database_set_operator.php index 55eb62c..952802d 100644 --- a/common/database/traits/database_set_operator.php +++ b/common/database/traits/database_set_operator.php @@ -118,7 +118,7 @@ trait t_database_set_operator { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_operator() { diff --git a/common/database/traits/database_set_publication_name.php b/common/database/traits/database_set_publication_name.php index 2a82eb2..72e0326 100644 --- a/common/database/traits/database_set_publication_name.php +++ b/common/database/traits/database_set_publication_name.php @@ -89,7 +89,7 @@ trait t_database_set_publication_name { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_publication_name() { diff --git a/common/database/traits/database_set_publication_parameter.php b/common/database/traits/database_set_publication_parameter.php index cbfa271..6f3629a 100644 --- a/common/database/traits/database_set_publication_parameter.php +++ b/common/database/traits/database_set_publication_parameter.php @@ -81,7 +81,7 @@ trait t_database_set_publication_parameter { * When NULL, all publication parameter types are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the set publication parameter settings on success. + * 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. */ @@ -114,7 +114,7 @@ trait t_database_set_publication_parameter { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_publication_parameter() { diff --git a/common/database/traits/database_set_schema.php b/common/database/traits/database_set_schema.php index 99431cb..05a597c 100644 --- a/common/database/traits/database_set_schema.php +++ b/common/database/traits/database_set_schema.php @@ -73,7 +73,7 @@ trait t_database_set_schema { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_schema() { diff --git a/common/database/traits/database_set_storage_parameter.php b/common/database/traits/database_set_storage_parameter.php index 3addcda..4c04a4e 100644 --- a/common/database/traits/database_set_storage_parameter.php +++ b/common/database/traits/database_set_storage_parameter.php @@ -86,7 +86,7 @@ trait t_database_set_storage_parameter { * When NULL, all index storage parameter types are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the set index storage parameter settings on success. + * 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. */ @@ -119,7 +119,7 @@ trait t_database_set_storage_parameter { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_storage_parameter() { diff --git a/common/database/traits/database_set_table.php b/common/database/traits/database_set_table.php index 330a312..63aaa32 100644 --- a/common/database/traits/database_set_table.php +++ b/common/database/traits/database_set_table.php @@ -83,7 +83,7 @@ trait t_database_set_table { * When NULL, all add table settings are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the add table settings on success. + * An array containing the add table settings. * NULL is returned if not set (add table not to be used). * NULL with the error bit set is returned on error. */ @@ -106,7 +106,7 @@ trait t_database_set_table { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_table() { diff --git a/common/database/traits/database_set_tablespace.php b/common/database/traits/database_set_tablespace.php index 5ba34fd..3c8c5b8 100644 --- a/common/database/traits/database_set_tablespace.php +++ b/common/database/traits/database_set_tablespace.php @@ -73,7 +73,7 @@ trait t_database_set_tablespace { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_tablespace() { diff --git a/common/database/traits/database_set_with_oids.php b/common/database/traits/database_set_with_oids.php index da76ffa..4b6efd2 100644 --- a/common/database/traits/database_set_with_oids.php +++ b/common/database/traits/database_set_with_oids.php @@ -72,7 +72,7 @@ trait t_database_set_with_oids { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_with_oids() { diff --git a/common/database/traits/database_set_without_cluster.php b/common/database/traits/database_set_without_cluster.php index 7fc3235..170cf76 100644 --- a/common/database/traits/database_set_without_cluster.php +++ b/common/database/traits/database_set_without_cluster.php @@ -72,7 +72,7 @@ trait t_database_set_without_cluster { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_set_without_cluster() { diff --git a/common/database/traits/database_start_with.php b/common/database/traits/database_start_with.php index 013d098..6f36e9a 100644 --- a/common/database/traits/database_start_with.php +++ b/common/database/traits/database_start_with.php @@ -69,7 +69,7 @@ trait t_database_start_with { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_start_with() { diff --git a/common/database/traits/database_to_role.php b/common/database/traits/database_to_role.php index 1652343..7bbfff7 100644 --- a/common/database/traits/database_to_role.php +++ b/common/database/traits/database_to_role.php @@ -114,7 +114,7 @@ trait t_database_to_role { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_to_role() { diff --git a/common/database/traits/database_using_expression.php b/common/database/traits/database_using_expression.php index 383c519..4a389c2 100644 --- a/common/database/traits/database_using_expression.php +++ b/common/database/traits/database_using_expression.php @@ -71,7 +71,7 @@ trait t_database_using_expression { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_using_expression() { diff --git a/common/database/traits/database_using_index_method.php b/common/database/traits/database_using_index_method.php index 169dfa8..1057b9c 100644 --- a/common/database/traits/database_using_index_method.php +++ b/common/database/traits/database_using_index_method.php @@ -76,7 +76,7 @@ trait t_database_using_index_method { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_using_index_method() { diff --git a/common/database/traits/database_validator.php b/common/database/traits/database_validator.php index 46f5d24..61a6c7f 100644 --- a/common/database/traits/database_validator.php +++ b/common/database/traits/database_validator.php @@ -96,7 +96,7 @@ trait t_database_validator { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_validator() { diff --git a/common/database/traits/database_version.php b/common/database/traits/database_version.php index 21fb5dd..3f7d7ac 100644 --- a/common/database/traits/database_version.php +++ b/common/database/traits/database_version.php @@ -76,7 +76,7 @@ trait t_database_version { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_version() { diff --git a/common/database/traits/database_wildcard.php b/common/database/traits/database_wildcard.php new file mode 100644 index 0000000..311351a --- /dev/null +++ b/common/database/traits/database_wildcard.php @@ -0,0 +1,81 @@ +wildcard = NULL; + return new c_base_return_true(); + } + + if (!is_bool($wildcard)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'wildcard', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->wildcard = $wildcard; + return new c_base_return_true(); + } + + /** + * Get the currently assigned set with oids status. + * + * @return c_base_return_bool|c_base_return_null + * TRUE for '*' and FALSE for not using '*'. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_wildcard() { + if (is_null($this->wildcard)) { + return new c_base_return_null(); + } + + if (is_bool($this->wildcard)) { + return c_base_return_bool::s_new($this->wildcard); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'wildcard', ':{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_wildcard() { + return $this->wildcard ? '*' : NULL; + } +} diff --git a/common/database/traits/database_with_check_expression.php b/common/database/traits/database_with_check_expression.php index 3591eb2..253197e 100644 --- a/common/database/traits/database_with_check_expression.php +++ b/common/database/traits/database_with_check_expression.php @@ -71,7 +71,7 @@ trait t_database_with_check_expression { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_with_check_expression() { diff --git a/common/database/traits/database_with_grant_option.php b/common/database/traits/database_with_grant_option.php index 6ccefa8..100f144 100644 --- a/common/database/traits/database_with_grant_option.php +++ b/common/database/traits/database_with_grant_option.php @@ -72,7 +72,7 @@ trait t_database_with_grant_option { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_with_grant_option() { diff --git a/common/database/traits/database_with_publication_option.php b/common/database/traits/database_with_publication_option.php index 1b6695f..48eb368 100644 --- a/common/database/traits/database_with_publication_option.php +++ b/common/database/traits/database_with_publication_option.php @@ -75,7 +75,7 @@ trait t_database_with_publication_option { * When NULL, all publication options are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the with publication option settings on success. + * An array containing the with publication option settings. * NULL is returned if not set (with publication option not to be used). * NULL with the error bit set is returned on error. */ @@ -108,7 +108,7 @@ trait t_database_with_publication_option { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_with_publication_option() { diff --git a/common/database/traits/database_with_refresh_option.php b/common/database/traits/database_with_refresh_option.php index 77c458c..8c0cfed 100644 --- a/common/database/traits/database_with_refresh_option.php +++ b/common/database/traits/database_with_refresh_option.php @@ -75,7 +75,7 @@ trait t_database_with_refresh_option { * When NULL, all refresh options are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the with refresh option settings on success. + * An array containing the with refresh 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. */ @@ -108,7 +108,7 @@ trait t_database_with_refresh_option { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_with_refresh_option() { diff --git a/common/database/traits/database_with_role_option.php b/common/database/traits/database_with_role_option.php index a3ed53b..cede4b1 100644 --- a/common/database/traits/database_with_role_option.php +++ b/common/database/traits/database_with_role_option.php @@ -114,7 +114,7 @@ trait t_database_with_role_option { * Get the with role option settings. * * @return c_base_return_array|c_base_return_null - * An array of with role option settings on success. + * An array of with role option settings. * NULL is returned if not set (with role option is not to be used). * NULL with the error bit set is returned on error. */ @@ -137,7 +137,7 @@ trait t_database_with_role_option { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_with_role_option() { diff --git a/common/database/traits/database_with_storage_parameter.php b/common/database/traits/database_with_storage_parameter.php index 0af7ea4..5fca01f 100644 --- a/common/database/traits/database_with_storage_parameter.php +++ b/common/database/traits/database_with_storage_parameter.php @@ -86,7 +86,7 @@ trait t_database_with_storage_parameter { * When NULL, all index storage parameter types are returned. * * @return c_base_return_array|c_base_return_null - * An array containing the set index storage parameter settings on success. + * 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. */ @@ -119,7 +119,7 @@ trait t_database_with_storage_parameter { * As an internal trait method, the caller is expected to perform any appropriate validation. * * @return string|null - * A string is returned on success. + * A string is returned. * NULL is returned if there is nothing to process or there is an error. */ protected function p_do_build_with_storage_parameter() {