Subversion Repositories oidplus

Rev

Rev 1231 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. use ViaThinkSoft\OIDplus\OIDplusDatabaseConnection;
  21.  
  22. /**
  23.  * This function will be called by OIDplusDatabaseConnection.class.php at method afterConnect().
  24.  * @param OIDplusDatabaseConnection $db is the OIDplusDatabaseConnection class
  25.  * @return int new version set
  26.  * @throws \ViaThinkSoft\OIDplus\OIDplusException
  27.  */
  28. function oidplus_dbupdate_1001(OIDplusDatabaseConnection $db): int {
  29.         if ($db->transaction_supported()) $db->transaction_begin();
  30.         try {
  31.                 // Change collation so that objects like FourCC can be case-sensitive
  32.                 if ($db->getSlang()->id() == 'mysql') {
  33.                         $db->query("ALTER TABLE ###asn1id     CHANGE `oid`    `oid`    varchar(255) NOT NULL     COLLATE utf8_bin;");
  34.                         $db->query("ALTER TABLE ###iri        CHANGE `oid`    `oid`    varchar(255) NOT NULL     COLLATE utf8_bin;");
  35.                         $db->query("ALTER TABLE ###objects    CHANGE `id`     `id`     varchar(255) NOT NULL     COLLATE utf8_bin;");
  36.                         $db->query("ALTER TABLE ###objects    CHANGE `parent` `parent` varchar(255) DEFAULT NULL COLLATE utf8_bin;");
  37.                         $db->query("ALTER TABLE ###log_object CHANGE `object` `object` varchar(255) NOT NULL     COLLATE utf8_bin;");
  38.                 } else if ($db->getSlang()->id() == 'mssql') {
  39.                         $db->query("ALTER TABLE ###asn1id     ALTER COLUMN [oid]    varchar(255) COLLATE German_PhoneBook_CS_AS NOT NULL;");
  40.                         $db->query("ALTER TABLE ###iri        ALTER COLUMN [oid]    varchar(255) COLLATE German_PhoneBook_CS_AS NOT NULL;");
  41.                         $db->query("ALTER TABLE ###objects    ALTER COLUMN [id]     varchar(255) COLLATE German_PhoneBook_CS_AS NOT NULL;");
  42.                         $db->query("ALTER TABLE ###objects    ALTER COLUMN [parent] varchar(255) COLLATE German_PhoneBook_CS_AS NULL    ;");
  43.                         $db->query("ALTER TABLE ###log_object ALTER COLUMN [object] varchar(255) COLLATE German_PhoneBook_CS_AS NOT NULL;");
  44.                 } else if ($db->getSlang()->id() == 'oracle') {
  45.                         // On the Oracle DeveloperDays 2019 VM, the default behavior is case-sensitive.
  46.                         // Let's hope that this is true for all OIDplus environments
  47.                         // DM 31.05.2022 : Reproduction on Ubuntu+PostgreSQL also successful. The default is case-sensitive, like we want.
  48.                 } else if ($db->getSlang()->id() == 'pgsql') {
  49.                         // It looks like PgSQL is case-sensitive by default
  50.                         // see https://stackoverflow.com/questions/18807276/how-to-make-my-postgresql-database-use-a-case-insensitive-collation
  51.                         // DM 31.05.2022 : Reproduction on Ubuntu+PostgreSQL successful. The default is case-sensitive, like we want.
  52.                 } else if ($db->getSlang()->id() == 'access') {
  53.                         // TODO: Implement
  54.                         // However, this is not important, because Access is not yet correctly implemented anyway
  55.                 } else if ($db->getSlang()->id() == 'sqlite') {
  56.                         // It looks like SQLite is case-sensitive by default
  57.                         // https://stackoverflow.com/questions/973541/how-to-set-sqlite3-to-be-case-insensitive-when-string-comparing
  58.                         // DM 05.06.2022 : Reproduction on Ubuntu successful. The default is case-sensitive, like we want.
  59.                 } else {
  60.                         // This should not happen
  61.                 }
  62.  
  63.                 $version = 1001;
  64.                 $db->query("UPDATE ###config SET value = ? WHERE name = 'database_version'", array("$version"));
  65.  
  66.                 if ($db->transaction_supported()) $db->transaction_commit();
  67.         } catch (\Exception $e) {
  68.                 if ($db->transaction_supported()) $db->transaction_rollback();
  69.                 throw new $e;
  70.         }
  71.  
  72.         return $version;
  73. }
  74.