$value = NULL;
if (is_string($this->rename_to)) {
- $action = $aggregate_signatures . ' ' . $this->p_do_build_rename_to();
+ $value = $aggregate_signatures . ' ' . $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $action = $aggregate_signatures . ' ' . $this->p_do_build_owner_to();
+ $value = $aggregate_signatures . ' ' . $this->p_do_build_owner_to();
}
else if (is_string($this->set_schema)) {
- $action = $aggregate_signatures . ' ' . $this->p_do_build_set_schema();
+ $value = $aggregate_signatures . ' ' . $this->p_do_build_set_schema();
}
else {
unset($aggregate_signatures);
- unset($action);
+ unset($value);
return new c_base_return_false();
}
unset($aggregate_signatures);
$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 = NULL;
if (is_bool($this->refresh_version)) {
if ($this->refresh_version) {
- $action = c_database_string::REFRESH_VERSION;
+ $value = c_database_string::REFRESH_VERSION;
}
}
else if (is_string($this->rename_to)) {
- $action = $this->p_do_build_rename_to();
+ $value = $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $action = $this->p_do_build_owner_to();
+ $value = $this->p_do_build_owner_to();
}
else 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();
}
$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 = NULL;
if (is_string($this->rename_to)) {
- $action = $this->p_do_build_rename_to();
+ $value = $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $action = $this->p_do_build_owner_to();
+ $value = $this->p_do_build_owner_to();
}
else 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();
}
$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 = NULL;
if ($this->option instanceof c_database_argument_database_option) {
$this->option->do_build_argument();
- $action = $this->option->get_value_exact();
+ $value = $this->option->get_value_exact();
}
else if (is_string($this->rename_to)) {
- $action = $this->p_do_build_rename_to();
+ $value = $this->p_do_build_rename_to();
}
else if (is_string($this->owner_to)) {
- $action = $this->p_do_build_owner_to();
+ $value = $this->p_do_build_owner_to();
}
else if (is_string($this->set_tablespace)) {
- $action = $this->p_do_build_set_tablespace();
+ $value = $this->p_do_build_set_tablespace();
}
else if (is_array($this->set)) {
- $action = $this->p_do_build_set();
+ $value = $this->p_do_build_set();
}
else if (is_array($this->reset)) {
- $action = $this->p_do_build_reset();
+ $value = $this->p_do_build_reset();
}
else {
- 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();
}
require_once('common/database/enumerations/database_cascade.php');
-require_once('common/database/traits/database_in_schema.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_option_for.php');
+require_once('common/database/traits/database_in_schema.php');
+require_once('common/database/traits/database_with_grant_option.php');
/**
* The class for building and returning a Postgresql ALTER DEFAULT PRIVILEGES query string.
* @see: https://www.postgresql.org/docs/current/static/sql-alterdefaultpriveleges.html
*/
class c_database_alter_default_priveleges extends c_database_query {
- use t_database_in_schema;
use t_database_action;
+ use t_database_cascade;
+ use t_database_for_role;
+ use t_database_grant_option_for;
+ use t_database_in_schema;
+ use t_database_with_grant_option;
protected const p_QUERY_COMMAND = 'alter default privileges';
protected $abbreviated;
- protected $cascade;
- protected $option_grant;
protected $on;
protected $privileges;
protected $role_names;
public function __construct() {
parent::__construct();
- $this->action = NULL;
- $this->in_schema = NULL;
-
- $this->abbreviated = NULL;
- $this->cascade = NULL;
- $this->option_grant = NULL;
- $this->on = NULL;
- $this->privileges = NULL;
- $this->role_names = NULL;
+ $this->action = NULL;
+ $this->cascade = NULL;
+ $this->for_role = NULL;
+ $this->grant_option_for = NULL;
+ $this->in_schema = NULL;
+ $this->with_grant_option = NULL;
+
+ $this->abbreviated = NULL;
+ $this->on = NULL;
+ $this->privileges = NULL;
+ $this->role_names = NULL;
}
/**
parent::__destruct();
unset($this->action);
+ unset($this->cascade);
+ unset($this->for_role);
+ unset($this->grant_option_for);
unset($this->in_schema);
+ unset($this->with_grant_option);
unset($this->abbreviated);
- unset($this->cascade);
- unset($this->option_grant);
+ unset($this->on);
unset($this->privileges);
unset($this->role_names);
}
}
/**
- * Assigns the SQL CASCADE/RESTRICT option.
- *
- * @param int|null $cascade
- * Whether or not to use CASCADE/RESTRICT 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_cascade($cascade) {
- if (is_null($cascade)) {
- $this->cascade = NULL;
- return new c_base_return_true();
- }
-
- switch ($cascade) {
- case e_database_cascade::CASCADE:
- case e_database_cascade::RESTRICT:
- $this->cascade = $cascade;
- return new c_base_return_true();
- default:
- break;
- }
-
- $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);
- }
-
- /**
- * Set the FOR ROLE role targets.
- *
- * @param string|bool|null $target
- * The for role target to use.
- * Set to TRUE to use (only) the current role, $append is considered FALSE.
- * 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_for_role_targets($target) {
- if (is_null($target)) {
- $this->target = NULL;
- return new c_base_return_true();
- }
-
- if (is_string($target)) {
- if (!is_array($this->for_role_targets)) {
- $this->for_role_targets = [];
- }
-
- $this->for_role_targets[] = $target;
-
- return new c_base_return_true();
- }
- else if ($target === TRUE) {
- $this->for_role_targets = TRUE;
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'target', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- /**
- * Enables/Disables the SQL WITH GRANT OPTION.
- *
- * @param bool|null $option_grant
- * Set to TRUE to append the with grant option or grant option for.
- * Set to FALSE to not append the with grant option or the grant option for.
- * 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_option_grant($option_grant) {
- if (!is_null($option_grant) && !is_bool($option_grant)) {
- $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'option_grant', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->option_grant = $option_grant;
- return new c_base_return_true();
- }
-
- /**
* Assigns the SQL ON operation.
*
* @param int|null $on
}
/**
- * Get assigned option.
- *
- * @param int|null $index
- * (optional) Get the argument signature at the specified index.
- * When NULL, all argument signatures are returned.
- * This is always considered NULL when for role targets is set to the current role.
- *
- * @return c_base_return_array|c_base_return_string|c_base_return_bool|c_base_return_null
- * An array of for role targets or NULL if not defined.
- * TRUE is returned if the current role is to be used as the for role target.
- * A string of a single for role target is returned if the $index is not NULL.
- * NULL with the error bit set is returned on error.
- */
- public function get_for_role_targets($index = NULL) {
- if (is_null($this->for_role_targets)) {
- return new c_base_return_null();
- }
-
- if ($this->for_role_targets === TRUE) {
- return c_base_return_bool::s_new(TRUE);
- }
-
- if (is_null($index)) {
- if (is_array($this->for_role_targets)) {
- return c_base_return_array::s_new($this->for_role_targets);
- }
- }
- else {
- if (is_int($index) && array_key_exists($index, $this->for_role_targets) && is_string($this->for_role_targets[$index])) {
- return c_base_return_string::s_new($this->for_role_targets[$index]);
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'for_role_targets[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}' => 'for_role_targets', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
- return c_base_return_error::s_null($error);
- }
-
- /**
- * Get the WITH GRANT OPTION status.
- *
- * @return c_base_return_bool|c_base_return_null
- * TRUE is returned if the with grant option or grant option for is enabled.
- * FALSE is returned if the with grant option or grant option for is disabled.
- * NULL is returned if undefined.
- * FALSE with error bit set is returned on error.
- */
- protected function get_option_grant() {
- if (is_null($this->option_grant)) {
- return new c_base_return_null();
- }
-
- return c_base_return_bool::s_new($this->option_grant);
- }
-
- /**
- * Get the CASCADE/RESTRICT 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_cascade() {
- if (is_null($this->cascade)) {
- return new c_base_return_null();
- }
-
- return c_base_return_int::s_new($this->cascade);
- }
-
- /**
* Get the ON operation status.
*
* @return c_base_return_int|c_base_return_null
return new c_base_return_false();
}
- // [ FOR ROLE target_role [, ... ] ]
- $action = NULL;
- if (is_array($this->for_role_targets) && !empty($this->for_role_targets)) {
- $action = c_database_string::FOR . ' ' . c_database_string::ROLE;
- $action .= ' ' . implode(', ', $this->for_role_targets);
+ $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)) {
- $action .= is_null($action) ? '' : ' ';
- $action .= $this->p_do_build_in_schema();
+ $value .= is_null($value) ? '' : ' ';
+ $value .= $this->p_do_build_in_schema();
}
if ($this->action === e_database_action::ACTION_GRANT) {
- $action .= is_null($action) ? '' : ' ';
- $action .= c_database_string::GRANT;
+ $value .= is_null($value) ? '' : ' ';
+ $value .= c_database_string::GRANT;
}
else if ($this->action === e_database_action::ACTION_REVOKE) {
- $action .= is_null($action) ? '' : ' ';
- $action .= c_database_string::REVOKE;
+ $value .= is_null($value) ? '' : ' ';
+ $value .= c_database_string::REVOKE;
- if ($this->option_grant) {
- $action .= ' ' . c_database_string::GRANT_OPTION_FOR;
+ if ($this->grant_option_for) {
+ $value .= ' ' . $this->p_do_build_grant_option_for();
}
}
}
}
- $action .= is_null($action) ? '' : ' ';
- $action .= ltrim($privileges, ', ');
+ $value .= is_null($value) ? '' : ' ';
+ $value .= ltrim($privileges, ', ');
unset($privileges);
// ON ...
switch($this->on) {
case e_database_on::TABLES_TO:
- $action .= ' ' . c_database_string::ON_TABLES_TO;
+ $value .= ' ' . c_database_string::ON_TABLES_TO;
break;
case e_database_on::SEQUENCES:
- $action .= ' ' . c_database_string::ON_SEQUENCES;
+ $value .= ' ' . c_database_string::ON_SEQUENCES;
break;
case e_database_on::FUNCTIONS:
- $action .= ' ' . c_database_string::ON_FUNCTIONS;
+ $value .= ' ' . c_database_string::ON_FUNCTIONS;
break;
case e_database_on::TYPES:
- $action .= ' ' . c_database_string::ON_TYPES;
+ $value .= ' ' . c_database_string::ON_TYPES;
break;
case e_database_on::SCHEMAS:
- $action .= ' ' . c_database_string::ON_SCHEMAS;
+ $value .= ' ' . c_database_string::ON_SCHEMAS;
break;
}
// [ TO | FROM ] ... role names ...
if ($this->action === e_database_action::GRANT) {
- $action .= ' ' . c_database_string::TO;
+ $value .= ' ' . c_database_string::TO;
}
else if ($this->action === e_database_action::REVOKE) {
- $action .= ' ' . c_database_string::FROM;
+ $value .= ' ' . c_database_string::FROM;
}
foreach ($this->role_names as $role_name) {
}
$role_name->do_build_argument();
- $action .= ' ' . $role_name->get_value_exact();
+ $value .= ' ' . $role_name->get_value_exact();
}
unset($role_name);
if ($this->action === e_database_action::GRANT) {
- // [ WITH GRANT OPTION ]
- if ($this->option_grant) {
- $action .= ' ' . c_database_string::WITH_GRANT_OPTION;
+ if ($this->with_grant_option) {
+ $value .= ' ' . $this->p_do_build_with_grant_option();
}
}
else if ($this->action === e_database_action::REVOKE) {
- // [ CASCADE | RESTRICT ]
- if ($this->cascade === e_database_option::CASCADE) {
- $value .= ' ' . c_database_string::CASCADE;
- }
- else if ($this->cascade === e_database_option::RESTRICT) {
- $value .= ' ' . c_database_string::RESTRICT;
+ if (is_int($this->cascade)) {
+ $value .= ' ' . $this->p_do_build_cascade();
}
}
$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();
}
<?php
/**
* @file
- * Provides a class for specific Postgesql query: ALTER COALATION.
+ * Provides a class for specific Postgesql query: ALTER EXTENSION.
*/
namespace n_koopa;
<?php
/**
* @file
- * Provides a class for specific Postgesql query: ALTER COALATION.
+ * Provides a class for specific Postgesql query: ALTER FOREIGN DATA WRAPPER.
*/
namespace n_koopa;
public const FOREIGN_DATA_WRAPPER = 'foreign data wrapper';
public const FOREIGN_TABLE = 'foreign table';
public const FOR = 'for';
+ public const FOR_ROLE = 'for role';
public const FROM_CURRENT = 'from current';
public const FUNCTION = 'function';
public const GRANT = 'grant';
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with cascade.
+ *
+ * @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/enumerations/database_cascade.php');
+
+/**
+ * Provide the sql HANDLER/NO HANDLER functionality.
+ */
+trait t_database_cascade {
+ protected $cascade;
+
+ /**
+ * Set the HANDLER settings.
+ *
+ * @param int|null $cascade
+ * The intege representing cascade/no-cascade.
+ * 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_cascade($cascade) {
+ if (is_null($cascade)) {
+ $this->cascade = NULL;
+ return new c_base_return_true();
+ }
+
+ if ($cascade === e_database_cascade::CASCADE || $cascade === e_database_cascade::RESTRICT) {
+ $this->cascade = $cascade;
+ return new c_base_return_true();
+ }
+
+ $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);
+ }
+
+ /**
+ * Get the currently assigned cascade.
+ *
+ * @return c_base_return_int|c_base_return_null
+ * An integer containing the cascade setting on success.
+ * NULL is returned if not set.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_cascade() {
+ if (is_null($this->cascade)) {
+ return new c_base_return_null();
+ }
+
+ if (is_array($this->cascade)) {
+ return c_base_return_array::s_new($this->cascade);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'cascade', ':{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_cascade() {
+ if (is_null($this->cascade)) {
+ return NULL;
+ }
+
+ $value = NULL;
+ if ($this->cascade['type'] === e_database_cascade::CASCADE) {
+ if (isset($this->cascade['name'])) {
+ $value = c_database_string::CASCADE;
+ }
+ }
+ else if ($this->cascade['type'] === e_database_cascade::RESTRICT) {
+ $value .= c_database_string::RESTRICT;
+ }
+
+ 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 FOR ROLE functionality.
+ */
+trait t_database_for_role {
+ protected $for_role;
+
+ /**
+ * Set the FOR ROLE value.
+ *
+ * @param string|null $for_role
+ * Append a role name to the list.
+ * Set to NULL to disable.
+ * When NULL, this resets the for_role to an empty array.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with the error bit set is returned on error.
+ */
+ public function set_for_role($for_role) {
+ if (is_null($for_role)) {
+ $this->for_role = NULL;
+ return new c_base_return_true();
+ }
+
+ if (!is_string($for_role)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'for_role', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_array($this->for_role)) {
+ $this->for_role = [];
+ }
+
+ $this->for_role[] = $for_role;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned for role value.
+ *
+ * @param int|null $index
+ * (optional) Get the for role at the specified index.
+ * When NULL, all for role values are returned.
+ *
+ * @return c_base_return_string|c_base_return_array|c_base_return_null
+ * An array of for roles or NULL if not defined.
+ * A single for role is returned if $index is an integer.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_for_role($index = NULL) {
+ if (is_null($this->for_role)) {
+ return new c_base_return_null();
+ }
+
+ if (is_null($index)) {
+ if (is_array($this->for_role)) {
+ return c_base_return_array::s_new($this->for_role);
+ }
+ }
+ else {
+ if (is_int($index) && array_key_exists($index, $this->for_role) && is_string($this->for_role[$index])) {
+ return c_base_return_string::s_new($this->for_role[$index]);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'for_role[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ return c_base_return_error::s_null($error);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'for_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_for_role() {
+ if (is_null($this->for_role)) {
+ return NULL;
+ }
+
+ return c_database_string::FOR_ROLE . ' ' . implode(', ', $this->for_role);
+ }
+}
--- /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 GANT OPTION FOR functionality.
+ */
+trait t_database_grant_option_for {
+ protected $grant_option_for;
+
+ /**
+ * Set the GANT OPTION FOR value.
+ *
+ * @param bool|null $grant_option_for
+ * Set to TRUE for GANT OPTION FOR.
+ * Set to FALSE for nothing.
+ * 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_option_for($grant_option_for) {
+ if (is_null($grant_option_for)) {
+ $this->grant_option_for = NULL;
+ return new c_base_return_true();
+ }
+
+ if (!is_bool($grant_option_for)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'grant_option_for', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->grant_option_for = $grant_option_for;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned grant option for value.
+ *
+ * @return c_base_return_bool|c_base_return_null
+ * TRUE for GANT OPTION FOR on success.
+ * NULL is returned if not set.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_grant_option_for() {
+ if (is_null($this->grant_option_for)) {
+ return new c_base_return_null();
+ }
+
+ if (is_bool($this->grant_option_for)) {
+ return c_base_return_bool::s_new($this->grant_option_for);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'grant_option_for', ':{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_option_for() {
+ if (is_null($this->grant_option_for)) {
+ return NULL;
+ }
+
+ return $this->grant_option_for ? c_database_string::GRANT_OPTION_FOR : NULL;
+ }
+}
return c_base_return_array::s_new($this->handler);
}
- $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'handler', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
return c_base_return_error::s_null($error);
}
}
$value = NULL;
- if ($this->handler['type'] == e_database_handler::HANDLER) {
+ if ($this->handler['type'] === e_database_handler::HANDLER) {
if (isset($this->handler['name'])) {
$value = c_database_string::HANDLER . ' ' . $this->handler['name'];
}
}
- else if ($this->handler['type'] == e_database_handler::NO_HANDLER) {
+ else if ($this->handler['type'] === e_database_handler::NO_HANDLER) {
$value .= c_database_string::NO_HANDLER;
}
* Set the SET WITH OIDS value.
*
* @param bool|null $set_with_oids
- * Set to TRUE for SET WITH OIDS an FALSE for SET WITHOUT OIDS.
+ * Set to TRUE for SET WITH OIDS.
+ * Set to FALSE for SET WITHOUT OIDS.
* Set to NULL to disable.
*
* @return c_base_return_status
--- /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 WITH GANT OPTION functionality.
+ */
+trait t_database_with_grant_option {
+ protected $with_grant_option;
+
+ /**
+ * Set the WITH GRANT OPTION value.
+ *
+ * @param bool|null $with_grant_option
+ * Set to TRUE for WITH GANT OPTION.
+ * Set to FALSE for nothing.
+ * 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_with_grant_option($with_grant_option) {
+ if (is_null($with_grant_option)) {
+ $this->with_grant_option = NULL;
+ return new c_base_return_true();
+ }
+
+ if (!is_bool($with_grant_option)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'with_grant_option', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->with_grant_option = $with_grant_option;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Get the currently assigned with grant option value.
+ *
+ * @return c_base_return_bool|c_base_return_null
+ * TRUE for WITH GANT OPTION on success.
+ * NULL is returned if not set.
+ * NULL with the error bit set is returned on error.
+ */
+ public function get_with_grant_option() {
+ if (is_null($this->with_grant_option)) {
+ return new c_base_return_null();
+ }
+
+ if (is_bool($this->with_grant_option)) {
+ return c_base_return_bool::s_new($this->with_grant_option);
+ }
+
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_grant_option', ':{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_with_grant_option() {
+ if (is_null($this->with_grant_option)) {
+ return NULL;
+ }
+
+ return $this->with_grant_option ? c_database_string::WITH_GRANT_OPTION : NULL;
+ }
+}