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_option.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/traits/database_in_schema.php');
require_once('common/database/traits/database_action.php');
-require_once('common/database/traits/database_option.php');
/**
* The class for building and returning a Postgresql ALTER DEFAULT PRIVILEGES query string.
class c_database_alter_default_priveleges extends c_database_query {
use t_database_in_schema;
use t_database_action;
- use t_database_option;
protected const pr_QUERY_COMMAND = 'alter default privileges';
protected $abbreviated;
+ protected $cascade;
protected $option_grant;
protected $on;
protected $privileges;
public function __construct() {
parent::__construct();
- $this->in_schema = NULL;
$this->action = NULL;
- $this->option = NULL;
+ $this->in_schema = NULL;
$this->abbreviated = NULL;
+ $this->cascade = NULL;
$this->option_grant = NULL;
$this->on = NULL;
$this->privileges = NULL;
public function __destruct() {
parent::__destruct();
- unset($this->in_schema);
unset($this->action);
+ unset($this->in_schema);
unset($this->abbreviated);
+ unset($this->cascade);
unset($this->option_grant);
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
}
/**
+ * 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
if (is_null($index)) {
if (is_array($this->privileges)) {
- return c_base_return_array::s_new($this->aggregate_signatures);
+ return c_base_return_array::s_new($this->privileges);
}
}
else {
- if (is_int($index) && array_key_exists($index, $this->aggregate_signatures) && $this->aggregate_signatures[$index] instanceof c_database_argument_aggregate_signature) {
+ if (is_int($index) && array_key_exists($index, $this->privileges) && $this->privileges[$index] instanceof c_database_argument_aggregate_signature) {
return clone($this->privileges[$index]);
}
}
else if ($this->action === e_database_action::REVOKE) {
// [ CASCADE | RESTRICT ]
- $option = $this->p_do_build_option();
- if (is_string($option)) {
- $action .= ' ' . $option;
+ 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;
}
- unset($option);
}
$this->value = static::pr_QUERY_COMMAND;
require_once('common/base/classes/base_return.php');
require_once('common/database/enumerations/database_action.php');
-require_once('common/database/enumerations/database_option.php');
+require_once('common/database/enumerations/database_cascade.php');
require_once('common/database/classes/database_query.php');
require_once('common/database/traits/database_rename_to.php');
require_once('common/database/traits/database_set_schema.php');
require_once('common/database/traits/database_action.php');
-require_once('common/database/traits/database_option.php');
/**
* The class for building and returning a Postgresql ALTER DOMAIN query string.
use t_database_set_schema;
use t_database_action;
use t_database_action_property;
- use t_database_option;
protected const pr_QUERY_COMMAND = 'alter domain';
protected $expression;
- protected $contraint;
+ protected $constraint;
/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
-
+;
+ $this->action = NULL;
+ $this->action_property = NULL;
$this->name = NULL;
$this->owner_to = NULL;
$this->rename_to = NULL;
- $this->set_schema = NULL;
- $this->action = NULL;
- $this->action_property = NULL;
- $this->option = NULL;
+ $this->set_schema = NULL
- $this->expression = NULL;
- $this->contraint = NULL;
- $this->contraint_new = NULL;
+ $this->expression = NULL;
+ $this->constraint = NULL;
}
/**
* Class destructor.
*/
public function __destruct() {
+ unset($this->action);
+ unset($this->action_property);
unset($this->name);
unset($this->owner_to);
unset($this->rename_to);
unset($this->set_schema);
- unset($this->action);
- unset($this->action_property);
- unset($this->option);
unset($this->expression);
- unset($this->contraint);
- unset($this->contraint_new);
+ unset($this->constraint);
parent::__destruct();
}
* @param string|null $constraint
* The constraint string to use.
* Set to NULL to disable.
- * @param string|null $constraint_new
- * When the constraint
+ * @param string|null $new_name
+ * The new constraint name, when applicable.
+ * Set to NULL to disable.
+ * @param int|null $cascade
+ * Set eithe CASCADE/RESTRICT, when applicable.
* 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_constraint($constraint, $constraint_new = NULL) {
+ public function set_constraint($constraint, $new_name = NULL, $cascade = NULL) {
if (is_null($constraint)) {
- if (is_null($constraint_new)) {
- $this->constraint = NULL;
- $this->constraint_new = NULL;
- return new c_base_return_true();
- }
-
- if (is_string($constraint_new)) {
- $this->constraint = NULL;
- $this->constraint_new = $constraint_new;
- return new c_base_return_true();
- }
+ $this->constraint = NULL;
+ return new c_base_return_true();
}
- else if (is_string($constraint)) {
- if (is_null($constraint_new)) {
- $this->constraint = $constraint;
- $this->constraint_new = NULL;
- return new c_base_return_true();
- }
- else if (is_string($constraint_new)) {
- $this->constraint = $constraint;
- $this->constraint_new = $constraint_new;
- return new c_base_return_true();
- }
+
+ if (!is_string($constraint)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'constraint', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
}
- $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'expression', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
+ if (!is_null($new_name) && !is_string($new_name)) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'new_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_null($cascade) && $cascade !== e_database_cascade::CASCADE && $cascade !== e_database_cascade::RESTRICT) {
+ $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'cascade', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->constraint = [
+ 'name' => $constraint,
+ 'name_new' => $new_name,
+ 'cascade' => $cascade,
+ ];
+ return new c_base_return_true();
}
/**
return new c_base_return_null();
}
- return c_base_return_string::s_new($this->constraint);
+ return c_base_return_string::s_new($this->constraint['name']);
+ }
+
+ /**
+ * Get constraint cascade option.
+ *
+ * @return c_base_return_int|c_base_return_null
+ * An integer representing the constraint cascade option.
+ * NULL is returned if undefined.
+ * FALSE with error bit set is returned on error.
+ */
+ public function get_constraint_cascade() {
+ if (is_null($this->constraint) || is_null($this->constraint['cascade'])) {
+ return new c_base_return_null();
+ }
+
+ return c_base_return_int::s_new($this->constraint['cascade']);
}
/**
* NULL is returned if undefined.
* FALSE with error bit set is returned on error.
*/
- public function get_constraint_new() {
- if (is_null($this->constraint_new)) {
+ public function get_constraint_new_name() {
+ if (is_null($this->constraint) || is_null($this->constraint['name_new'])) {
return new c_base_return_null();
}
- return c_base_return_string::s_new($this->constraint_new);
+ return c_base_return_string::s_new($this->constraint['name_new']);
}
/**
$action = NULL;
switch ($this->action) {
case e_database_action::ADD:
- if (!is_string($this->constraint)) {
+ if (!is_array($this->constraint)) {
unset($action);
return new c_base_return_false();
}
$action = c_database_string::ADD;
- $action .= ' ' . $this->constraint;
+ $action .= ' ' . $this->constraint['name'];
if ($this->property === e_database_property::NOT_VALID) {
$action .= ' ' . c_database_string::NOT_VALID;
break;
case e_database_action::DROP_CONSTRAINT:
- if (!is_string($this->constraint)) {
+ if (!is_array($this->constraint['name'])) {
unset($action);
return new c_base_return_false();
}
$action .= ' ' . c_database_string::IF_EXISTS;
}
- $action .= ' ' . $this->constraint;
+ $action .= ' ' . $this->constraint['name'];
- $option = $this->p_do_build_option();
- if (is_string($option)) {
- $action .= ' ' . $option;
+ if ($this->constraint['cascade'] === e_database_cascade::CASCADE) {
+ $action .= ' ' . c_database_string::CASCADE;
+ }
+ else if ($this->constraint['cascade'] === e_database_cascade::RESTRICT) {
+ $action .= ' ' . c_database_string::RESTRICT;
}
- unset($option);
break;
case e_database_action::DROP_DEFAULT:
break;
case e_database_action::RENAME_CONSTRAINT:
- if (!is_string($this->constraint) || !is_string($this->constraint_new)) {
+ if (!is_string($this->constraint['name']) || !is_string($this->constraint['name_new'])) {
unset($action);
return new c_base_return_false();
}
- $action = c_database_string::RENAME_CONSTRAINT . ' ' . $this->constraint . ' ' . c_database_string::TO . ' ' . $this->constraint_new;
+ $action = c_database_string::RENAME_CONSTRAINT . ' ' . $this->constraint['name'] . ' ' . c_database_string::TO . ' ' . $this->constraint['name_new'];
break;
case e_database_action::RENAME_TO:
break;
case e_database_action::VALIDATE_CONSTRAINT:
- if (!is_string($this->constraint)) {
+ if (!is_array($this->constraint)) {
unset($action);
return new c_base_return_false();
}
- $action = c_database_string::VALIDATE_CONSTRAINT . ' ' . $this->constraint;
+ $action = c_database_string::VALIDATE_CONSTRAINT . ' ' . $this->constraint['name'];
break;
default:
+++ /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 option support for an SQL query.
- */
-trait t_database_option {
- protected $option;
-
- /**
- * Assigns this query option.
- *
- * @param int|null $option
- * Whether or not to use a query option, such as CASCADE.
- * 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($option) {
- if (is_null($option)) {
- $this->option = NULL;
- return new c_base_return_true();
- }
-
- if (is_int($option)) {
- $this->option = $option;
- return new c_base_return_true();
- }
-
- $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'option', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- /**
- * Get the currently assigned option.
- *
- * @return c_base_return_int|c_base_return_null
- * Integer representing the option is returned on success.
- * NULL is returned if undefined.
- * FALSE with error bit set is returned on error.
- */
- protected function get_option() {
- if (is_null($this->option)) {
- return new c_base_return_null();
- }
-
- return c_base_return_int::s_new($this->option);
- }
-
- /**
- * 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_option() {
- $value = NULL;
-
- if ($this->option === e_database_option::CASCADE) {
- $value = c_database_string::CASCADE;
- }
- else if ($this->option === e_database_option::RESTRICT) {
- $value = c_database_string::RESTRICT;
- }
-
- return $value;
- }
-}