/**
* Get the total aggregate signatures.
*
+ * @param int|null $index
+ * (optional) Get the aggregate signature at the specified index.
+ * When NULL, all aggregate signatures are returned.
+ *
* @return c_base_return_int
* The total number of aggregate signatures.
* 0 with the error bit set is returned on error.
$aggregate_signatures = ' *';
}
else {
- // [ argument_mode ] [ argument_name ] argument_type [, ...]
foreach ($this->aggregate_signatures as $aggregate_signature) {
if ($aggregate_signature instanceof c_database_argument_aggregate_signature) {
if (is_null($aggregate_signatures)) {
}
unset($aggregate_signature);
- // ORDER BY [ argument_mode ] [ argument_name ] argument_type [, ...]
$order_by_signatures = NULL;
foreach ($this->order_by_signatures as $order_by_signature) {
if ($order_by_signature instanceof c_database_argument_aggregate_signature_base) {
unset($order_by_signatures);
}
- $value = NULL;
+ $value = $this->p_do_build_name() . ' ';
if (is_string($this->rename_to)) {
- $value = $aggregate_signatures . ' ' . $this->p_do_build_rename_to();
+ $value .= $aggregate_signatures . ' ' . $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $value = $aggregate_signatures . ' ' . $this->p_do_build_owner_to();
+ $value .= $aggregate_signatures . ' ' . $this->p_do_build_owner_to();
}
else if (is_string($this->set_schema)) {
- $value = $aggregate_signatures . ' ' . $this->p_do_build_set_schema();
+ $value .= $aggregate_signatures . ' ' . $this->p_do_build_set_schema();
}
else {
unset($aggregate_signatures);
unset($aggregate_signatures);
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
$this->value .= ' ' . $value;
unset($value);
return new c_base_return_false();
}
- $value = NULL;
+ $value = $this->p_do_build_name();
if (is_bool($this->refresh_version)) {
if ($this->refresh_version) {
- $value = c_database_string::REFRESH_VERSION;
+ $value .= c_database_string::REFRESH_VERSION;
}
}
else if (is_string($this->rename_to)) {
- $value = $this->p_do_build_rename_to();
+ $value .= $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $value = $this->p_do_build_owner_to();
+ $value .= $this->p_do_build_owner_to();
}
else if (is_string($this->set_schema)) {
- $value = $this->p_do_build_set_schema();
+ $value .= $this->p_do_build_set_schema();
}
else {
unset($value);
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
$this->value .= ' ' . $value;
unset($value);
return new c_base_return_false();
}
- $value = NULL;
+ $value = $this->p_do_build_name() . ' ';
if (is_string($this->rename_to)) {
- $value = $this->p_do_build_rename_to();
+ $value .= $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $value = $this->p_do_build_owner_to();
+ $value .= $this->p_do_build_owner_to();
}
else if (is_string($this->set_schema)) {
- $value = $this->p_do_build_set_schema();
+ $value .= $this->p_do_build_set_schema();
}
else {
unset($value);
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
$this->value .= ' ' . $value;
unset($value);
return new c_base_return_false();
}
- $value = NULL;
+ $value = $this->p_do_build_name() . ' ';
if ($this->option instanceof c_database_argument_database_option) {
- $this->option->do_build_argument();
- $value = $this->option->get_value_exact();
+ // @todo: review this, the code may and probably should be converted into a trait.
+ if ($this->option->do_build_argument() instanceof c_base_return_true) {
+ $value .= $this->option->get_value_exact();
+ }
}
else if (is_string($this->rename_to)) {
- $value = $this->p_do_build_rename_to();
+ $value .= $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $value = $this->p_do_build_owner_to();
+ $value .= $this->p_do_build_owner_to();
}
else if (is_string($this->set_tablespace)) {
- $value = $this->p_do_build_set_tablespace();
+ $value .= $this->p_do_build_set_tablespace();
}
else if (is_array($this->set)) {
- $value = $this->p_do_build_set();
+ $value .= $this->p_do_build_set();
}
else if (is_array($this->reset)) {
- $value = $this->p_do_build_reset();
+ $value .= $this->p_do_build_reset();
}
else {
unset($value);
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
$this->value .= ' ' . $value;
unset($value);
require_once('common/base/classes/base_error.php');
require_once('common/base/classes/base_return.php');
-require_once('common/database/enumerations/database_action.php');
require_once('common/database/enumerations/database_cascade.php');
-require_once('common/database/enumerations/database_on.php');
require_once('common/database/enumerations/database_privilege.php');
require_once('common/database/classes/database_query.php');
require_once('common/database/enumerations/database_cascade.php');
+require_once('common/database/enumerations/database_grant.php');
-require_once('common/database/traits/database_action.php');
require_once('common/database/traits/database_cascade.php');
require_once('common/database/traits/database_for_role.php');
+require_once('common/database/traits/database_grant.php');
require_once('common/database/traits/database_grant_option_for.php');
require_once('common/database/traits/database_in_schema.php');
+require_once('common/database/traits/database_on.php');
+require_once('common/database/traits/database_privilege.php');
+require_once('common/database/traits/database_to_role.php');
require_once('common/database/traits/database_with_grant_option.php');
/**
* @see: https://www.postgresql.org/docs/current/static/sql-alterdefaultpriveleges.html
*/
class c_database_alter_default_priveleges extends c_database_query {
- use t_database_action;
use t_database_cascade;
use t_database_for_role;
+ use t_database_grant;
use t_database_grant_option_for;
use t_database_in_schema;
+ use t_database_on;
+ use t_database_privilege;
+ use t_database_to_role;
use t_database_with_grant_option;
protected const p_QUERY_COMMAND = 'alter default privileges';
- protected $abbreviated;
- protected $on;
- protected $privileges;
- protected $role_names;
-
/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
- $this->action = NULL;
$this->cascade = NULL;
$this->for_role = NULL;
+ $this->grant = NULL;
$this->grant_option_for = NULL;
$this->in_schema = NULL;
+ $this->on = NULL;
+ $this->privilege = NULL;
+ $this->to_role = NULL;
$this->with_grant_option = NULL;
-
- $this->abbreviated = NULL;
- $this->on = NULL;
- $this->privileges = NULL;
- $this->role_names = NULL;
}
/**
public function __destruct() {
parent::__destruct();
- unset($this->action);
unset($this->cascade);
unset($this->for_role);
+ unset($this->grant);
unset($this->grant_option_for);
unset($this->in_schema);
- unset($this->with_grant_option);
-
- unset($this->abbreviated);
unset($this->on);
- unset($this->privileges);
- unset($this->role_names);
+ unset($this->privilege);
+ unset($this->to_role);
+ unset($this->with_grant_option);
}
/**
}
/**
- * Assigns the SQL ON operation.
- *
- * @param int|null $on
- * Whether or not to use the ON operation in the query.
- * 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_on($on) {
- if (is_null($on)) {
- $this->on = NULL;
- return new c_base_return_true();
- }
-
- switch ($on) {
- case e_database_on::TABLES_TO:
- case e_database_on::SEQUENCES:
- case e_database_on::FUNCTIONS:
- case e_database_on::TYPES:
- case e_database_on::SCHEMAS:
- $this->on = $on;
- return new c_base_return_true();
- default:
- break;
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'on', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- /**
- * Assigns the SQL privileges.
- *
- * @param int|null $privilege
- * Whether or not to use the ON operation in the query.
- * Set to NULL to disable.
- * When NULL, this will remove all values.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- * FALSE with error bit set is returned on error.
- */
- public function set_privilege($privilege) {
- if (is_null($privilege)) {
- $this->privileges = NULL;
- return new c_base_return_true();
- }
-
- if (is_int($privilege)) {
- if (!is_array($this->privilege)) {
- $this->privileges = [];
- }
-
- $this->privileges[] = $privilege;
- return new c_base_return_true();
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'privilege', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- /**
- * Set the role names.
- *
- * @param c_database_argument_role_name|null $role_name
- * The role name to use.
- * Set to NULL to disable.
- * When NULL, this will remove all values.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- * FALSE with error bit set is returned on error.
- */
- public function set_role_name($role_name) {
- if (is_null($role_name)) {
- $this->role_names = NULL;
- return new c_base_return_true();
- }
-
- if ($role_name instanceof c_database_argument_role_name) {
- if (!is_array($this->role_names)) {
- $this->role_names = [];
- }
-
- $this->role_names[] = $role_name;
- return new c_base_return_true();
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'role_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- /**
- * Get the role names.
- *
- * @param int|null $index
- * (optional) Get the role name at the specified index.
- * When NULL, all role names are returned.
- *
- * @return c_database_argument_role_name|c_base_return_array|c_base_return_null
- * An array of role names or NULL if not defined.
- * A single role name is returned if $index is an integer.
- * NULL with the error bit set is returned on error.
- */
- public function get_role_name($index = NULL) {
- if (is_null($this->role_names)) {
- return new c_base_return_null();
- }
-
- if (is_null($index)) {
- if (is_array($this->role_names)) {
- return c_base_return_array::s_new($this->role_names);
- }
- }
- else {
- if (is_int($index) && array_key_exists($index, $this->role_names) && $this->role_names[$index] instanceof c_database_argument_role_name) {
- return $this->role_names[$index];
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'role_names[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}' => 'role_names', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
- return c_base_return_error::s_null($error);
- }
-
- /**
- * Get the ON operation status.
- *
- * @return c_base_return_int|c_base_return_null
- * Integer representing the on operation is returned on success.
- * NULL is returned if undefined.
- * FALSE with error bit set is returned on error.
- */
- protected function get_on() {
- if (is_null($this->on)) {
- return new c_base_return_null();
- }
-
- return c_base_return_int::s_new($this->on);
- }
-
- /**
- * Get the privileges.
- *
- * @param int|null $index
- * (optional) Get the privilege at the specified index.
- * When NULL, all privileges are returned.
- *
- * @return int|c_base_return_array|c_base_return_null
- * An array of privileges or NULL if not defined.
- * A single privilege is returned if $index is an integer.
- * NULL with the error bit set is returned on error.
- */
- public function get_privilege($index = NULL) {
- if (is_null($this->privileges)) {
- return new c_base_return_null();
- }
-
- if (is_null($index)) {
- if (is_array($this->privileges)) {
- return c_base_return_array::s_new($this->privileges);
- }
- }
- else {
- if (is_int($index) && array_key_exists($index, $this->privileges) && $this->privileges[$index] instanceof c_database_argument_aggregate_signature) {
- return clone($this->privileges[$index]);
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'privileges[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}' => 'privileges', ':{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->grant) || !(is_array($this->role_names) && !empty($this->role_names))) {
+ if (is_null($this->grant) || !(is_array($this->to_role) && !empty($this->to_role))) {
return new c_base_return_false();
}
- switch ($this->action) {
- case e_database_action::_GRANT:
- case e_database_action::_REVOKE:
- break;
- default:
- return new c_base_return_false();
- }
-
$value = NULL;
if ($this->for_role) {
$value .= $this->p_do_build_for_role();
}
- // [ IN SCHEMA schema_name [, ... ] ]
if (is_array($this->in_schema) && !empty($this->in_schema)) {
$value .= is_null($value) ? '' : ' ';
$value .= $this->p_do_build_in_schema();
}
- if ($this->action === e_database_action::ACTION_GRANT) {
+ if (is_int($this->grant)) {
$value .= is_null($value) ? '' : ' ';
- $value .= c_database_string::GRANT;
- }
- else if ($this->action === e_database_action::ACTION_REVOKE) {
- $value .= is_null($value) ? '' : ' ';
- $value .= c_database_string::REVOKE;
+ $value .= $this->p_do_build_grant();
- if ($this->grant_option_for) {
- $value .= ' ' . $this->p_do_build_grant_option_for();
- }
- }
-
- // [ { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | USAGE | EXECUTE | CREATE } [, ...] | ALL ]
- $privileges = '';
- foreach ($this->privileges as $privilege) {
- $privileges .= ', ';
- switch ($privilege) {
- case e_database_privilege::SELECT:
- $privileges .= c_database_string::SELECT;
- break;
- case e_database_privilege::INSERT:
- $privileges .= c_database_string::INSERT;
- break;
- case e_database_privilege::UPDATE:
- $privileges .= c_database_string::UPDATE;
- break;
- case e_database_privilege::DELETE:
- $privileges .= c_database_string::DELETE;
- break;
- case e_database_privilege::TRUNCATE:
- $privileges .= c_database_string::TRUNCATE;
- break;
- case e_database_privilege::REFERENCES:
- $privileges .= c_database_string::REFERENCES;
- break;
- case e_database_privilege::TRIGGER:
- $privileges .= c_database_string::TRIGGER;
- break;
- case e_database_privilege::USAGE:
- $privileges .= c_database_string::USAGE;
- break;
- case e_database_privilege::EXECUTE:
- $privileges .= c_database_string::EXECUTE;
- break;
- case e_database_privilege::CREATE:
- $privileges .= c_database_string::CREATE;
- break;
- case e_database_privilege::ALL:
- $privileges .= c_database_string::ALL;
- break;
- default:
- break;
+ if ($this->grant === e_database_action::ACTION_REVOKE) {
+ if ($this->grant_option_for) {
+ $value .= ' ' . $this->p_do_build_grant_option_for();
+ }
}
}
$value .= is_null($value) ? '' : ' ';
- $value .= ltrim($privileges, ', ');
- unset($privileges);
+ $value .= $this->p_do_build_privilege();
- // ON ...
- switch($this->on) {
- case e_database_on::TABLES_TO:
- $value .= ' ' . c_database_string::ON_TABLES_TO;
- break;
- case e_database_on::SEQUENCES:
- $value .= ' ' . c_database_string::ON_SEQUENCES;
- break;
- case e_database_on::FUNCTIONS:
- $value .= ' ' . c_database_string::ON_FUNCTIONS;
- break;
- case e_database_on::TYPES:
- $value .= ' ' . c_database_string::ON_TYPES;
- break;
- case e_database_on::SCHEMAS:
- $value .= ' ' . c_database_string::ON_SCHEMAS;
- break;
+ if (is_int($this->on)) {
+ $value .= ' ' . $this->p_do_build_on();
}
- // [ TO | FROM ] ... role names ...
- if ($this->action === e_database_action::GRANT) {
+ if ($this->grant === e_database_action::GRANT) {
$value .= ' ' . c_database_string::TO;
}
- else if ($this->action === e_database_action::REVOKE) {
+ else if ($this->grant === e_database_action::REVOKE) {
$value .= ' ' . c_database_string::FROM;
}
- foreach ($this->role_names as $role_name) {
- if (!($role_name instanceof c_database_argument_role_name)) {
- continue;
- }
-
- $role_name->do_build_argument();
- $value .= ' ' . $role_name->get_value_exact();
+ if (is_array($this->to_role)) {
+ $value .= ' ' . $this->p_do_build_to_role();
}
- unset($role_name);
- if ($this->action === e_database_action::GRANT) {
+ if ($this->grant === e_database_action::GRANT) {
if ($this->with_grant_option) {
$value .= ' ' . $this->p_do_build_with_grant_option();
}
}
- else if ($this->action === e_database_action::REVOKE) {
+ else if ($this->grant === e_database_action::REVOKE) {
if (is_int($this->cascade)) {
$value .= ' ' . $this->p_do_build_cascade();
}
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
$this->value .= ' ' . $value;
unset($value);
$this->name = NULL;
$this->owner_to = NULL;
$this->rename_to = NULL;
- $this->set_schema = NULL
+ $this->set_schema = NULL;
$this->expression = NULL;
$this->constraint = NULL;
return new c_base_return_false();
}
- $action = NULL;
+ $value = $this->p_do_build_name() . ' ';
switch ($this->action) {
case e_database_action::ADD:
if (!is_array($this->constraint)) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = c_database_string::ADD;
- $action .= ' ' . $this->constraint['name'];
+ $value .= c_database_string::ADD;
+ $value .= ' ' . $this->constraint['name'];
if ($this->property === e_database_property::NOT_VALID) {
- $action .= ' ' . c_database_string::NOT_VALID;
+ $value .= ' ' . c_database_string::NOT_VALID;
}
break;
case e_database_action::DROP:
- $action = c_database_string::DROP;
+ $value .= c_database_string::DROP;
if ($this->property === e_database_property::NOT_NULL) {
- $action .= ' ' . c_database_string::NOT_NULL;
+ $value .= ' ' . c_database_string::NOT_NULL;
}
break;
case e_database_action::DROP_CONSTRAINT:
if (!is_array($this->constraint['name'])) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = c_database_string::DROP_CONSTRAINT;
+ $value .= c_database_string::DROP_CONSTRAINT;
if ($this->property === e_database_property::IF_EXISTS) {
- $action .= ' ' . c_database_string::IF_EXISTS;
+ $value .= ' ' . c_database_string::IF_EXISTS;
}
- $action .= ' ' . $this->constraint['name'];
+ $value .= ' ' . $this->constraint['name'];
if ($this->constraint['cascade'] === e_database_cascade::CASCADE) {
- $action .= ' ' . c_database_string::CASCADE;
+ $value .= ' ' . c_database_string::CASCADE;
}
else if ($this->constraint['cascade'] === e_database_cascade::RESTRICT) {
- $action .= ' ' . c_database_string::RESTRICT;
+ $value .= ' ' . c_database_string::RESTRICT;
}
break;
case e_database_action::DROP_DEFAULT:
- $action = c_database_string::DROP_DEFAULT;
+ $value .= c_database_string::DROP_DEFAULT;
break;
case e_database_action::OWNER_TO:
if (!is_string($this->owner_to)) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = $this->p_do_build_owner_to();
+ $value .= $this->p_do_build_owner_to();
break;
case e_database_action::RENAME_CONSTRAINT:
if (!is_string($this->constraint['name']) || !is_string($this->constraint['name_new'])) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = c_database_string::RENAME_CONSTRAINT . ' ' . $this->constraint['name'] . ' ' . c_database_string::TO . ' ' . $this->constraint['name_new'];
+ $value .= c_database_string::RENAME_CONSTRAINT . ' ' . $this->constraint['name'] . ' ' . c_database_string::TO . ' ' . $this->constraint['name_new'];
break;
case e_database_action::RENAME_TO:
if (!is_string($this->rename_to)) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = $this->p_do_build_rename_to();
+ $value .= $this->p_do_build_rename_to();
break;
case e_database_action::SET:
- $action = c_database_string::SET;
+ $value = c_database_string::SET;
if ($this->property === e_database_property::NOT_NULL) {
- $action .= ' ' . c_database_string::NOT_NULL;
+ $value .= ' ' . c_database_string::NOT_NULL;
}
break;
case e_database_action::SET_DEFAULT:
if (!is_string($this->expression)) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = c_database_string::SET_DEFAULT . ' ' . $this->expression;
+ $value .= c_database_string::SET_DEFAULT . ' ' . $this->expression;
break;
case e_database_action::SET_SCHEMA:
if (!is_string($this->set_schema)) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = $this->p_do_build_set_schema();
+ $value .= $this->p_do_build_set_schema();
break;
case e_database_action::VALIDATE_CONSTRAINT:
if (!is_array($this->constraint)) {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- $action = c_database_string::VALIDATE_CONSTRAINT . ' ' . $this->constraint['name'];
+ $value .= c_database_string::VALIDATE_CONSTRAINT . ' ' . $this->constraint['name'];
break;
default:
- unset($action);
+ unset($value);
return new c_base_return_false();
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
- $this->value .= ' ' . $action;
- unset($action);
+ $this->value .= ' ' . $value;
+ unset($value);
return new c_base_return_true();
}
return new c_base_return_false();
}
- $action = NULL;
+ $value = $this->p_do_build_name() . ' ';
switch($this->action) {
case e_database_action::DISABLE:
- $this->action = c_database_string::DISABLE;
+ $value .= c_database_string::DISABLE;
break;
case e_database_action::ENABLE:
- $action = c_database_string::ENABLE;
+ $value .= c_database_string::ENABLE;
if ($this->action_property === e_database_property::REPLICA) {
- $action .= ' ' . c_database_string::REPLICA;
+ $value .= ' ' . c_database_string::REPLICA;
}
else if ($this->action_property === e_database_property::ALWAYS) {
- $action .= ' ' . c_database_string::ALWAYS;
+ $value .= ' ' . c_database_string::ALWAYS;
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_action::OWNER_TO:
if (is_string($this->owner_to)) {
- $action = $this->p_do_build_owner_to();
+ $value .= $this->p_do_build_owner_to();
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_action::RENAME_TO:
if (is_string($this->rename_to)) {
- $action = $this->p_do_build_rename_to();
+ $value .= $this->p_do_build_rename_to();
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
default:
- unset($action);
+ unset($value);
return new c_base_return_false();
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $action;
- unset($action);
+ $this->value .= ' ' . $value;
+ unset($value);
return new c_base_return_true();
}
return new c_base_return_false();
}
- $action = $this->name . ' ';
+ $value = $this->p_do_build_name() . ' ';
switch($this->action) {
case e_database_action::UPDATE:
- $action .= c_database_string::UPDATE;
+ $value .= c_database_string::UPDATE;
if (is_string($this->action_parameter)) {
- $action .= ' ' . c_database_string::TO . ' ' . $this->action_parameter;
+ $value .= ' ' . c_database_string::TO . ' ' . $this->action_parameter;
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_action::SET_SCHEMA:
if (is_string($this->set_schema)) {
- $action = $this->p_do_build_set_schema();
+ $value = $this->p_do_build_set_schema();
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_action::ADD:
- $action .= c_database_string::ADD;
+ $value .= c_database_string::ADD;
if ($this->action_parameter instanceof c_database_member_object && $this->action_parameter->do_build() instanceof c_base_return_true) {
- $action .= ' ' . $this->action_parameter->get_value();
+ $value .= ' ' . $this->action_parameter->get_value();
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_action::DROP:
- $action .= c_database_string::DROP;
+ $value .= c_database_string::DROP;
if ($this->action_parameter instanceof c_database_member_object) {
if ($this->action_parameter->do_build() instanceof c_base_return_true) {
- $action .= ' ' . $this->action_parameter->get_value();
+ $value .= ' ' . $this->action_parameter->get_value();
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
default:
- unset($action);
+ unset($value);
return new c_base_return_false();
}
- unset($action);
+ unset($value);
- $this->value = $action;
+ $this->value = $value;
return new c_base_return_true();
}
}
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
+ $this->value .= ' ' . $this->p_do_build_name();
$this->value .= ' ' . $action;
unset($action);
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $this->name;
+ $this->value .= ' ' . $this->p_do_build_name();
if ($this->include_descendents) {
$this->value .' *';
<?php
/**
* @file
- * Provides a class for specific Postgesql query: ALTER COALATION.
+ * Provides a class for specific Postgesql query: ALTER FUNCTION.
*/
namespace n_koopa;
require_once('common/database/classes/database_query.php');
+require_once('common/database/traits/database_argument_type.php');
+require_once('common/database/traits/database_depends_on_extension.php');
+require_once('common/database/traits/database_function_action.php');
+require_once('common/database/traits/database_name.php');
+require_once('common/database/traits/database_owner_to.php');
+require_once('common/database/traits/database_rename_to.php');
+require_once('common/database/traits/database_restrict.php');
+require_once('common/database/traits/database_set_schema.php');
/**
* The class for building and returning a Postgresql ALTER COALATION query string.
* @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
*/
class c_database_alter_coalation extends c_database_query {
- protected const p_QUERY_COMMAND = 'alter coalation';
+ use t_database_argument_type;
+ use t_database_depends_on_extension;
+ use t_database_function_action;
+ use t_database_name;
+ use t_database_owner_to;
+ use t_database_rename_to;
+ use t_database_restrict;
+ use t_database_set_schema;
+ protected const p_QUERY_COMMAND = 'alter function';
/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
+
+ $this->argument_type = NULL;
+ $this->depends_on_extension = NULL;
+ $this->function_action = NULL;
+ $this->name = NULL;
+ $this->owner_to = NULL;
+ $this->rename_to = NULL;
+ $this->restrict = NULL;
+ $this->set_schema = NULL;
}
/**
* Class destructor.
*/
public function __destruct() {
+ unset($this->argument_type);
+ unset($this->depends_on_extension);
+ unset($this->function_action);
+ unset($this->name);
+ unset($this->owner_to);
+ unset($this->rename_to);
+ unset($this->restrict);
+ unset($this->set_schema);
+
parent::__destruct();
}
* Implements do_build().
*/
public function do_build() {
- $this->value = NULL;
+ if (!is_string($this->name)) {
+ return new c_base_return_false();
+ }
+
+ $value = $this->p_do_build_name();
+
+ if (is_array($this->argument_type) && !empty($this->argument_type)) {
+ $value .= ' ' . $this->p_do_build_argument_type();
+ }
+
+ if (is_array($this->function_action)) {
+ $value .= ' ' . $this->p_do_build_function_action();
+
+ if ($this->restrict) {
+ $value .= ' ' . $this->p_do_build_restrict();
+ }
+ }
+ else if (is_string($this->rename_to)) {
+ $value .= $this->p_do_build_rename_to();
+ }
+ else if (is_string($this->owner_to)) {
+ $value .= $this->p_do_build_owner_to();
+ }
+ else if (is_string($this->set_schema)) {
+ $value .= $this->p_do_build_set_schema();
+ }
+ else if (is_string($this->depends_on_extension)) {
+ $value .= $this->p_do_build_depends_on_extension();
+ }
+ else {
+ unset($value);
+ return new c_base_return_false();
+ }
- // @todo
+ $this->value = static::p_QUERY_COMMAND;
+ $this->value .= ' ' . $value;
+ unset($value);
return new c_base_return_true();
}
return new c_base_return_false();
}
- $action = NULL;
+ $value = NULL;
switch($this->action) {
case e_database_method_object::ACCESS_METHOD:
- $action = c_database_string::ACCESS_METHOD . ' ' . $this->name;
+ $value = c_database_string::ACCESS_METHOD . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::AGGREGATE:
- $action = c_database_string::AGGREGATE . ' ' . $this->name;
+ $value = c_database_string::AGGREGATE . ' ' . $this->p_do_build_name();
// TODO: as a query argument?
if ($this->action_parameter instanceof c_database_alter_aggregate && $this->action_parameter->do_build()) {
- $action .= ' ( ' . $this->action_parameter->get_value() . ' )';
+ $value .= ' ( ' . $this->action_parameter->get_value() . ' )';
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_method_object::CAST:
// uses 'name' property to represent AS 'source_type'
- $action = c_database_string::CAST;
+ $value = c_database_string::CAST;
if (is_string($this->action_parameter)) {
- $action .= ' ' . $this->name . ' ' . c_database_string::AS . ' ( ' . $this->action_parameter . ' )';
+ $value .= ' ' . $this->p_do_build_name() . ' ' . c_database_string::AS . ' ( ' . $this->action_parameter . ' )';
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_method_object::COLLATION:
- $action = c_database_string::COLLATION . ' ' . $this->name;
+ $value = c_database_string::COLLATION . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::CONVERSION:
- $action = c_database_string::CONVERSION . ' ' . $this->name;
+ $value = c_database_string::CONVERSION . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::DOMAIN:
- $action = c_database_string::DOMAIN . ' ' . $this->name;
+ $value = c_database_string::DOMAIN . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::EVENT_TRIGGER:
- $action = c_database_string::EVENT_TRIGGER . ' ' . $this->name;
+ $value = c_database_string::EVENT_TRIGGER . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::FOREIGN_DATA_WRAPPER:
- $action = c_database_string::FOREIGN_DATA_WRAPPER . ' ' . $this->name;
+ $value = c_database_string::FOREIGN_DATA_WRAPPER . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::FOREIGN_TABLE:
- $action = c_database_string::FOREIGN_TABLE . ' ' . $this->name;
+ $value = c_database_string::FOREIGN_TABLE . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::FUNCTION:
- $action = c_database_string::FUNCTION . ' ' . $this->name;
+ $value = c_database_string::FUNCTION . ' ' . $this->p_do_build_name();
// TODO: finish adding support for function
// TODO: as a query argument?
/*if ($this->action_parameter instanceof c_database_function && $this->action_parameter->do_build()) {
- $action .= ' ( ' . $this->action_parameter->get_value() . ' )';
+ $value .= ' ( ' . $this->action_parameter->get_value() . ' )';
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}*/
break;
case e_database_method_object::MATERIALIZED_VIEW:
- $action = c_database_string::MATERIALIZED_VIEW . ' ' . $this->name;
+ $value = c_database_string::MATERIALIZED_VIEW . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::OPERATOR:
- $action = c_database_string::OPERATOR . ' ' . $this->name;
+ $value = c_database_string::OPERATOR . ' ' . $this->p_do_build_name();
if (isset($this->action_parameter[0]) && is_string($this->action_parameter[0]) && isset($this->action_parameter[1]) && is_string($this->action_parameter[1])) {
- $action .= ' ' . $this->action_parameter[0] . ' ( ' . $this->action_parameter[0] . ', ' . $this->action_parameter[1] . ' )';
+ $value .= ' ' . $this->action_parameter[0] . ' ( ' . $this->action_parameter[0] . ', ' . $this->action_parameter[1] . ' )';
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_method_object::OPERATOR_CLASS:
- $action = c_database_string::OPERATOR_CLASS . ' ' . $this->name;
+ $value = c_database_string::OPERATOR_CLASS . ' ' . $this->p_do_build_name();
if (is_string($this->action_parameter)) {
- $action .= ' ' . c_database_string::USING . ' ' . $this->action_parameter;
+ $value .= ' ' . c_database_string::USING . ' ' . $this->action_parameter;
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_method_object::OPERATOR_FAMILY:
- $action = c_database_string::OPERATOR_FAMILY . ' ' . $this->name;
+ $value = c_database_string::OPERATOR_FAMILY . ' ' . $this->p_do_build_name();
if (is_string($this->action_parameter)) {
- $action .= ' ' . c_database_string::USING . ' ' . $this->action_parameter;
+ $value .= ' ' . c_database_string::USING . ' ' . $this->action_parameter;
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_method_object::LANGUAGE:
- $action = c_database_string::LANGUAGE . ' ' . $this->name;
+ $value = c_database_string::LANGUAGE . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::PROCEDURAL:
- $action = c_database_string::PROCEDURAL . ' ' . c_database_string::LANGUAGE . ' ' . $this->name;
+ $value = c_database_string::PROCEDURAL . ' ' . c_database_string::LANGUAGE . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::SCHEMA:
- $action = c_database_string::SCHEMA . ' ' . $this->name;
+ $value = c_database_string::SCHEMA . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::SEQUENCE:
- $action = c_database_string::SEQUENCE . ' ' . $this->name;
+ $value = c_database_string::SEQUENCE . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::SERVER:
- $action = c_database_string::SERVER . ' ' . $this->name;
+ $value = c_database_string::SERVER . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::TABLE:
- $action = c_database_string::TABLE . ' ' . $this->name;
+ $value = c_database_string::TABLE . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::TEXT_SEARCH_CONFIGURATION:
- $action = c_database_string::TEXT_SEARCH_CONFIGURATION . ' ' . $this->name;
+ $value = c_database_string::TEXT_SEARCH_CONFIGURATION . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::TEXT_SEARCH_DICTIONARY:
- $action = c_database_string::TEXT_SEARCH_DICTIONARY . ' ' . $this->name;
+ $value = c_database_string::TEXT_SEARCH_DICTIONARY . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::TEXT_SEARCH_PARSER:
- $action = c_database_string::TEXT_SEARCH_PARSER . ' ' . $this->name;
+ $value = c_database_string::TEXT_SEARCH_PARSER . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::TEXT_SEARCH_TEMPLATE:
- $action = c_database_string::TEXT_SEARCH_TEMPLATE . ' ' . $this->name;
+ $value = c_database_string::TEXT_SEARCH_TEMPLATE . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::TRANSFORM_FOR:
- $action = c_database_string::TRANSFORM_FOR . ' ' . $this->name;
+ $value = c_database_string::TRANSFORM_FOR . ' ' . $this->p_do_build_name();
if (is_string($this->action_parameter)) {
- $action .= ' ' . c_database_string::LANGUAGE . ' ' . $this->action_parameter;
+ $value .= ' ' . c_database_string::LANGUAGE . ' ' . $this->action_parameter;
}
else {
- unset($action);
+ unset($value);
return new c_base_return_false();
}
break;
case e_database_method_object::TYPE:
- $action = c_database_string::TYPE . ' ' . $this->name;
+ $value = c_database_string::TYPE . ' ' . $this->p_do_build_name();
break;
case e_database_method_object::VIEW:
- $action = c_database_string::VIEW . ' ' . $this->name;
+ $value = c_database_string::VIEW . ' ' . $this->p_do_build_name();
break;
default:
- unset($action);
+ unset($value);
return new c_base_return_false();
}
$this->value = static::p_QUERY_COMMAND;
- $this->value .= ' ' . $action;
- unset($action);
+ $this->value .= ' ' . $value;
+ unset($value);
return new c_base_return_true();
}
public const CONVERSION = 'conversion';
public const CREATE = 'create';
public const DELETE = 'delete';
+ public const DEPENDS_ON_EXTENSION = 'depends on extension';
public const DESCEND = 'desc';
public const DISABLE_TRIGGER = 'disable trigger';
public const DOMAIN = 'domain';
public const HANDLER = 'handler';
public const IF_EXISTS = 'if exists';
public const IN = 'in';
+ public const INOUT = 'inout';
+ public const IN_SCHEMA = 'in schema';
public const INHERIT = 'inherit';
public const INSERT = 'insert';
public const IS_TEMPLATE = 'is_template';
public const OPERATOR_FAMILY = 'operator family';
public const OPTIONS = 'options';
public const ORDER_BY = 'order by';
+ public const OUT = 'out';
public const OWNER_TO = 'owner to';
public const PROCEDURAL = 'procedural';
public const PUBLIC = 'public';
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides enumeration classes for managing codes used for generating specific Postgesql Queries.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+/**
+ * Codes associated with database argument type mode.
+ */
+class e_database_argument_mode {
+ public const NONE = 0;
+ public const IN = 1;
+ public const INOUT = 2;
+ public const OUT = 3;
+ public const VARIADIC = 4;
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides enumeration classes for managing codes used for generating specific Postgesql Queries.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+/**
+ * Codes associated with postgresql function action information.
+ */
+class e_database_function_action {
+ public const NONE = 0;
+ public const CALLED_ON_NULL_INPUT = 1;
+ public const IMMUTABLE = 2;
+ public const LEAKPROOF = 3;
+ public const NOT_LEAKPROOF = 4;
+ public const PARALLEL_RESTRICTED = 5;
+ public const PARALLEL_SAFE = 6;
+ public const PARALLEL_UNSAFE = 7;
+ public const RESET = 8;
+ public const RESET_ALL = 9;
+ public const RETURNS_NULL_ON_NULL_INPUT = 10;
+ public const SECURITY_DEFINER = 11;
+ public const SECURITY_INVOKER = 12;
+ public const SET_EQUAL = 13;
+ public const SET_FROM = 14;
+ public const SET_TO = 15;
+ public const STABLE = 16;
+ public const STRICT = 17;
+ public const VOLATILE = 18;
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides enumeration classes for managing codes used for generating specific Postgesql Queries.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+/**
+ * Codes associated with database grant/revoke.
+ */
+class e_database_grant {
+ public const NONE = 0;
+ public const GRANT = 1;
+ public const REVOKE = 2;
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides enumeration classes for managing codes used for generating specific Postgesql Queries.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+/**
+ * Codes associated with postgresql role information.
+ */
+class e_database_role {
+ public const NONE = 0;
+ public const GROUP = 1;
+ public const NAME = 2;
+ public const PUBLIC = 3;
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with argument_type.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+require_once('common/database/enumerations/database_argument_mode.php');
+
+/**
+ * Provide the sql argument type functionality.
+ */
+trait t_database_argument_type {
+ protected $argument_type;
+
+ /**
+ * Set the argument type settings.
+ *
+ * @param string|null $argument_type
+ * The argument type to assign.
+ * Set to NULL to disable.
+ * Setting to NULL removes all existing values.
+ * @param string|null $argument_name
+ * When $argument_type is not NULL, this specifies the name of the argument.
+ * @param int|null $argument_mode
+ * When $argument_type is not NULL, this specifies the argument mode code of the argument.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_argument_type($argument_type, $argument_name = NULL, $argument_mode = NULL) {
+ if (is_null($argument_type)) {
+ $this->argument_type = NULL;
+ return new c_base_return_true();
+ }
+
+ if (!is_string($argument_type)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'argument_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_string($argument_name)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'argument_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ switch($argument_mode) {
+ case e_database_argument_mode::IN:
+ case e_database_argument_mode::INOUT:
+ case e_database_argument_mode::OUT:
+ case e_database_argument_mode::VARIADIC:
+ break;
+ default:
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'argument_mode', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_array($this->argument_type)) {
+ $this->argument_type = [];
+ }
+
+ $this->argument_type[] = [
+ 'type' => $argument_type,
+ 'name' => $argument_name,
+ 'mode' => $argument_mode,
+ ];
+
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned sql argument type at the specified index.
+ *
+ * @param int|null $index
+ * (optional) Get the argument type array at the specified index.
+ * When NULL, all argument type are returned.
+ *
+ * @return c_base_return_array|c_base_return_null
+ * A code representing the argument_type on success.
+ * NULL is returned if not set (argument_type tablespace is not to be used).
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_argument_type($index = NULL) {
+ if (is_null($this->argument_type)) {
+ return new c_base_return_null();
+ }
+
+ if (is_null($this->argument_type['type'])) {
+ return c_base_return_array::s_new($this->argument_type);
+ }
+ else if (isset($this->argument_type[$index]) && is_array($this->argument_type[$index])) {
+ return c_base_return_int::s_new($this->argument_type[$index]);
+ }
+ else {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'argument_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_null($error);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'argument_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_argument_type() {
+ if (is_null($this->argument_type)) {
+ return NULL;
+ }
+
+ $values = [];
+ foreach ($this->argument_type as $argument_type) {
+ $value = '';
+
+ switch($argument_type['mode']) {
+ case e_database_argument_mode::IN:
+ $value = c_database_string::IN;
+ break;
+ case e_database_argument_mode::INOUT:
+ $value = c_database_string::INOUT;
+ break;
+ case e_database_argument_mode::OUT:
+ $value = c_database_string::OUT;
+ break;
+ case e_database_argument_mode::VARIADIC:
+ $value = c_database_string::VARIADIC;
+ break;
+ }
+
+ $value .= ' ' . $argument_type['name'];
+ $value .= ' ' . $argument_type['type'];
+
+ $values[] = $value;
+ }
+ unset($argument_type);
+ unset($value);
+
+ return implode(', ', $values);
+ }
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+/**
+ * Provide the sql DEPENDS ON EXTENSION functionality.
+ */
+trait t_database_depends_on_extension {
+ protected $depends_on_extension;
+
+ /**
+ * Set the RENAME TO settings.
+ *
+ * @param string|null $depends_on_extension
+ * The name to rename to.
+ * Set to NULL to disable.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_depends_on_extension($depends_on_extension) {
+ if (!is_null($depends_on_extension) && !is_string($depends_on_extension)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'depends_on_extension', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->depends_on_extension = $depends_on_extension;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned schema name to set to.
+ *
+ * @return c_base_return_string|c_base_return_null
+ * An extension name on success.
+ * NULL is returned if not set (depends on extension is not to be used).
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_depends_on_extension() {
+ if (is_null($this->depends_on_extension)) {
+ return new c_base_return_null();
+ }
+
+ if (is_string($this->depends_on_extension)) {
+ return c_base_return_string::s_new($this->depends_on_extension);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'depends_on_extension', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_depends_on_extension() {
+ if (is_null($this->depends_on_extension)) {
+ return NULL;
+ }
+
+ return c_database_string::DEPENDS_ON_EXTENSION . ' ' . $this->depends_on_extension;
+ }
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with function_action.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+require_once('common/database/enumerations/database_argument_function_action.php');
+
+/**
+ * Provide the sql argument type functionality.
+ */
+trait t_database_function_action {
+ protected $function_action;
+
+ /**
+ * Set the argument type settings.
+ *
+ * @param int|null $function_action
+ * The function action code to assign.
+ * Set to NULL to disable.
+ * Setting to NULL removes all existing values.
+ * @param string|int|null $parameter_1
+ * Value for the first parameter if required by the $function_action_code.
+ * A string representing the configuration parameter for SET_TO, SET_EQUAL, SET_FROM, or RESET.
+ * An integer representing execution cost for COST.
+ * An integer representing result rows for ROWS.
+ * @param string|null $parameter_2
+ * Value for the second parameter if required by the $function_action_code.
+ * SET_TO and SET_FROM use this as value, but if left as NULL then DEFAULT is used.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_function_action($function_action, $parameter_1 = NULL, $parameter_2 = NULL) {
+ if (is_null($function_action)) {
+ $this->function_action = NULL;
+ return new c_base_return_true();
+ }
+
+ switch($function_action) {
+ case e_database_function_action::CALLED_ON_NULL_INPUT:
+ case e_database_function_action::COST:
+ case e_database_function_action::IMMUTABLE:
+ case e_database_function_action::LEAKPROOF:
+ case e_database_function_action::NOT_LEAKPROOF:
+ case e_database_function_action::PARALLEL_RESTRICTED:
+ case e_database_function_action::PARALLEL_SAFE:
+ case e_database_function_action::PARALLEL_UNSAFE:
+ case e_database_function_action::RESET:
+ case e_database_function_action::RESET_ALL:
+ case e_database_function_action::RETURNS_NULL_ON_NULL_INPUT:
+ case e_database_function_action::ROWS:
+ case e_database_function_action::SECURITY_DEFINER:
+ case e_database_function_action::SECURITY_INVOKER:
+ case e_database_function_action::SET_EQUAL:
+ case e_database_function_action::SET_FROM:
+ case e_database_function_action::SET_TO:
+ case e_database_function_action::STABLE:
+ case e_database_function_action::STRICT:
+ case e_database_function_action::VOLATILE:
+ break;
+ default:
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'function_action', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $action = [
+ 'type' => $function_action,
+ 'parameter_1' => NULL,
+ 'parameter_2' => NULL,
+ ];
+
+ if ($function_action === e_database_function_action::COST || $function_action === e_database_function_action::ROWS) {
+ if (!is_int($parameter_1)) {
+ unset($action);
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'parameter_1', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $action['parameter_1'] = $parameter_1;
+ }
+ else if ($function_action === e_database_function_action::SET_TO || $function_action === e_database_function_action::SET_EQUAL) {
+ if (!is_string($parameter_1)) {
+ unset($action);
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'parameter_1', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_null($parameter_2) && !is_string($parameter_2)) {
+ unset($action);
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'parameter_2', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $action['parameter_1'] = $parameter_1;
+ $action['parameter_2'] = $parameter_2;
+ }
+ else if ($function_action === e_database_function_action::SET_FROM || $function_action === e_database_function_action::RESET) {
+ if (!is_string($parameter_1)) {
+ unset($action);
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'parameter_1', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $action['parameter_1'] = $parameter_1;
+ }
+
+ $this->function_action = $action;
+ unset($action);
+
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned sql functionn action.
+ *
+ * @return c_base_return_array|c_base_return_null
+ * An array representing the function action on success.
+ * NULL is returned if not set (function action tablespace is not to be used).
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_function_action($index = NULL) {
+ if (is_null($this->function_action)) {
+ return new c_base_return_null();
+ }
+
+ if (is_array($this->function_action)) {
+ return c_base_return_array::s_new($this->function_action);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'function_action', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_function_action() {
+ if (is_null($this->function_action)) {
+ return NULL;
+ }
+
+ // @todo
+ }
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+require_once('common/database/enumerations/database_grant.php');
+
+/**
+ * Provide the sql GRANT functionality.
+ * @fixme: doesn't group by support multiple arguments?
+ */
+trait t_database_grant {
+ protected $grant;
+
+ /**
+ * Set the GRANT settings.
+ *
+ * @param int|null $grant
+ * The grant/revoke code to assign.
+ * Set to NULL to disable.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_grant($grant) {
+ if (is_null($grant)) {
+ $this->grant = NULL;
+ return new c_base_return_true();
+ }
+
+ if ($grant === e_database_grant::GRANT || $grant === e_database_grant::REVOKE) {
+ $this->grant = $grant;
+ return new c_base_return_true();
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'grant', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ /**
+ * Get the currently assigned grant code.
+ *
+ * @return c_base_return_int|c_base_return_null
+ * A grant code on success.
+ * NULL is returned if not set (grant is not to be used).
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_grant() {
+ if (is_null($this->grant)) {
+ return new c_base_return_null();
+ }
+
+ if (is_int($this->grant)) {
+ return c_base_return_int::s_new($this->grant);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'grant', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_grant() {
+ $value = NULL;
+ if ($this->grant === e_database_grant::GRANT) {
+ $value = c_database_string::GRANT;
+ }
+ else if ($this->grant === e_database_grant::REVOKE) {
+ $value = c_database_string::REVOKE;
+ }
+
+ return $value;
+ }
+}
return NULL;
}
- return c_database_string::IN . ' ' . c_database_string::SCHEMA . ' ' . implode(', ', $this->in_schema);
+ return c_database_string::IN_SCHEMA . ' ' . implode(', ', $this->in_schema);
}
}
$error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
return c_base_return_error::s_null($error);
}
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_name() {
+ if (is_null($this->name)) {
+ return NULL;
+ }
+
+ return $this->name;
+ }
}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with on.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+require_once('common/database/enumerations/database_on.php');
+
+require_once('common/database/enumerations/database_on.php');
+
+/**
+ * Provide the sql ON functionality.
+ */
+trait t_database_on {
+ protected $on;
+
+ /**
+ * Assigns the SQL ON operation.
+ *
+ * @param int|null $on
+ * Whether or not to use the ON operation in the query.
+ * 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_on($on) {
+ if (is_null($on)) {
+ $this->on = NULL;
+ return new c_base_return_true();
+ }
+
+ switch ($on) {
+ case e_database_on::TABLES_TO:
+ case e_database_on::SEQUENCES:
+ case e_database_on::FUNCTIONS:
+ case e_database_on::TYPES:
+ case e_database_on::SCHEMAS:
+ $this->on = $on;
+ return new c_base_return_true();
+ default:
+ break;
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'on', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ /**
+ * Get the ON operation status.
+ *
+ * @return c_base_return_int|c_base_return_null
+ * Integer representing the on operation is returned on success.
+ * NULL is returned if undefined.
+ * FALSE with error bit set is returned on error.
+ */
+ protected function get_on() {
+ if (is_null($this->on)) {
+ return new c_base_return_null();
+ }
+
+ return c_base_return_int::s_new($this->on);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_on() {
+ if (is_null($this->on)) {
+ return NULL;
+ }
+
+ $value = NULL;
+ switch($this->on) {
+ case e_database_on::TABLES_TO:
+ $value .= c_database_string::ON_TABLES_TO;
+ break;
+ case e_database_on::SEQUENCES:
+ $value .= c_database_string::ON_SEQUENCES;
+ break;
+ case e_database_on::FUNCTIONS:
+ $value .= c_database_string::ON_FUNCTIONS;
+ break;
+ case e_database_on::TYPES:
+ $value .= c_database_string::ON_TYPES;
+ break;
+ case e_database_on::SCHEMAS:
+ $value .= c_database_string::ON_SCHEMAS;
+ break;
+ }
+
+ return $value;
+ }
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+/**
+ * Provide the sql PRIVILEGE functionality.
+ */
+trait t_database_privilege {
+ protected $privilege;
+
+ /**
+ * Assigns the SQL privileges.
+ *
+ * @param int|null $privilege
+ * Set a privilege code.
+ * Set to NULL to disable.
+ * When NULL, this will remove all values.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
+ */
+ public function set_privilege($privilege) {
+ if (is_null($privilege)) {
+ $this->privileges = NULL;
+ return new c_base_return_true();
+ }
+
+ if (is_int($privilege)) {
+ // no reason to add any privilege once ALL is present.
+ if ($this->privilege === e_database_privilege::ALL) {
+ return new c_base_return_true();
+ }
+
+ if ($privilege === e_database_privilege::ALL) {
+ $this->privilege = e_database_privilege::ALL;
+ }
+ else {
+ if (!is_array($this->privilege)) {
+ $this->privilege = [];
+ }
+
+ $this->privilege[] = $privilege;
+ }
+
+ return new c_base_return_true();
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'privilege', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ /**
+ * Get the privileges.
+ *
+ * @param int|null $index
+ * (optional) Get the privilege at the specified index.
+ * When NULL, all privileges are returned.
+ *
+ * @return c_base_return_int|c_base_return_array|c_base_return_null
+ * An array of privileges or NULL if not defined.
+ * A single privilege is returned if $index is an integer.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_privilege($index = NULL) {
+ if (is_null($this->privilege)) {
+ return new c_base_return_null();
+ }
+
+ if (is_null($index)) {
+ if ($this->privilege === e_database_privilege::ALL) {
+ return c_base_return_array::s_new([$this->privilege]);
+ }
+ else if (is_array($this->privilege)) {
+ return c_base_return_array::s_new($this->privilege);
+ }
+ }
+ else {
+ if (is_int($index) && array_key_exists($index, $this->privilege) && is_int($this->privilege[$index])) {
+ return clone($this->privilege[$index]);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'privilege[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'privilege', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_privilege() {
+ if (is_null($this->privilege)) {
+ return NULL;
+ }
+
+ if ($this->privilege === e_database_privilege::ALL) {
+ return c_database_string::ALL;
+ }
+
+ $privileges = [];
+ foreach ($this->privilege as $privilege) {
+ switch ($privilege) {
+ case e_database_privilege::SELECT:
+ $privileges[] = c_database_string::SELECT;
+ break;
+ case e_database_privilege::INSERT:
+ $privileges[] = c_database_string::INSERT;
+ break;
+ case e_database_privilege::UPDATE:
+ $privileges[] = c_database_string::UPDATE;
+ break;
+ case e_database_privilege::DELETE:
+ $privileges[] = c_database_string::DELETE;
+ break;
+ case e_database_privilege::TRUNCATE:
+ $privileges[] = c_database_string::TRUNCATE;
+ break;
+ case e_database_privilege::REFERENCES:
+ $privileges[] = c_database_string::REFERENCES;
+ break;
+ case e_database_privilege::TRIGGER:
+ $privileges[] = c_database_string::TRIGGER;
+ break;
+ case e_database_privilege::USAGE:
+ $privileges[] = c_database_string::USAGE;
+ break;
+ case e_database_privilege::EXECUTE:
+ $privileges[] = c_database_string::EXECUTE;
+ break;
+ case e_database_privilege::CREATE:
+ $privileges[] = c_database_string::CREATE;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return implode(', ', $privileges);
+ }
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+/**
+ * Provide the sql RESTRICT functionality.
+ */
+trait t_database_restrict {
+ protected $restrict;
+
+ /**
+ * Set the RESTRICT value.
+ *
+ * @param bool|null $restrict
+ * Set to TRUE for RESTRICT.
+ * Set to FALSE for not using RESTICT.
+ * Set to NULL to disable.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_restrict($restrict) {
+ if (is_null($restrict)) {
+ $this->restrict = NULL;
+ return new c_base_return_true();
+ }
+
+ if (!is_bool($restrict)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'restrict', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->restrict = $restrict;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned restrict status.
+ *
+ * @return c_base_return_bool|c_base_return_null
+ * TRUE for RESTRICT or FALSE for not using RESTRICT on success.
+ * NULL is returned if not set.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_restrict() {
+ if (is_null($this->restrict)) {
+ return new c_base_return_null();
+ }
+
+ if (is_bool($this->restrict)) {
+ return c_base_return_bool::s_new($this->restrict);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'restrict', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_restrict() {
+ if (is_null($this->restrict)) {
+ return NULL;
+ }
+
+ return $this->restrict ? c_database_string::RESTRICT : NULL;
+ }
+}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+require_once('common/database/classes/database_string.php');
+
+require_once('common/database/enumerations/database_role.php');
+
+/**
+ * Provide the sql TO ROLES functionality.
+ */
+trait t_database_to_role {
+ protected $to_role;
+
+ /**
+ * Set the in schema, to roles.
+ *
+ * @param int|null $role_type
+ * The role type to use.
+ * Set to NULL to disable.
+ * When NULL, this will remove all values.
+ * @param string|null $role_name
+ * The role name to use.
+ * This may be NULL if not used by the $role_type.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
+ */
+ public function set_to_role($role_type, $role_name = NULL) {
+ if (is_null($role_type)) {
+ $this->to_role = NULL;
+ return new c_base_return_true();
+ }
+
+ if (is_int($role_type)) {
+ if ($role_type === e_database_role::NAME && !is_string($role_name) || !is_null($role_name) && !is_string($role_name)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'role_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+ else if ($role_type !== e_database_role::GROUP && $role_type !== e_database_role::PUBLIC) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'role_type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_array($this->to_role)) {
+ $this->to_role = [];
+ }
+
+ $this->to_role[] = [
+ 'type' => $role_type,
+ 'name' => $role_name,
+ ];
+ return new c_base_return_true();
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'to_role', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ /**
+ * Get the in schema, to roles.
+ *
+ * @param int|null $index
+ * (optional) Get the schema name at the specified index.
+ * When NULL, all to roles are returned.
+ *
+ * @return c_base_return_array|c_base_return_null
+ * An array of to role arrays or NULL if not defined.
+ * A single to role array is returned if $index is an integer.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_to_role($index = NULL) {
+ if (is_null($this->to_role)) {
+ return new c_base_return_null();
+ }
+
+ if (is_null($index)) {
+ if (is_array($this->to_role)) {
+ return c_base_return_array::s_new($this->to_role);
+ }
+ }
+ else {
+ if (is_int($index) && array_key_exists($index, $this->to_role) && is_array($this->to_role[$index])) {
+ return c_base_return_array::s_new($this->to_role[$index]);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'to_role[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'to_role', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ /**
+ * Perform the common build process for this trait.
+ *
+ * As an internal trait method, the caller is expected to perform any appropriate validation.
+ *
+ * @return string|null
+ * A string is returned on success.
+ * NULL is returned if there is nothing to process or there is an error.
+ */
+ protected function p_do_build_to_role() {
+ if (is_null($this->to_role)) {
+ return NULL;
+ }
+
+ $values = [];
+ foreach ($this->to_role as $to_role) {
+ if ($this->to_role['type'] === e_database_role::PUBLIC) {
+ $values[] = c_database_string::PUBLIC;
+ }
+ else if ($this->to_role['type'] === e_database_role::GROUP) {
+ $values[] = c_database_string::GROUP;
+ }
+ else if ($this->to_role['type'] === e_database_role::NAME) {
+ $values[] = $this->to_role['name'];
+ }
+ }
+
+ return c_database_string::TO . ' ' . implode(', ', $values);
+ }
+}