]> Kevux Git Server - koopa/commitdiff
Progress: continue development on database abstraction
authorKevin Day <thekevinday@gmail.com>
Tue, 11 Dec 2018 05:48:31 +0000 (23:48 -0600)
committerKevin Day <thekevinday@gmail.com>
Tue, 11 Dec 2018 05:48:31 +0000 (23:48 -0600)
12 files changed:
common/database/classes/database_alter_function.php
common/database/classes/database_alter_group.php
common/database/classes/database_alter_index.php
common/database/classes/database_alter_language.php
common/database/classes/database_string.php
common/database/enumerations/database_storage_parameter.php [new file with mode: 0644]
common/database/traits/database_no_wait.php [new file with mode: 0644]
common/database/traits/database_owned_by.php [new file with mode: 0644]
common/database/traits/database_reset_storage_parameter.php [new file with mode: 0644]
common/database/traits/database_set.php
common/database/traits/database_set_storage_parameter.php [new file with mode: 0644]
common/database/traits/database_set_tablespace.php

index c2bf9b8c51706563adcaf45e84210d87de72f991..f0bade5065c3bbddcccf3a1a08a2f8a8b0307504 100644 (file)
@@ -24,7 +24,7 @@ require_once('common/database/traits/database_set_schema.php');
  *
  * @see: https://www.postgresql.org/docs/current/static/sql-alterfunction.html
  */
