]> Kevux Git Server - koopa/commitdiff
Progress: continue development on database abstraction
authorKevin Day <thekevinday@gmail.com>
Sun, 3 Feb 2019 01:40:45 +0000 (19:40 -0600)
committerKevin Day <thekevinday@gmail.com>
Sun, 3 Feb 2019 01:40:45 +0000 (19:40 -0600)
16 files changed:
common/database/classes/database_alter_tablespace.php
common/database/classes/database_alter_text_search_configuration.php
common/database/classes/database_alter_text_search_dictionary.php
common/database/classes/database_alter_text_search_parser.php
common/database/classes/database_alter_text_search_template.php
common/database/classes/database_alter_trigger.php
common/database/classes/database_alter_type.php
common/database/classes/database_string.php
common/database/enumerations/database_mapping_for.php [new file with mode: 0644]
common/database/enumerations/database_position.php [new file with mode: 0644]
common/database/traits/database_action_mapping_for.php [new file with mode: 0644]
common/database/traits/database_action_not_of.php
common/database/traits/database_add_table.php
common/database/traits/database_add_value.php [new file with mode: 0644]
common/database/traits/database_set_schema.php
common/database/traits/database_with_dictionary.php [new file with mode: 0644]

index bf3857e4bf78d6f794f6cfd5183282524c688a2c..240bf354646b8b5c3e3dc73076484386b6dce0e4 100644 (file)
@@ -10,14 +10,26 @@ require_once('common/base/classes/base_return.php');
 
 require_once('common/database/classes/database_query.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_reset.php');
+require_once('common/database/traits/database_set.php');
+
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql ALTER TABLESPACE query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-altertablespace.html
  */
 class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+  use t_database_name;
+  use t_database_owner_to;
+  use t_database_rename_to;
+  use t_database_reset;
+  use t_database_set;
+
+  protected const p_QUERY_COMMAND = 'alter tablespace';
 
 
   /**
@@ -25,6 +37,12 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->name      = NULL;
+    $this->owner_to  = NULL;
+    $this->rename_to = NULL;
+    $this->reset     = NULL;
+    $this->set       = NULL;
   }
 
   /**
@@ -32,6 +50,12 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __destruct() {
     parent::__destruct();
+
+    unset($this->name);
+    unset($this->owner_to);
+    unset($this->rename_to);
+    unset($this->reset);
+    unset($this->set);
   }
 
   /**
@@ -64,6 +88,18 @@ class c_database_alter_coalation extends c_database_query {
     }
 
     $value = $this->p_do_build_name();
+    if (isset($this->owner_to)) {
+      $value .= ' ' . $this->p_do_build_owner_to();
+    }
+    else if (isset($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else if (isset($this->reset)) {
+      $value .= ' ' . $this->p_do_build_reset();
+    }
+    else if (isset($this->set)) {
+      $value .= ' ' . $this->p_do_build_set();
+    }
 
     $this->value = static::p_QUERY_COMMAND;
     $this->value .= ' ' . $value;
index bf3857e4bf78d6f794f6cfd5183282524c688a2c..d08a8960db987c1e979385d91b09619f7567ad98 100644 (file)
@@ -10,14 +10,30 @@ require_once('common/base/classes/base_return.php');
 
 require_once('common/database/classes/database_query.php');
 
+require_once('common/database/enumerations/database_mapping_for.php');
+
+require_once('common/database/traits/database_mapping_for.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_set_schema.php');
+require_once('common/database/traits/database_with_dictionary.php');
+
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql TEXT SEARCH CONFIGURATION query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-altertextsearchconfiguration.html
  */
