Subversion Repositories oidplus

Rev

Rev 1211 | 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. abstract class OIDplusSqlSlangPlugin extends OIDplusPlugin {
  27.  
  28.         /**
  29.          * @return string
  30.          */
  31.         public abstract static function id(): string;
  32.  
  33.         /**
  34.          * @return bool
  35.          * @throws OIDplusConfigInitializationException
  36.          * @throws OIDplusException
  37.          */
  38.         public final function isActive(): bool {
  39.                 return $this->id() == OIDplus::db()->getSlang()->id();
  40.         }
  41.  
  42.         /**
  43.          * @return string
  44.          */
  45.         public abstract function sqlDate(): string;
  46.  
  47.         /**
  48.          * @param OIDplusDatabaseConnection $db
  49.          * @return bool
  50.          */
  51.         public abstract function detect(OIDplusDatabaseConnection $db): bool;
  52.  
  53.         /**
  54.          * Please note: This insert_id() function should use SQL to receive
  55.          * the last inserted ID. If the database connection provider (e.g. PDO)
  56.          * offers a way to fetch the last inserted ID, please use this instead!
  57.          * So, please do NOT use  OIDplus::db()->getSlang()->insert_id()
  58.          * but instead use        OIDplus::db()->insert_id()
  59.          * This way, the database connection provider can override that function
  60.          * with their own method of fetching the last inserted ID.
  61.          * @param OIDplusDatabaseConnection $db
  62.          * @return int 0 on failure.
  63.          */
  64.         public abstract function insert_id(OIDplusDatabaseConnection $db): int;
  65.  
  66.         /**
  67.          * @param string $cont
  68.          * @param string $table
  69.          * @param string $prefix
  70.          * @return string
  71.          */
  72.         public abstract function setupSetTablePrefix(string $cont, string $table, string $prefix): string;
  73.  
  74.         /**
  75.          * @param string $database
  76.          * @return string
  77.          */
  78.         public abstract function setupCreateDbIfNotExists(string $database): string;
  79.  
  80.         /**
  81.          * @param string $database
  82.          * @return string
  83.          */
  84.         public abstract function setupUseDatabase(string $database): string;
  85.  
  86.         /**
  87.          * @param string $sql
  88.          * @return string
  89.          */
  90.         public abstract function filterQuery(string $sql): string;
  91.  
  92.         /**
  93.          * @param bool $bool
  94.          * @return string
  95.          */
  96.         public abstract function getSQLBool(bool $bool): string;
  97.  
  98.         /**
  99.          * @param string $str
  100.          * @return string
  101.          */
  102.         public abstract function escapeString(string $str): string;
  103.  
  104.         /**
  105.          * @param string $expr1
  106.          * @param string $expr2
  107.          * @return string
  108.          */
  109.         public abstract function isNullFunction(string $expr1, string $expr2): string;
  110.  
  111.         /**
  112.          * This gives the SQL slang plugin the chance to review the result before it is passed to the application.
  113.          * @param OIDplusQueryResult $res
  114.          * @param string $sql
  115.          * @param array|null $prepared_args
  116.          * @return void
  117.          */
  118.         public function reviewResult(OIDplusQueryResult $res, string $sql, array $prepared_args=null) {
  119.                 // nothing here. Override it is you need it.
  120.         }
  121.  
  122.         /**
  123.          * @param string $sql
  124.          * @return bool
  125.          */
  126.         public function fetchableRowsExpected(string $sql): bool {
  127.                 return str_starts_with(trim(strtolower($sql)),'select');
  128.         }
  129.  
  130. }
  131.