Subversion Repositories oidplus

Rev

Rev 1239 | Go to most recent revision | 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusSqlSlangPluginFirebird extends OIDplusSqlSlangPlugin {
  27.  
  28.         /**
  29.          * @return string
  30.          */
  31.         public static function id(): string {
  32.                 return 'firebird';
  33.         }
  34.  
  35.         /**
  36.          * @return string
  37.          */
  38.         public function sqlDate(): string {
  39.                 return 'current_timestamp';
  40.         }
  41.  
  42.         /**
  43.          * @param OIDplusDatabaseConnection $db
  44.          * @return bool
  45.          */
  46.         public function detect(OIDplusDatabaseConnection $db): bool {
  47.                 try {
  48.                         return $db->query('select * from rdb$character_sets;')->num_rows() > 0;
  49.                 } catch (\Exception $e) {
  50.                         return false;
  51.                 }
  52.         }
  53.  
  54.         /**
  55.          * @param OIDplusDatabaseConnection $db
  56.          * @return int
  57.          * @throws OIDplusException
  58.          */
  59.         public function insert_id(OIDplusDatabaseConnection $db): int {
  60.  
  61.                 // TODO: IMPLEMENT FOR FIREBIRD!
  62.                 return 0;
  63.  
  64.         }
  65.  
  66.         /**
  67.          * @param string $cont
  68.          * @param string $table
  69.          * @param string $prefix
  70.          * @return string
  71.          */
  72.         public function setupSetTablePrefix(string $cont, string $table, string $prefix): string {
  73.                 $table = strtoupper($table);
  74.                 $prefix = strtoupper($prefix);
  75.                 return str_replace('"'.$table.'"', '"'.$prefix.$table.'"', $cont);
  76.         }
  77.  
  78.         /**
  79.          * @param string $database
  80.          * @return string
  81.          */
  82.         public function setupCreateDbIfNotExists(string $database): string {
  83.                 // TODO! Implement
  84.                 return "";
  85.         }
  86.  
  87.         /**
  88.          * @param string $database
  89.          * @return string
  90.          */
  91.         public function setupUseDatabase(string $database): string {
  92.                 // TODO! Implement
  93.                 return "";
  94.         }
  95.  
  96.         /**
  97.          * @param string $expr1
  98.          * @param string $expr2
  99.          * @return string
  100.          */
  101.         public function isNullFunction(string $expr1, string $expr2): string {
  102.                 return "COALESCE($expr1, $expr2)";
  103.         }
  104.  
  105.         /**
  106.          * @param string $sql
  107.          * @return string
  108.          */
  109.         public function filterQuery(string $sql): string {
  110.                 // "select 1" is not valid. You need to add "from RDB$DATABASE"
  111.                 if ((stripos($sql,'select') !== false) && (stripos($sql,'from') === false)) {
  112.                         $sql .= ' from RDB$DATABASE';
  113.                 }
  114.  
  115.                 //Value is a keyword and cannot be used as column name
  116.                 $sql = str_ireplace('value', '"VALUE"', $sql);
  117.                 $sql = str_ireplace('"VALUE"s', 'values', $sql);
  118.                 return $sql;
  119.         }
  120.  
  121.         /**
  122.          * @param bool $bool
  123.          * @return string
  124.          */
  125.         public function getSQLBool(bool $bool): string {
  126.                 return $bool ? '1' : '0';
  127.         }
  128.  
  129.         /**
  130.          * @param string $str
  131.          * @return string
  132.          */
  133.         public function escapeString(string $str): string {
  134.                 return str_replace("'", "''", $str);
  135.         }
  136. }
  137.