Subversion Repositories oidplus

Rev

Rev 1211 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
507 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
1086 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
507 daniel-mar 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
 
1116 daniel-mar 20
namespace ViaThinkSoft\OIDplus;
21
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
1116 daniel-mar 24
// phpcs:enable PSR1.Files.SideEffects
511 daniel-mar 25
 
507 daniel-mar 26
abstract class OIDplusSqlSlangPlugin extends OIDplusPlugin {
27
 
1116 daniel-mar 28
        /**
29
         * @return string
30
         */
507 daniel-mar 31
        public abstract static function id(): string;
32
 
1116 daniel-mar 33
        /**
1211 daniel-mar 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
        /**
1116 daniel-mar 43
         * @return string
44
         */
507 daniel-mar 45
        public abstract function sqlDate(): string;
46
 
1116 daniel-mar 47
        /**
48
         * @param OIDplusDatabaseConnection $db
49
         * @return bool
50
         */
507 daniel-mar 51
        public abstract function detect(OIDplusDatabaseConnection $db): bool;
52
 
1116 daniel-mar 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
         */
507 daniel-mar 64
        public abstract function insert_id(OIDplusDatabaseConnection $db): int;
65
 
1116 daniel-mar 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;
507 daniel-mar 73
 
1116 daniel-mar 74
        /**
75
         * @param string $database
76
         * @return string
77
         */
78
        public abstract function setupCreateDbIfNotExists(string $database): string;
507 daniel-mar 79
 
1116 daniel-mar 80
        /**
81
         * @param string $database
82
         * @return string
83
         */
84
        public abstract function setupUseDatabase(string $database): string;
507 daniel-mar 85
 
1116 daniel-mar 86
        /**
87
         * @param string $sql
88
         * @return string
89
         */
90
        public abstract function filterQuery(string $sql): string;
507 daniel-mar 91
 
1116 daniel-mar 92
        /**
93
         * @param bool $bool
94
         * @return string
95
         */
96
        public abstract function getSQLBool(bool $bool): string;
507 daniel-mar 97
 
1116 daniel-mar 98
        /**
99
         * @param string $str
100
         * @return string
101
         */
102
        public abstract function escapeString(string $str): string;
507 daniel-mar 103
 
1116 daniel-mar 104
        /**
105
         * @param string $expr1
106
         * @param string $expr2
107
         * @return string
108
         */
109
        public abstract function isNullFunction(string $expr1, string $expr2): string;
110
 
1240 daniel-mar 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
 
1116 daniel-mar 130
}