-class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+class c_database_alter_text_search_configuration extends c_database_query {
+  use t_database_mapping_for;
+  use t_database_name;
+  use t_database_owner_to;
+  use t_database_rename_to;
+  use t_database_set_schema;
+  use t_database_with_dictionary;
+
+  protected const p_QUERY_COMMAND = 'alter text search configuration';
 
 
   /**
@@ -25,12 +41,26 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->mapping_for     = NULL;
+    $this->name            = NULL;
+    $this->owner_to        = NULL;
+    $this->rename_to       = NULL;
+    $this->set_schema      = NULL;
+    $this->with_dictionary = NULL;
   }
 
   /**
    * Class destructor.
    */
   public function __destruct() {
+    unset($this->mapping_for);
+    unset($this->name);
+    unset($this->owner_to);
+    unset($this->rename_to);
+    unset($this->set_schema);
+    unset($this->with_dictionary);
+
     parent::__destruct();
   }
 
@@ -64,6 +94,45 @@ class c_database_alter_coalation extends c_database_query {
     }
 
     $value = $this->p_do_build_name();
+    if (isset($this->owner_to)) {
+      $value .= ' ' . $this->p_do_build_owner_to();
+    }
+    else if (isset($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else if (isset($this->set_schema)) {
+      $value .= ' ' . $this->p_do_build_set_schema();
+    }
+    else if (isset($this->mapping_for['type'])) {
+      $value .= ' ' . $this->p_do_build_mapping_for();
+
+      if ($this->mapping_for['type'] === e_database_mapping_for::REPLACE) {
+        if (isset($this->with_dictionary) && count($this->with_dictionary) == 1) {
+          // when mapping is REPLACE, there should only be a single with_dictionary entry.
+          $value .= ' ' . $this->p_do_build_with_dictionary();
+        }
+        else {
+          unset($value);
+          return new c_base_return_false();
+        }
+      }
+      else if ($this->mapping_for['type'] !== e_database_mapping_for::DROP) {
+        if (isset($this->with_dictionary)) {
+          $value .= ' ' . $this->p_do_build_with_dictionary();
+        }
+        else {
+          unset($value);
+          return new c_base_return_false();
+        }
+      }
+    }
+    else if (isset($this->mapping_replace)) {
+      $value .= ' ' . $this->p_do_build_mapping_replace();
+    }
+    else {
+      unset($value);
+      return new c_base_return_false();
+    }
 
     $this->value = static::p_QUERY_COMMAND;
     $this->value .= ' ' . $value;
index bf3857e4bf78d6f794f6cfd5183282524c688a2c..cf37e696f5fdff93c4f3d5af512af06594f6656b 100644 (file)
@@ -10,14 +10,26 @@ require_once('common/base/classes/base_return.php');
 
 require_once('common/database/classes/database_query.php');
 
+require_once('common/database/traits/database_name.php');
+require_once('common/database/traits/database_options.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_set_schema.php');
+
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql ALTER TEXT SEARCH DICTIONARY query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-altertextsearchdictionary.html
  */
-class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+class c_database_alter_text_search_dictionary extends c_database_query {
+  use t_database_name;
+  use t_database_options;
+  use t_database_owner_to;
+  use t_database_rename_to;
+  use t_database_set_schema;
+
+  protected const p_QUERY_COMMAND = 'alter text search dictionary';
 
 
   /**
@@ -25,12 +37,24 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->name       = NULL;
+    $this->options    = NULL;
+    $this->owner_to   = NULL;
+    $this->rename_to  = NULL;
+    $this->set_schema = NULL;
   }
 
   /**
    * Class destructor.
    */
   public function __destruct() {
+    unset($this->name);
+    unset($this->options);
+    unset($this->owner_to);
+    unset($this->rename_to);
+    unset($this->set_schema);
+
     parent::__destruct();
   }
 
@@ -64,6 +88,22 @@ class c_database_alter_coalation extends c_database_query {
     }
 
     $value = $this->p_do_build_name();
+    if (isset($this->options)) {
+      $value .= ' ' . $this->p_do_build_options();
+    }
+    else if (isset($this->owner_to)) {
+      $value .= ' ' . $this->p_do_build_owner_to();
+    }
+    else if (isset($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else if (isset($this->set_schema)) {
+      $value .= ' ' . $this->p_do_build_set_schema();
+    }
+    else {
+      unset($value);
+      return new c_base_return_false();
+    }
 
     $this->value = static::p_QUERY_COMMAND;
     $this->value .= ' ' . $value;
index bf3857e4bf78d6f794f6cfd5183282524c688a2c..a639363c1a6390ef28171ba246e1e90903dbaf25 100644 (file)
@@ -10,14 +10,21 @@ require_once('common/base/classes/base_return.php');
 
 require_once('common/database/classes/database_query.php');
 
+require_once('common/database/traits/database_name.php');
+require_once('common/database/traits/database_rename_to.php');
+require_once('common/database/traits/database_set_schema.php');
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql ALTER TEXT SEARCH PARSER query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-altertextsearchparser.html
  */
-class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+class c_database_alter_text_search_parser extends c_database_query {
+  use t_database_name;
+  use t_database_rename_to;
+  use t_database_set_schema;
+
+  protected const p_QUERY_COMMAND = 'alter text search parser';
 
 
   /**
@@ -25,12 +32,20 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->name       = NULL;
+    $this->rename_to  = NULL;
+    $this->set_schema = NULL;
   }
 
   /**
    * Class destructor.
    */
   public function __destruct() {
+    unset($this->name);
+    unset($this->rename_to);
+    unset($this->set_schema);
+
     parent::__destruct();
   }
 
@@ -64,6 +79,16 @@ class c_database_alter_coalation extends c_database_query {
     }
 
     $value = $this->p_do_build_name();
+    if (isset($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else if (isset($this->set_schema)) {
+      $value .= ' ' . $this->p_do_build_set_schema();
+    }
+    else {
+      unset($value);
+      return new c_base_return_false();
+    }
 
     $this->value = static::p_QUERY_COMMAND;
     $this->value .= ' ' . $value;
index bf3857e4bf78d6f794f6cfd5183282524c688a2c..91fc618c3e9c29472678b5393db144b7f304468b 100644 (file)
@@ -10,14 +10,22 @@ require_once('common/base/classes/base_return.php');
 
 require_once('common/database/classes/database_query.php');
 
+require_once('common/database/traits/database_name.php');
+require_once('common/database/traits/database_rename_to.php');
+require_once('common/database/traits/database_set_schema.php');
+
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql ALTER TEXT SEARCH TEMPLATE query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-altertextsearchtemplate.html
  */
-class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+class c_database_alter_text_search_template extends c_database_query {
+  use t_database_name;
+  use t_database_rename_to;
+  use t_database_set_schema;
+
+  protected const p_QUERY_COMMAND = 'alter text search template';
 
 
   /**
@@ -25,12 +33,20 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->name       = NULL;
+    $this->rename_to  = NULL;
+    $this->set_schema = NULL;
   }
 
   /**
    * Class destructor.
    */
   public function __destruct() {
+    unset($this->name);
+    unset($this->rename_to);
+    unset($this->set_schema);
+
     parent::__destruct();
   }
 
@@ -64,6 +80,16 @@ class c_database_alter_coalation extends c_database_query {
     }
 
     $value = $this->p_do_build_name();
+    if (isset($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else if (isset($this->set_schema)) {
+      $value .= ' ' . $this->p_do_build_set_schema();
+    }
+    else {
+      unset($value);
+      return new c_base_return_false();
+    }
 
     $this->value = static::p_QUERY_COMMAND;
     $this->value .= ' ' . $value;
index bf3857e4bf78d6f794f6cfd5183282524c688a2c..b087072e51e9bc0382500170f33a2b4c37b61c1f 100644 (file)
@@ -10,14 +10,22 @@ 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_name.php');
+require_once('common/database/traits/database_rename_to.php');
+
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql ALTER TRIGGER query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-altertrigger.html
  */
-class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+class c_database_alter_trigger extends c_database_query {
+  use t_database_depends_on_extension;
+  use t_database_name;
+  use t_database_rename_to;
+
+  protected const p_QUERY_COMMAND = 'alter trigger';
 
 
   /**
@@ -25,12 +33,20 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->depends_on_extension = NULL;
+    $this->name                 = NULL;
+    $this->rename_to            = NULL;
   }
 
   /**
    * Class destructor.
    */
   public function __destruct() {
+    unset($this->depends_on_extension);
+    unset($this->name);
+    unset($this->rename_to);
+
     parent::__destruct();
   }
 
@@ -64,6 +80,16 @@ class c_database_alter_coalation extends c_database_query {
     }
 
     $value = $this->p_do_build_name();
+     if (isset($this->depends_on_extension)) {
+      $value .= ' ' . $this->p_do_build_depends_on_extension();
+    }
+    else if (isset($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else {
+      unset($value);
+      return new c_base_return_false();
+    }
 
     $this->value = static::p_QUERY_COMMAND;
     $this->value .= ' ' . $value;
index bf3857e4bf78d6f794f6cfd5183282524c688a2c..32fe198f7b1eb016032a21629dc789b77a9ae4ab 100644 (file)
@@ -10,14 +10,31 @@ require_once('common/base/classes/base_return.php');
 
 require_once('common/database/classes/database_query.php');
 
+require_once('common/database/traits/database_add_value.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_attribute.php');
+require_once('common/database/traits/database_rename_to.php');
+require_once('common/database/traits/database_rename_value.php');
+require_once('common/database/traits/database_set_schema.php');
+require_once('common/database/traits/database_type_action.php');
 
 /**
- * The class for building and returning a Postgresql ALTER COALATION query string.
+ * The class for building and returning a Postgresql ALTER TYPE query string.
  *
- * @see: https://www.postgresql.org/docs/current/static/sql-alteraggregate.html
+ * @see: https://www.postgresql.org/docs/current/static/sql-altertype.html
  */
-class c_database_alter_coalation extends c_database_query {
-  protected const p_QUERY_COMMAND = 'alter coalation';
+class c_database_alter_type extends c_database_query {
+  use t_database_add_value;
+  use t_database_name;
+  use t_database_owner_to;
+  use t_database_rename_attribute;
+  use t_database_rename_to;
+  use t_database_rename_value;
+  use t_database_set_schema;
+  use t_database_type_action;
+
+  protected const p_QUERY_COMMAND = 'alter type';
 
 
   /**
@@ -25,12 +42,30 @@ class c_database_alter_coalation extends c_database_query {
    */
   public function __construct() {
     parent::__construct();
+
+    $this->add_value        = NULL;
+    $this->name             = NULL;
+    $this->owner_to         = NULL;
+    $this->rename_attribute = NULL;
+    $this->rename_to        = NULL;
+    $this->rename_value     = NULL;
+    $this->set_schema       = NULL;
+    $this->type_action      = NULL;
   }
 
   /**
    * Class destructor.
    */
   public function __destruct() {
+    unset($this->add_value);
+    unset($this->name);
+    unset($this->owner_to);
+    unset($this->rename_attribute);
+    unset($this->rename_to);
+    unset($this->rename_value);
+    unset($this->set_schema);
+    unset($this->type_action);
+
     parent::__destruct();
   }
 
@@ -64,6 +99,31 @@ class c_database_alter_coalation extends c_database_query {
     }
 
     $value = $this->p_do_build_name();
+     if (isset($this->add_value)) {
+      $value .= ' ' . $this->p_do_build_add_value();
+    }
+    else if (isset($this->owner_to)) {
+      $value .= ' ' . $this->p_do_build_owner_to();
+    }
+    else if (isset($this->rename_attribute)) {
+      $value .= ' ' . $this->p_do_build_rename_attribute();
+    }
+    else if (isset($this->rename_to)) {
+      $value .= ' ' . $this->p_do_build_rename_to();
+    }
+    else if (isset($this->rename_value)) {
+      $value .= ' ' . $this->p_do_build_rename_value();
+    }
+    else if (isset($this->set_schema)) {
+      $value .= ' ' . $this->p_do_build_set_schema();
+    }
+    else if (isset($this->type_action)) {
+      $value .= ' ' . $this->p_do_build_type_action();
+    }
+    else {
+      unset($value);
+      return new c_base_return_false();
+    }
 
     $this->value = static::p_QUERY_COMMAND;
     $this->value .= ' ' . $value;
index 0cf78935792b5ec6f79a4f5320a1bc5b60fc4bba..b3359eb53e2a9f7a8db9c7fa9ac0760b13368e90 100644 (file)
@@ -15,6 +15,8 @@ class c_database_string {
   public const ADD                                   = 'add';
   public const ADD_COLUMN                            = 'add column';
   public const ADD_TABLE                             = 'add table';
+  public const ADD_VALUE                             = 'add value';
+  public const AFTER                                 = 'after';
   public const AGGREGATE                             = 'aggregate';
   public const ALL                                   = 'all';
   public const ALLOW_CONNECTIONS                     = 'allow_connections';
@@ -36,8 +38,9 @@ class c_database_string {
   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 BYPASSRLS                             = 'bypassrls';
+  public const BEFORE                                = 'before';
   public const BUFFERING                             = 'buffering';
+  public const BYPASSRLS                             = 'bypassrls';
   public const CACHE                                 = 'cache';
   public const CALLED_ON_NULL_INPUT                  = 'called on null input';
   public const CASCADE                               = 'cascade';
@@ -70,6 +73,7 @@ class c_database_string {
   public const DROP                                  = 'drop';
   public const DROP_CONSTRAINT                       = 'drop constraint';
   public const DROP_DEFAULT                          = 'drop default';
+  public const DROP_MAPPING                          = 'drop mapping';
   public const DROP_TABLE                            = 'drop table';
   public const ENABLE                                = 'enable';
   public const ENABLED                               = 'enabled';
@@ -103,6 +107,7 @@ class c_database_string {
   public const GIN_PENDING_LIST_LIMIT                = 'gin_pending_list_limit';
   public const HANDLER                               = 'handler';
   public const IF_EXISTS                             = 'if exists';
+  public const IF_NOT_EXISTS                         = 'if not exists';
   public const IMMUTABLE                             = 'immutable';
   public const IN                                    = 'in';
   public const IN_DATABASE                           = 'in database';
@@ -118,6 +123,9 @@ class c_database_string {
   public const LOGIN                                 = 'login';
   public const LOG_AUTOVACUUM_MIN_DURATION           = 'log_autovacuum_min_duration';
   public const MAIN                                  = 'main';
+  public const MAPPING                               = 'mapping';
+  public const MAPPING_FOR                           = 'mapping for';
+  public const MAPPING_REPLACE                       = 'mapping replace';
   public const MATERIALIZED_VIEW                     = 'materialized view';
   public const MAXVALUE                              = 'maxvalue';
   public const MINVALUE                              = 'minvalue';
@@ -241,6 +249,7 @@ class c_database_string {
   public const VOLATILE                              = 'volatile';
   public const VIEW                                  = 'view';
   public const WITH                                  = 'with';
+  public const WITH_DICTIONARY                       = 'with dictionary';
   public const WITHOUT_CLUSTER                       = 'without cluster';
   public const WITH_CHECK                            = 'with check';
   public const WITH_GRANT_OPTION                     = 'with grant option';
diff --git a/common/database/enumerations/database_mapping_for.php b/common/database/enumerations/database_mapping_for.php
new file mode 100644 (file)
index 0000000..d642da7
--- /dev/null
@@ -0,0 +1,19 @@
+<?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 mapping for types.
+ */
+class e_database_mapping_for {
+  public const NONE    = 0;
+  public const ADD     = 1;
+  public const ALTER   = 2;
+  public const DROP    = 3;
+  public const REPLACE = 4;
+}
diff --git a/common/database/enumerations/database_position.php b/common/database/enumerations/database_position.php
new file mode 100644 (file)
index 0000000..643b962
--- /dev/null
@@ -0,0 +1,17 @@
+<?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 position.
+ */
+class e_database_position {
+  public const NONE   = 0;
+  public const AFTER  = 1;
+  public const BEFORE = 2;
+}
diff --git a/common/database/traits/database_action_mapping_for.php b/common/database/traits/database_action_mapping_for.php
new file mode 100644 (file)
index 0000000..a8384bc
--- /dev/null
@@ -0,0 +1,160 @@
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * @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_mapping_for.php');
+
+/**
+ * Provide the sql MAPPING FOR functionality.
+ */
+trait t_database_mapping_for {
+  protected $mapping_for;
+
+  /**
+   * Set the MAPPING FOR settings.
+   *
+   * Set all parameters to NULL to reset data to NULL.
+   *
+   * @param int|null $type
+   *   The mapping type from e_database_mapping_for.
+   * @param string|null $token
+   *   (optional) The token type.
+   * @param bool|null $if_exists
+   *   (optional) Boolean for adding IF EXISTS when $type is DROP.
+   *   Set to TRUE to use IF EXISTS.
+   *
+   * @return c_base_return_status
+   *   TRUE on success, FALSE otherwise.
+   *   FALSE with the error bit set is returned on error.
+   */
+  public function set_mapping_for($type, $token = NULL, $if_exists = NULL) {
+    if (is_null($name) && is_null($token) && is_null($if_exists)) {
+      $this->mapping_for = NULL;
+      return new c_base_return_true();
+    }
+
+    switch ($type) {
+      case e_database_mapping_for::ADD:
+      case e_database_mapping_for::ALTER:
+      case e_database_mapping_for::DROP:
+      case e_database_mapping_for::REPLACE:
+        $this->mapping_for['type'] = $type;
+        break;
+      case NULL:
+        break;
+      default:
+        $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+        return c_base_return_error::s_false($error);
+    }
+
+    if (!is_null($token) && !is_string($token)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'token', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+      return c_base_return_error::s_false($error);
+    }
+
+    if (!is_array($this->mapping_for)) {
+      $this->mapping_for = [
+        'type' => NULL,
+        'values' => [],
+        'if_exists' => NULL,
+      ];
+    }
+
+    if (is_int($type)) {
+      $this->mapping_for['type'] = $type;
+    }
+
+    if (is_string($token)) {
+      $placeholder = $this->add_placeholder($token);
+      if ($placeholder->has_error()) {
+        return c_base_return_error::s_false($placeholder->get_error());
+      }
+
+      $this->mapping_for['values'][] = $placeholder;
+      unset($placeholder);
+    }
+
+    if (is_bool($if_exists)) {
+      $this->mapping_for['if_exists'] = $if_exists;
+    }
+
+    return new c_base_return_true();
+  }
+
+  /**
+   * Get the currently assigned settings.
+   *
+   * @return c_base_return_array|c_base_return_null
+   *   An array containing the add table settings.
+   *   NULL is returned if not set (add table not to be used).
+   *   NULL with the error bit set is returned on error.
+   */
+  public function get_mapping_for() {
+    if (is_null($this->mapping_for)) {
+      return new c_base_return_null();
+    }
+
+    if (isset($this->mapping_for)) {
+      return c_base_return_array::s_new($this->mapping_for);
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'mapping_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.
+   *   NULL is returned if there is nothing to process or there is an error.
+   */
+  protected function p_do_build_mapping_for() {
+    $value = NULL;
+
+    if ($this->mapping_for['type'] === e_database_mapping_for::ADD) {
+      $value = c_database_string::ADD . ' ' . c_database_string::MAPPING_FOR;
+    }
+    else if ($this->mapping_for['type'] === e_database_mapping_for::ALTER) {
+      $value = c_database_string::ALTER . ' ' . c_database_string::MAPPING_FOR;
+    }
+    else if ($this->mapping_for['type'] === e_database_mapping_for::DROP) {
+      $value = c_database_string::DROP_MAPPING;
+
+      if ($this->mapping_for['if_exists']) {
+        $value .= ' ' . c_database_string::IF_EXISTS;
+      }
+
+      $value .= ' ' . c_database_string::FOR;
+    }
+    else if ($this->mapping_for['type'] === e_database_mapping_for::REPLACE) {
+      $value = c_database_string::ALTER . ' ' . c_database_string::MAPPING;
+
+      if (isset($this->mapping_for['values'])) {
+        $value .= ' ' . c_database_string::FOR;
+      }
+    }
+
+    if (isset($this->mapping_for['values'])) {
+      $value .= ' ' . implode(', ', $this->mapping_for['values']);
+    }
+
+    if ($this->mapping_for['type'] === e_database_mapping_for::REPLACE) {
+      $value .= ' ' . c_database_string::REPLACE;
+    }
+
+    return $value;
+  }
+}
index 0d5872c96fb9f8bcd679c6e5b82a10a31eaa2d25..1fa489b718a9dc677b1a9e97dc4ffccbb2055d75 100644 (file)
@@ -59,7 +59,7 @@ trait t_database_action_not_of {
     }
 
     if (is_bool($this->action_not_of)) {
-      return c_base_return_bool:s_new($this->action_not_of);
+      return c_base_return_bool::s_new($this->action_not_of);
     }
 
     $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'action_not_of', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
index a84b2bea1f29730de31f8317afcad84ebe1ee93e..2574a7bfe5e2c337dd54626066cef4e3fde7c286 100644 (file)
@@ -78,10 +78,6 @@ trait t_database_add_table {
   /**
    * Get the currently assigned add table settings.
    *
-   * @param int|null $index
-   *   (optional) Get the add table settings at the specified index.
-   *   When NULL, all add table settings are returned.
-   *
    * @return c_base_return_array|c_base_return_null
    *   An array containing the add table settings.
    *   NULL is returned if not set (add table not to be used).
diff --git a/common/database/traits/database_add_value.php b/common/database/traits/database_add_value.php
new file mode 100644 (file)
index 0000000..319ab4c
--- /dev/null
@@ -0,0 +1,153 @@
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * @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_position.php');
+
+/**
+ * Provide the sql ADD VALUE functionality.
+ */
+trait t_database_add_value {
+  protected $add_value;
+
+  /**
+   * Set the SET WITH OIDS value.
+   *
+   * @param string|null $new_enum_value
+   *   The enum value to use.
+   *   Set to NULL to disable.
+   * @param bool|null $if_not_exists
+   *   (optional) If TRUE, IF NO EXISTS is used.
+   *   If FALSE, do nothing.
+   *   If NULL, do nothing.
+   * @param int|null $position
+   *   (optional) Either BEFORE or AFTER from e_database_position.
+   *   If NULL, do nothing.
+   * @param string|null $neighbor_enum_value
+   *   The neighbor enum value to use.
+   *   When not NULL, $position must also be not NULL.
+   *   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_add_value($new_enum_value, $if_not_exists = NULL, $position = NULL, $neighbor_enum_value = NULL) {
+    if (is_null($add_value)) {
+      $this->add_value = NULL;
+      return new c_base_return_true();
+    }
+
+    if (!is_string($new_enum_value)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'new_enum_value', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+      return c_base_return_error::s_false($error);
+    }
+
+    if (!is_bool($if_not_exists)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'if_not_exists', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+      return c_base_return_error::s_false($error);
+    }
+
+    switch ($position) {
+      case e_database_position::AFTER:
+      case e_database_position::BEFORE:
+      case NULL:
+        break;
+      default:
+        $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'position', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+        return c_base_return_error::s_false($error);
+    }
+
+    if (!is_null($neighbor_enum_value) && !is_string($neighbor_enum_value)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'neighbor_enum_value', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+      return c_base_return_error::s_false($error);
+    }
+
+    $placeholder_new_enum_value = $this->add_placeholder($new_enum_value);
+    if ($placeholder_new_enum_value->has_error()) {
+      return c_base_return_error::s_false($placeholder_new_enum_value->get_error());
+    }
+
+    $placeholder_neighbor_enum_value = NULL;
+    if (is_string($neighbor_enum_value)) {
+      unset($placeholder_new_enum_value);
+      $placeholder_neighbor_enum_value = $this->add_placeholder($neighbor_enum_value);
+      if ($placeholder_neighbor_enum_value->has_error()) {
+        return c_base_return_error::s_false($placeholder_neighbor_enum_value->get_error());
+      }
+    }
+
+    $this->add_value = [
+      'new_enum_value' => $placeholder_new_enum_value,
+      'if_not_exists' =>  $if_not_exists,
+      'position' => $position,
+      'neighbor_enum_value' => $placeholder_neighbor_enum_value,
+    ];
+    unset($placeholder_new_enum_value);
+    unset($placeholder_neighbor_enum_value);
+
+    return new c_base_return_true();
+  }
+
+  /**
+   * Get the currently assigned settings.
+   *
+   * @return c_base_return_array|c_base_return_null
+   *   An array containing the settings.
+   *   NULL is returned if not set.
+   *   NULL with the error bit set is returned on error.
+   */
+  public function get_add_value() {
+    if (is_null($this->add_value)) {
+      return new c_base_return_null();
+    }
+
+    if (is_array($this->add_value)) {
+      return c_base_return_array::s_new($this->add_value);
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'add_value', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+    return c_base_return_error::s_null($error);
+  }
+
+  /**
+   * Perform the common build process for this trait.
+   *
+   * As an internal trait method, the caller is expected to perform any appropriate validation.
+   *
+   * @return string|null
+   *   A string is returned.
+   *   NULL is returned if there is nothing to process or there is an error.
+   */
+  protected function p_do_build_add_value() {
+    $value = c_database_string::ADD_VALUE;
+    $value .= ' \'' . $this->add_value['new_enum_value'] . '\'';
+
+    if ($this->add_value['if_not_exists']) {
+      $value .= ' ' . c_database_string::IF_NOT_EXISTS;
+    }
+
+    if (is_int($this->add_value['position'])) {
+      if ($this->add_value['position'] === e_database_position::AFTER) {
+        $value .= ' ' . c_database_string::AFTER;
+      }
+      else if ($this->add_value['position'] === e_database_position::BEFORE) {
+        $value .= ' ' . c_database_string::BEFORE;
+      }
+
+      $value .= ' \'' . $this->add_value['neighbor_enum_value'] . '\'';
+    }
+
+    return $value;
+  }
+}
index 05a597cd70a8751510568822b1691fc7972b5241..3fffb66c0c1d5a5e2e0582b8855d0ceb9596dbda 100644 (file)
@@ -19,9 +19,9 @@ trait t_database_set_schema {
   protected $set_schema;
 
   /**
-   * Set the RENAME TO settings.
+   * Set the SET SCHEMA settings.
    *
-   * @param string|null $set_schema
+   * @param string|null $name
    *   The schema name.
    *   Set to NULL to disable.
    *
@@ -29,13 +29,18 @@ trait t_database_set_schema {
    *   TRUE on success, FALSE otherwise.
    *   FALSE with the error bit set is returned on error.
    */
-  public function set_set_schema($set_schema) {
-    if (!is_null($set_schema) && !is_string($set_schema)) {
-      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'set_schema', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+  public function set_set_schema($name) {
+    if (is_null($name)) {
+      $this->set_schema = NULL;
+      return new c_base_return_true();
+    }
+
+    if (!is_null($name) && !is_string($name)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
       return c_base_return_error::s_false($error);
     }
 
-    $placeholder = $this->add_placeholder($set_schema);
+    $placeholder = $this->add_placeholder($name);
     if ($placeholder->has_error()) {
       return c_base_return_error::s_false($placeholder->get_error());
     }
diff --git a/common/database/traits/database_with_dictionary.php b/common/database/traits/database_with_dictionary.php
new file mode 100644 (file)
index 0000000..f4356dd
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * @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 DICTIONARY functionality.
+ */
+trait t_database_with_dictionary {
+  protected $with_dictionary;
+
+  /**
+   * Set the WITH DICTIONARY settings.
+   *
+   * @param string|null $name
+   *   The dictionary name.
+   *   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_dictionary($name) {
+    if (is_null($name)) {
+      $this->with_dictionary = NULL;
+      return new c_base_return_true();
+    }
+
+    if (!is_string($name)) {
+      $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT);
+      return c_base_return_error::s_false($error);
+    }
+
+    $placeholder = $this->add_placeholder($name);
+    if ($placeholder->has_error()) {
+      return c_base_return_error::s_false($placeholder->get_error());
+    }
+
+    $this->with_dictionary = $placeholder;
+    unset($placeholder);
+
+    return new c_base_return_true();
+  }
+
+  /**
+   * Get the currently assigned dictionary name to set to.
+   *
+   * @return i_database_query_placeholder|c_base_return_null
+   *   A dictionary name query placeholder on success.
+   *   NULL is returned if not set (set schema is not to be used).
+   *   NULL with the error bit set is returned on error.
+   */
+  public function get_with_dictionary() {
+    if (is_null($this->with_dictionary)) {
+      return new c_base_return_null();
+    }
+
+    if (isset($this->with_dictionary)) {
+      return clone($this->with_dictionary);
+    }
+
+    $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'with_dictionary', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE);
+    return c_base_return_error::s_null($error);
+  }
+
+  /**
+   * Perform the common build process for this trait.
+   *
+   * As an internal trait method, the caller is expected to perform any appropriate validation.
+   *
+   * @return string|null
+   *   A string is returned.
+   *   NULL is returned if there is nothing to process or there is an error.
+   */
+  protected function p_do_build_with_dictionary() {
+    return c_database_string::WITH_DICTIONARY . ' ' . $this->with_dictionary;
+  }
+}