-class c_database_alter_coalation extends c_database_query {
+class c_database_alter_function extends c_database_query {
   use t_database_argument_type;
   use t_database_depends_on_extension;
   use t_database_function_action;
index e5926c70fad07817eb93270fd65a14d74082f7bc..cea116acdc376fa8dcadb0d7cb3557d4c791aa6a 100644 (file)
@@ -11,6 +11,8 @@ require_once('common/base/classes/base_return.php');
 require_once('common/database/classes/database_query.php');
 
 require_once('common/database/traits/database_add_user.php');
+require_once('common/database/traits/database_name.php');
+require_once('common/database/traits/database_rename_to.php');
 require_once('common/database/traits/database_role_specification.php');
 
 /**
@@ -18,8 +20,10 @@ require_once('common/database/traits/database_role_specification.php');
  *
  * @see: https://www.postgresql.org/docs/current/static/sql-altergroup.html
  */
-class c_database_alter_coalation extends c_database_query {
+class c_database_alter_group extends c_database_query {
   use t_database_add_user;
+  use t_database_name;
+  use t_database_rename_to;
   use t_database_role_specification;
 
   protected const p_QUERY_COMMAND = 'alter group';
@@ -32,6 +36,8 @@ class c_database_alter_coalation extends c_database_query {
     parent::__construct();
 
     $this->add_user           = NULL;
+    $this->name               = NULL;
+    $this->rename_to          = NULL;
     $this->role_specification = NULL;
   }
 
@@ -40,6 +46,8 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __destruct() {
     unset($this->add_user);
+    unset($this->name);
+    unset($this->rename_to);
     unset($this->role_specification);
 
     parent::__destruct();
@@ -70,13 +78,13 @@ class c_database_alter_coalation extends c_database_query {
    * Implements do_build().
    */
   public function do_build() {
-    if (!is_string($this->name)) {
-      return new c_base_return_false();
-    }
-
-    if ((is_int($this->role_specification) || is_string($this->role_specification)) && is_array($this->add_user)) {
+    if (is_array($this->add_user) && (is_int($this->role_specification) || is_string($this->role_specification))) {
       $value = $this->p_do_build_role_specification();
-      $value = ' ' . $this->p_do_build_add_user();
+      $value .= ' ' . $this->p_do_build_add_user();
+    }
+    else if (!is_string($this->name) && !is_string($this->rename_to)) {
+      $value = $this->p_do_build_name();
+      $value .= ' ' . $this->p_do_build_rename_to();
     }
     else {
       return new c_base_return_false();
index 54885a78e40eb319f679ce49d2db285b60047332..5383ba00da0e4ecf5ee9dc50f16c8953e7047daf 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * @file
- * Provides a class for specific Postgesql query: ALTER COALATION.
+ * Provides a class for specific Postgesql query: ALTER INDEX.
  */
 namespace n_koopa;
 
@@ -10,14 +10,34 @@ require_once('common/base/classes/base_return.php');
 
 require_once('common/database/classes/database_query.php');
 
+require_once('common/database/traits/database_depends_on_extension.php');
+require_once('common/database/traits/database_if_exists.php');
+require_once('common/database/traits/database_name.php');
+require_once('common/database/traits/database_no_wait.php');
+require_once('common/database/traits/database_owned_by.php');
+require_once('common/database/traits/database_rename_to.php');
+require_once('common/database/traits/database_reset_storage_parameter.php');
+require_once('common/database/traits/database_set_storage_parameter.php');
+require_once('common/database/traits/database_set_tablespace.php');
+
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql ALTER INDEX query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-alterindex.html
  */
-class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+class c_database_alter_index extends c_database_query {
+  use t_database_depends_on_extension;
+  use t_database_if_exists;
+  use t_database_name;
+  use t_database_no_wait;
+  use t_database_owned_by;
+  use t_database_rename_to;
+  use t_database_reset_index_storage_parameter;
+  use t_database_set_index_storage_parameter;
+  use t_database_set_tablespace;
+
+  protected const p_QUERY_COMMAND = 'alter index';
 
 
   /**
@@ -25,12 +45,32 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->depends_on_extension    = NULL;
+    $this->if_exists               = NULL;
+    $this->name                    = NULL;
+    $this->no_wait                 = NULL;
+    $this->owned_by                = NULL;
+    $this->rename_to               = NULL;
+    $this->reset_storage_parameter = NULL;
+    $this->set_storage_parameter   = NULL;
+    $this->set_tablespace          = NULL;
   }
 
   /**
    * Class destructor.
    */
   public function __destruct() {
+    unset($this->depends_on_extension);
+    unset($this->if_exists);
+    unset($this->name);
+    unset($this->no_wait);
+    unset($this->owned_by);
+    unset($this->rename_to);
+    unset($this->reset_storage_parameter);
+    unset($this->set_storage_parameter);
+    unset($this->set_tablespace);
+
     parent::__destruct();
   }
 
@@ -59,9 +99,56 @@ class c_database_alter_coalation extends c_database_query {
    * Implements do_build().
    */
   public function do_build() {
-    $this->value = NULL;
+    if (!is_string($this->name)) {
+      return new c_base_return_false();
+    }
+
+    $if_exists = NULL;
+    if (is_bool($this->if_exists)) {
+      $if_exists = ' ' . $this->p_do_build_if_exists();
+    }
+
+    $value = $this->name;
+    if (is_string($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else if (is_string($this->set_tablespace)) {
+      $value .= ' ' . $this->p_do_build_set_tablespace();
+    }
+    else if (is_string($this->depends_on_extension)) {
+      $if_exists = NULL;
+      $value .= ' ' . $this->p_do_build_depends_on_extension();
+    }
+    else if (is_array($this->set_storage_parameter)) {
+      $value .= ' ' . $this->p_do_build_set_storage_parameter();
+    }
+    else if (is_array($this->reset_storage_parameter)) {
+      $value .= ' ' . $this->p_do_build_reset_storage_parameter();
+    }
+    else if (is_string($this->set_tablespace)) {
+      $if_exists = NULL;
+      $value = c_database_string::ALL_IN_TABLESPACE . ' ' . $value;
+
+      if (is_array($this->owned_by)) {
+        $value .= ' ' . $this->p_do_build_owned_by();
+      }
+
+      $value .= ' ' . $this->p_do_build_set_tablespace();
+
+      if (is_bool($this->no_wait)) {
+        $value .= ' ' . $this->p_do_build_no_wait();
+      }
+    }
+
+    $this->value = static::p_QUERY_COMMAND;
+
+    if (is_string($if_exists)) {
+      $this->value .= $if_exists;
+    }
+    unset($if_exists);
 
-    // @todo
+    $this->value .= ' ' . $value;
+    unset($value);
 
     return new c_base_return_true();
   }
index 54885a78e40eb319f679ce49d2db285b60047332..1cd88877a2f5b162720840e38faae8b0108b0304 100644 (file)
@@ -59,10 +59,14 @@ class c_database_alter_coalation extends c_database_query {
    * Implements do_build().
    */
   public function do_build() {
-    $this->value = NULL;
+    if (!is_string($this->name)) {
+      return new c_base_return_false();
+    }
 
     // @todo
 
-    return new c_base_return_true();
+    $this->value = static::p_QUERY_COMMAND;
+    $this->value .= ' ' . $value;
+    unset($value);
   }
 }
index c57cd158d6149ec62d3c46133bb3b40c8581f70a..4ae49112437b43c1e99c9824750275792458f45b 100644 (file)
@@ -11,131 +11,154 @@ namespace n_koopa;
  * A collection of strings used for generating SQL.
  */
 class c_database_string {
-  public const ACCESS_METHOD              = 'access method';
-  public const ADD                        = 'add';
-  public const AGGREGATE                  = 'aggregate';
-  public const ALL                        = 'all';
-  public const ALLOW_CONNECTIONS          = 'allow_connections';
-  public const AS                         = 'as';
-  public const ASCEND                     = 'asc';
-  public const CALLED_ON_NULL_INPUT       = 'called on null input';
-  public const CASCADE                    = 'cascade';
-  public const CAST                       = 'cast';
-  public const COLLATION                  = 'collation';
-  public const CONNECTION_LIMIT           = 'connection limit';
-  public const CONVERSION                 = 'conversion';
-  public const COST                       = 'cost';
-  public const CREATE                     = 'create';
-  public const DEFAULT                    = 'default';
-  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 DROP                       = 'drop';
-  public const DROP_CONSTRAINT            = 'drop constraint';
-  public const DROP_DEFAULT               = 'drop default';
-  public const ENABLE_ALWAYS_TRIGGER      = 'enable always trigger';
-  public const ENABLE_REPLICA_TRIGGER     = 'enable replica trigger';
-  public const ENABLE_TRIGGER             = 'enable trigger';
-  public const EVENT_TRIGGER              = 'event trigger';
-  public const EXECUTE                    = 'execute';
-  public const EXTERNAL                   = 'external';
-  public const FALSE                      = 'false';
-  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';
-  public const GRANT_OPTION_FOR           = 'grant option for';
-  public const GROUP                      = 'group';
-  public const GROUP_BY                   = 'group by';
-  public const HANDLER                    = 'handler';
-  public const IF_EXISTS                  = 'if exists';
-  public const IMMUTABLE                  = 'immutable';
-  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 LANGUAGE                   = 'language';
-  public const LEAKPROOF                  = 'leakproof';
-  public const MATERIALIZED_VIEW          = 'materialized view';
-  public const NO_HANDLER                 = 'no handler';
-  public const NO_INHERIT                 = 'no inherit';
-  public const NO_VALIDATOR               = 'no validator';
-  public const NOT_LEAKPROOF              = 'not leakproof';
-  public const NOT_NULL                   = 'not null';
-  public const NOT_VALID                  = 'not valid';
-  public const ON_FUNCTIONS               = 'on functons';
-  public const ON_SCHEMAS                 = 'on schemas';
-  public const ON_SEQUENCES               = 'on sequences';
-  public const ON_TABLES_TO               = 'on tables to';
-  public const ON_TYPES                   = 'on types';
-  public const ONLY                       = 'only';
-  public const OPERATOR_CLASS             = 'operator class';
-  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 PARALLEL                   = 'parallel';
-  public const PROCEDURAL                 = 'procedural';
-  public const PUBLIC                     = 'public';
-  public const REFERENCES                 = 'references';
-  public const REFRESH_VERSION            = 'refresh version';
-  public const RENAME_TO                  = 'rename to';
-  public const RENAME_COLUMN              = 'rename column';
-  public const RENAME_CONSTRAINT          = 'rename constraint';
-  public const RESET                      = 'reset';
-  public const RESET_ALL                  = 'reset all';
-  public const RESTRICT                   = 'restrict';
-  public const RESTRICTED                 = 'restricted';
-  public const RETURNS_NULL_ON_NULL_INPUT = 'returns null on null input';
-  public const REVOKE                     = 'revoke';
-  public const ROLE                       = 'role';
-  public const ROWS                       = 'rows';
-  public const SAFE                       = 'safe';
-  public const SCHEMA                     = 'schema';
-  public const SECURITY_DEFINER           = 'security definer';
-  public const SECURITY_INVOKER           = 'security invoker';
-  public const SELECT                     = 'select';
-  public const SEQUENCE                   = 'sequence';
-  public const SERVER                     = 'server';
-  public const SET                        = 'set';
-  public const SET_DEFAULT                = 'set default';
-  public const SET_SCHEMA                 = 'set schema';
-  public const SET_TABLESPACE             = 'set tablespace';
-  public const SET_WITH_OIDS              = 'set with oids';
-  public const SET_WITHOUT_OIDS           = 'set without oids';
-  public const STABLE                     = 'stable';
-  public const STRICT                     = 'strict';
-  public const TABLE                      = 'table';
-  public const TEXT_SEARCH_CONFIGURATION  = 'text search configuration';
-  public const TEXT_SEARCH_DICTIONARY     = 'text search dictionary';
-  public const TEXT_SEARCH_PARSER         = 'text search parser';
-  public const TEXT_SEARCH_TEMPLATE       = 'text search template';
-  public const TRANSFORM_FOR              = 'transform for';
-  public const TRIGGER                    = 'trigger';
-  public const TRUE                       = 'true';
-  public const TRUNCATE                   = 'truncate';
-  public const TYPE                       = 'type';
-  public const TO                         = 'to';
-  public const UNSAFE                     = 'unsafe';
-  public const UPDATE                     = 'update';
-  public const USAGE                      = 'usage';
-  public const USER                       = 'user';
-  public const USER_CURRENT               = 'current_user';
-  public const USER_SESSION               = 'session_user';
-  public const USING                      = 'using';
-  public const VALIDATOR                  = 'validator';
-  public const VALIDATE_CONSTRAINT        = 'validate constraint';
-  public const VARIADIC                   = 'variadic';
-  public const VOLATILE                   = 'volatile';
-  public const VIEW                       = 'view';
-  public const WITH                       = 'with';
-  public const WITH_GRANT_OPTION          = 'with grant option';
+  public const ACCESS_METHOD                         = 'access method';
+  public const ADD                                   = 'add';
+  public const AGGREGATE                             = 'aggregate';
+  public const ALL                                   = 'all';
+  public const ALLOW_CONNECTIONS                     = 'allow_connections';
+  public const AS                                    = 'as';
+  public const ASCEND                                = 'asc';
+  public const AUTOSUMMARIZE                         = 'autosummarize';
+  public const AUTOVACUUM_ANALYZE_SCALE_FACTOR       = 'autovacuum_analyze_scale_factor';
+  public const AUTOVACUUM_ANALYZE_THRESHOLD          = 'autovacuum_analyze_threshold';
+  public const AUTOVACUUM_COST_DELAY                 = 'autovacuum_cost_delay';
+  public const AUTOVACUUM_COST_LIMIT                 = 'autovacuum_cost_limit';
+  public const AUTOVACUUM_ENABLED                    = 'autovacuum_enabled';
+  public const AUTOVACUUM_FREEZE_MIN_AGE             = 'autovacuum_freeze_min_age';
+  public const AUTOVACUUM_FREEZE_MAX_AGE             = 'autovacuum_freeze_max_age';
+  public const AUTOVACUUM_FREEZE_TABLE_AGE           = 'autovacuum_freeze_table_age';
+  public const AUTOVACUUM_MULTIXACT_FREEZE_MIN_AGE   = 'autovacuum_multixact_freeze_min_age';
+  public const AUTOVACUUM_MULTIXACT_FREEZE_TABLE_AGE = 'autovacuum_multixact_freeze_table_age';
+  public const AUTOVACUUM_SCALE_FACTOR               = 'autovacuum_scale_factor';
+  public const AUTOVACUUM_VACUUM_THRESHOLD           = 'autovacuum_vacuum_threshold';
+  public const BUFFERING                             = 'buffering';
+  public const CALLED_ON_NULL_INPUT                  = 'called on null input';
+  public const CASCADE                               = 'cascade';
+  public const CAST                                  = 'cast';
+  public const COLLATION                             = 'collation';
+  public const CONNECTION_LIMIT                      = 'connection limit';
+  public const CONVERSION                            = 'conversion';
+  public const COST                                  = 'cost';
+  public const CREATE                                = 'create';
+  public const DEFAULT                               = 'default';
+  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 DROP                                  = 'drop';
+  public const DROP_CONSTRAINT                       = 'drop constraint';
+  public const DROP_DEFAULT                          = 'drop default';
+  public const ENABLE_ALWAYS_TRIGGER                 = 'enable always trigger';
+  public const ENABLE_REPLICA_TRIGGER                = 'enable replica trigger';
+  public const ENABLE_TRIGGER                        = 'enable trigger';
+  public const EVENT_TRIGGER                         = 'event trigger';
+  public const EXECUTE                               = 'execute';
+  public const EXTERNAL                              = 'external';
+  public const FALSE                                 = 'false';
+  public const FAST_UPDATE                           = 'fastupdate';
+  public const FILL_FACTOR                           = 'fillfactor';
+  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';
+  public const GRANT_OPTION_FOR                      = 'grant option for';
+  public const GROUP                                 = 'group';
+  public const GROUP_BY                              = 'group by';
+  public const GIN_PENDING_LIST_LIMIT                = 'gin_pending_list_limit';
+  public const HANDLER                               = 'handler';
+  public const IF_EXISTS                             = 'if exists';
+  public const IMMUTABLE                             = 'immutable';
+  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 LANGUAGE                              = 'language';
+  public const LEAKPROOF                             = 'leakproof';
+  public const LOG_AUTOVACUUM_MIN_DURATION           = 'log_autovacuum_min_duration';
+  public const MATERIALIZED_VIEW                     = 'materialized view';
+  public const NO_HANDLER                            = 'no handler';
+  public const NO_INHERIT                            = 'no inherit';
+  public const NO_VALIDATOR                          = 'no validator';
+  public const NO_WAIT                               = 'no wait';
+  public const NOT_LEAKPROOF                         = 'not leakproof';
+  public const NOT_NULL                              = 'not null';
+  public const NOT_VALID                             = 'not valid';
+  public const ON_FUNCTIONS                          = 'on functons';
+  public const ON_SCHEMAS                            = 'on schemas';
+  public const ON_SEQUENCES                          = 'on sequences';
+  public const ON_TABLES_TO                          = 'on tables to';
+  public const ON_TYPES                              = 'on types';
+  public const ONLY                                  = 'only';
+  public const OPERATOR_CLASS                        = 'operator class';
+  public const OPERATOR_FAMILY                       = 'operator family';
+  public const OPTIONS                               = 'options';
+  public const ORDER_BY                              = 'order by';
+  public const OUT                                   = 'out';
+  public const OWNED_BY                              = 'owned by';
+  public const OWNER_TO                              = 'owner to';
+  public const PAGES_PER_RANGE                       = 'pages_per_range';
+  public const PARALLEL                              = 'parallel';
+  public const PARALLEL_WORKERS                      = 'parallel_workers';
+  public const PROCEDURAL                            = 'procedural';
+  public const PUBLIC                                = 'public';
+  public const REFERENCES                            = 'references';
+  public const REFRESH_VERSION                       = 'refresh version';
+  public const RENAME_TO                             = 'rename to';
+  public const RENAME_COLUMN                         = 'rename column';
+  public const RENAME_CONSTRAINT                     = 'rename constraint';
+  public const RESET                                 = 'reset';
+  public const RESET_ALL                             = 'reset all';
+  public const RESTRICT                              = 'restrict';
+  public const RESTRICTED                            = 'restricted';
+  public const RETURNS_NULL_ON_NULL_INPUT            = 'returns null on null input';
+  public const REVOKE                                = 'revoke';
+  public const ROLE                                  = 'role';
+  public const ROWS                                  = 'rows';
+  public const SAFE                                  = 'safe';
+  public const SCHEMA                                = 'schema';
+  public const SECURITY_DEFINER                      = 'security definer';
+  public const SECURITY_INVOKER                      = 'security invoker';
+  public const SELECT                                = 'select';
+  public const SEQUENCE                              = 'sequence';
+  public const SERVER                                = 'server';
+  public const SET                                   = 'set';
+  public const SET_DEFAULT                           = 'set default';
+  public const SET_SCHEMA                            = 'set schema';
+  public const SET_TABLESPACE                        = 'set tablespace';
+  public const SET_WITH_OIDS                         = 'set with oids';
+  public const SET_WITHOUT_OIDS                      = 'set without oids';
+  public const STABLE                                = 'stable';
+  public const STRICT                                = 'strict';
+  public const TABLE                                 = 'table';
+  public const TEXT_SEARCH_CONFIGURATION             = 'text search configuration';
+  public const TEXT_SEARCH_DICTIONARY                = 'text search dictionary';
+  public const TEXT_SEARCH_PARSER                    = 'text search parser';
+  public const TEXT_SEARCH_TEMPLATE                  = 'text search template';
+  public const TRANSFORM_FOR                         = 'transform for';
+  public const TRIGGER                               = 'trigger';
+  public const TRUE                                  = 'true';
+  public const TRUNCATE                              = 'truncate';
+  public const TYPE                                  = 'type';
+  public const TO                                    = 'to';
+  public const UNSAFE                                = 'unsafe';
+  public const UPDATE                                = 'update';
+  public const USAGE                                 = 'usage';
+  public const USER                                  = 'user';
+  public const USER_CATALOG_TABLE                    = 'user_catalog_table';
+  public const USER_CURRENT                          = 'current_user';
+  public const USER_SESSION                          = 'session_user';
+  public const USING                                 = 'using';
+  public const VALIDATOR                             = 'validator';
+  public const VALIDATE_CONSTRAINT                   = 'validate constraint';
+  public const VARIADIC                              = 'variadic';
+  public const VOLATILE                              = 'volatile';
+  public const VIEW                                  = 'view';
+  public const WITH                                  = 'with';
+  public const WITH_GRANT_OPTION                     = 'with grant option';
 }
diff --git a/common/database/enumerations/database_storage_parameter.php b/common/database/enumerations/database_storage_parameter.php
new file mode 100644 (file)
index 0000000..3ff59a9
--- /dev/null
@@ -0,0 +1,36 @@
+<?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 index storage_parameter and related queries.
+ */
+class e_database_storage_parameter {
+  public const NONE                                  = 0;
+  public const AUTOSUMMARIZE                         = 1;
+  public const AUTOVACUUM_ANALYZE_SCALE_FACTOR       = 2;
+  public const AUTOVACUUM_ANALYZE_THRESHOLD          = 3;
+  public const AUTOVACUUM_COST_DELAY                 = 4;
+  public const AUTOVACUUM_COST_LIMIT                 = 5;
+  public const AUTOVACUUM_ENABLED                    = 6;
+  public const AUTOVACUUM_FREEZE_MIN_AGE             = 7;
+  public const AUTOVACUUM_FREEZE_MAX_AGE             = 8;
+  public const AUTOVACUUM_FREEZE_TABLE_AGE           = 9;
+  public const AUTOVACUUM_MULTIXACT_FREEZE_MIN_AGE   = 10;
+  public const AUTOVACUUM_MULTIXACT_FREEZE_TABLE_AGE = 11;
+  public const AUTOVACUUM_SCALE_FACTOR               = 12;
+  public const AUTOVACUUM_VACUUM_THRESHOLD           = 13;
+  public const BUFFERING                             = 14;
+  public const FAST_UPDATE                           = 15;
+  public const FILL_FACTOR                           = 16;
+  public const GIN_PENDING_LIST_LIMIT                = 17;
+  public const LOG_AUTOVACUUM_MIN_DURATION           = 18;
+  public const PAGES_PER_RANGE                       = 19;
+  public const PARALLEL_WORKERS                      = 20;
+  public const USER_CATALOG_TABLE                    = 21;
+}
diff --git a/common/database/traits/database_no_wait.php b/common/database/traits/database_no_wait.php
new file mode 100644 (file)
index 0000000..3e0b274
--- /dev/null
@@ -0,0 +1,87 @@
+<?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 NOWAIT functionality.
+ */
+trait t_database_no_wait {
+  protected $no_wait;
+
+  /**
+   * Set the NOWAIT value.
+   *
+   * @param bool|null $no_wait
+   *   Set to TRUE for NOWAIT.
+   *   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_no_wait($no_wait) {
+    if (is_null($no_wait)) {
+      $this->no_wait = NULL;
+      return new c_base_return_true();
+    }
+
+    if (!is_bool($no_wait)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'no_wait', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+      return c_base_return_error::s_false($error);
+    }
+
+    $this->no_wait = $no_wait;
+    return new c_base_return_true();
+  }
+
+  /**
+   * Get the currently assigned no wait value.
+   *
+   * @return c_base_return_bool|c_base_return_null
+   *   TRUE for NOWAIT on success.
+   *   NULL is returned if not set.
+   *   NULL with the error bit set is returned on error.
+   */
+  public function get_no_wait() {
+    if (is_null($this->no_wait)) {
+      return new c_base_return_null();
+    }
+
+    if (is_bool($this->no_wait)) {
+      return c_base_return_bool::s_new($this->no_wait);
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'no_wait', ':{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_no_wait() {
+    if (is_null($this->no_wait)) {
+      return NULL;
+    }
+
+    return $this->no_wait ? c_database_string::NO_WAIT : NULL;
+  }
+}
diff --git a/common/database/traits/database_owned_by.php b/common/database/traits/database_owned_by.php
new file mode 100644 (file)
index 0000000..196a953
--- /dev/null
@@ -0,0 +1,119 @@
+<?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 OWNED BY functionality.
+ */
+trait t_database_owned_by {
+  protected $owned_by;
+
+  /**
+   * Assigns the SQL owned_by.
+   *
+   * @param int|null $owned_by
+   *   Set a owned_by 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_owned_by($owned_by) {
+    if (is_null($owned_by)) {
+      $this->owned_by = NULL;
+      return new c_base_return_true();
+    }
+
+    if (is_int($owned_by)) {
+      // no reason to add any owned_by once ALL is present.
+      if ($this->owned_by === e_database_owned_by::ALL) {
+        return new c_base_return_true();
+      }
+
+      if ($owned_by === e_database_owned_by::ALL) {
+        $this->owned_by = e_database_owned_by::ALL;
+      }
+      else {
+        if (!is_array($this->owned_by)) {
+          $this->owned_by = [];
+        }
+
+        $this->owned_by[] = $owned_by;
+      }
+
+      return new c_base_return_true();
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'owned_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+    return c_base_return_error::s_false($error);
+  }
+
+  /**
+   * Get the owned_by.
+   *
+   * @param int|null $index
+   *   (optional) Get the owned_by at the specified index.
+   *   When NULL, all owned_by are returned.
+   *
+   * @return c_base_return_int|c_base_return_array|c_base_return_null
+   *   An array of owned_by or NULL if not defined.
+   *   A single owned_by is returned if $index is an integer.
+   *   NULL with the error bit set is returned on error.
+   */
+  public function get_owned_by($index = NULL) {
+    if (is_null($this->owned_by)) {
+      return new c_base_return_null();
+    }
+
+    if (is_null($index)) {
+      if ($this->owned_by === e_database_owned_by::ALL) {
+        return c_base_return_array::s_new([$this->owned_by]);
+      }
+      else if (is_array($this->owned_by)) {
+        return c_base_return_array::s_new($this->owned_by);
+      }
+    }
+    else {
+      if (is_int($index) && array_key_exists($index, $this->owned_by) && is_int($this->owned_by[$index])) {
+        return clone($this->owned_by[$index]);
+      }
+
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'owned_by[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+      return c_base_return_error::s_null($error);
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'owned_by', ':{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_owned_by() {
+    if (is_null($this->owned_by)) {
+      return NULL;
+    }
+
+    return c_database_string::OWNED_BY . ' ' . implode(', ', $this->owned_by);
+  }
+}
diff --git a/common/database/traits/database_reset_storage_parameter.php b/common/database/traits/database_reset_storage_parameter.php
new file mode 100644 (file)
index 0000000..660c855
--- /dev/null
@@ -0,0 +1,138 @@
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with RESET storage_parameter.
+ *
+ * @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_index_storage_parameter.php');
+
+/**
+ * Provide the sql RESET (storage_parameter ...) functionality.
+ */
+trait t_database_reset_storage_parameter {
+  protected $reset_storage_parameter;
+
+  /**
+   * Set the RESET (storage_parameter ...) settings.
+   *
+   * @param int|null $storage_parameter
+   *   The index storage_parameter code to assign.
+   *   Should be one of: e_database_storage_parameter.
+   *   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_reset_storage_parameter($storage_parameter) {
+    if (is_null($storage_parameter)) {
+      $this->reset_storage_parameter = NULL;
+      return new c_base_return_true();
+    }
+
+    switch ($storage_parameter) {
+      case e_database_storage_parameter::AUTOSUMMARIZE:
+      case e_database_storage_parameter::BUFFERING:
+      case e_database_storage_parameter::FAST_UPDATE:
+      case e_database_storage_parameter::FILL_FACTOR:
+      case e_database_storage_parameter::GIN_PENDING_LIST_LIMIT:
+      case e_database_storage_parameter::PAGES_PER_RANGE:
+        break;
+      default:
+        $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'storage_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+        return c_base_return_error::s_false($error);
+    }
+
+    if (!is_array($this->reset_storage_parameter)) {
+      $this->reset_storage_parameter = [];
+    }
+
+    $this->reset_storage_parameter[] = $storage_parameter;
+    return new c_base_return_true();
+  }
+
+  /**
+   * Get the currently assigned RESET storage parameter at the specified index.
+   *
+   * @param int|null $index
+   *   (optional) Get the index storage parameter type at the specified index.
+   *   When NULL, all index storage parameter types are returned.
+   *
+   * @return c_base_return_array|c_base_return_int|c_base_return_null
+   *   A code or an array of codes representing the argument_type on success.
+   *   NULL is returned if not set (reset_storage_parameter tablespace is not to be used).
+   *   NULL with the error bit set is returned on error.
+   */
+  public function get_reset_storage_parameter($index = NULL) {
+    if (is_null($this->reset_storage_parameter)) {
+      return new c_base_return_null();
+    }
+
+    if (is_null($index)) {
+      if (is_array($this->reset_storage_parameter)) {
+        return c_base_return_array::s_new($this->reset_storage_parameter);
+      }
+    }
+    else {
+      if (is_int($index) && array_key_exists($index, $this->reset_storage_parameter) && is_int($this->reset_storage_parameter[$index])) {
+        return c_base_return_int::s_new($this->reset_storage_parameter[$index]);
+      }
+
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'reset_storage_parameter[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+      return c_base_return_error::s_null($error);
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'reset_storage_parameter', ':{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_reset_storage_parameter() {
+    if (is_null($this->reset_storage_parameter)) {
+      return NULL;
+    }
+
+    $values = [];
+    foreach ($this->reset_storage_parameter as $storage_parameter) {
+      if ($storage_parameter === e_database_storage_parameter::AUTOSUMMARIZE) {
+        $values[] = c_database_string::AUTOSUMMARIZE;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::BUFFERING) {
+        $values[] = c_database_string::BUFFERING;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::FAST_UPDATE) {
+        $values[] = c_database_string::FAST_UPDATE;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::FILL_FACTOR) {
+        $values[] = c_database_string::FILL_FACTOR;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::GIN_PENDING_LIST_LIMIT) {
+        $values[] = c_database_string::GIN_PENDING_LIST_LIMIT;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::PAGES_PER_RANGE) {
+        $values[] = c_database_string::PAGES_PER_RANGE;
+      }
+    }
+    unset($storage_parameter);
+
+    return c_database_string::RESET . ' ' . implode(', ', $values);
+  }
+}
index ec8377b09e62249341d33101182fae4547adc61b..dbdf4bf330b291a6100dcf013c9538d5faa11ab9 100644 (file)
@@ -3,7 +3,7 @@
  * @file
  * Provides traits for specific Postgesql Queries.
  *
- * These traits are associated with set/reset.
+ * These traits are associated with set.
  *
  * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
  */
@@ -33,7 +33,7 @@ trait t_database_set {
    *   (optional) When non-NULL this is the configuration parameter.
    *   When NULL, DEFAULT is used if applicablem otherwise this is ignored.
    * @param string|null $value
-   *   (optional) When non-NULL this is the value.
+   *   (optional) When non-NULL this is the value associated with the parameter.
    *   When NULL, this is ignored.
    *
    * @return c_base_return_status
@@ -51,13 +51,13 @@ trait t_database_set {
       return c_base_return_error::s_false($error);
     }
 
-    if ($set == e_database_set::TO || $set == e_database_set::EQUAL) {
+    if ($set === e_database_set::TO || $set === e_database_set::EQUAL) {
       if (!is_null($parameter) || !is_string($parameter)) {
         $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
         return c_base_return_error::s_false($error);
       }
 
-      if (!is_null($value) || !is_string($value)) {
+      if (!is_null($value) && !is_string($value)) {
         $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'value', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
         return c_base_return_error::s_false($error);
       }
diff --git a/common/database/traits/database_set_storage_parameter.php b/common/database/traits/database_set_storage_parameter.php
new file mode 100644 (file)
index 0000000..8679990
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with SET index storage_parameter.
+ *
+ * @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_index_storage_parameter.php');
+
+require_once('common/database/classes/database_string.php');
+
+/**
+ * Provide the sql SET functionality.
+ */
+trait t_database_set_storage_parameter {
+  protected $set_storage_parameter;
+
+  /**
+   * Set the SET index (storage_parameter ...) settings.
+   *
+   * @param int|null $storage_parameter
+   *   The storage parameter code to assign.
+   *   Should be one of: e_database_storage_parameter.
+   *   Set to NULL to disable.
+   * @param string|null $value
+   *   The value associated with the parameter.
+   *   This must not be NULL when $storage_parameter is not NULL.
+   *   When NULL, this is ignored.
+   *
+   * @return c_base_return_status
+   *   TRUE on success, FALSE otherwise.
+   *   FALSE with the error bit set is returned on error.
+   */
+  public function set_storage_parameter($storage_parameter, $value = NULL) {
+    if (is_null($storage_parameter)) {
+      $this->set_storage_parameter = NULL;
+      return new c_base_return_true();
+    }
+
+    switch ($storage_parameter) {
+      case e_database_storage_parameter::AUTOSUMMARIZE:
+      case e_database_storage_parameter::BUFFERING:
+      case e_database_storage_parameter::FAST_UPDATE:
+      case e_database_storage_parameter::FILL_FACTOR:
+      case e_database_storage_parameter::GIN_PENDING_LIST_LIMIT:
+      case e_database_storage_parameter::PAGES_PER_RANGE:
+        break;
+      default:
+        $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'storage_parameter', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+        return c_base_return_error::s_false($error);
+    }
+
+    if (!is_string($value)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'value', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+      return c_base_return_error::s_false($error);
+    }
+
+    if (!is_array($this->set_storage_parameter)) {
+      $this->set_storage_parameter = [];
+    }
+
+    $this->set_storage_parameter[] = [
+      'type' => $storage_parameter,
+      'value' => $value,
+    ];
+    return new c_base_return_true();
+  }
+
+  /**
+   * Get the currently assigned SET index storage parameter at the specified index.
+   *
+   * @param int|null $index
+   *   (optional) Get the index storage parameter type at the specified index.
+   *   When NULL, all index storage parameter types are returned.
+   *
+   * @return c_base_return_array|c_base_return_null
+   *   An array containing the set index storage parameter settings on success.
+   *   NULL is returned if not set (set index storage parameter not to be used).
+   *   NULL with the error bit set is returned on error.
+   */
+  public function get_set_storage_parameter($index = NULL) {
+    if (is_null($this->set_storage_parameter)) {
+      return new c_base_return_null();
+    }
+
+    if (is_null($index)) {
+      if (is_array($this->set_storage_parameter)) {
+        return c_base_return_array::s_new($this->set_storage_parameter);
+      }
+    }
+    else {
+      if (is_int($index) && array_key_exists($index, $this->set_storage_parameter) && is_int($this->set_storage_parameter[$index])) {
+        return c_base_return_array::s_new($this->set_storage_parameter[$index]);
+      }
+
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_storage_parameter[index]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+      return c_base_return_error::s_null($error);
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'set_storage_parameter', ':{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_set_storage_parameter() {
+    if (is_null($this->set_storage_parameter)) {
+      return NULL;
+    }
+
+    $values = [];
+    foreach ($this->set_storage_parameter as $storage_parameter => $value) {
+      if ($storage_parameter === e_database_storage_parameter::AUTOSUMMARIZE) {
+        $values[] = c_database_string::AUTOSUMMARIZE . ' = ' . $value;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::BUFFERING) {
+        $values[] = c_database_string::BUFFERING . ' = ' . $value;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::FAST_UPDATE) {
+        $values[] = c_database_string::FAST_UPDATE . ' = ' . $value;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::FILL_FACTOR) {
+        $values[] = c_database_string::FILL_FACTOR . ' = ' . $value;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::GIN_PENDING_LIST_LIMIT) {
+        $values[] = c_database_string::GIN_PENDING_LIST_LIMIT . ' = ' . $value;
+      }
+      else if ($storage_parameter === e_database_storage_parameter::PAGES_PER_RANGE) {
+        $values[] = c_database_string::PAGES_PER_RANGE . ' = ' . $value ;
+      }
+    }
+    unset($storage_parameter);
+    unset($value);
+
+    return c_database_string::SET . ' ' . implode(', ', $values);
+  }
+}
index 724657355e2cfe271c125bad7b71ccc4b5e894af..ff8dfbc3e043220d019b867dd63a20aa5700dc73 100644 (file)
@@ -76,6 +76,6 @@ trait t_database_set_tablespace {
       return NULL;
     }
 
-    return c_database_string::SET_TABLESPACE . ' (' . $this->set_tablespace . ')';
+    return c_database_string::SET_TABLESPACE . ' ' . $this->set_tablespace;
   }
 }