Rev 1086 | Rev 1130 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1086 | Rev 1116 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusSqlSlangPluginOracle extends OIDplusSqlSlangPlugin { |
26 | class OIDplusSqlSlangPluginOracle extends OIDplusSqlSlangPlugin { |
27 | 27 | ||
- | 28 | /** |
|
- | 29 | * @return string |
|
- | 30 | */ |
|
28 | public static function id(): string { |
31 | public static function id(): string { |
29 | return 'oracle'; |
32 | return 'oracle'; |
30 | } |
33 | } |
31 | 34 | ||
- | 35 | /** |
|
- | 36 | * @param string $fieldname |
|
- | 37 | * @param string $order |
|
- | 38 | * @return string |
|
- | 39 | * @throws OIDplusException |
|
- | 40 | */ |
|
32 | public function natOrder($fieldname, $order='asc'): string { |
41 | public function natOrder(string $fieldname, string $order='asc'): string { |
33 | 42 | ||
34 | $order = strtolower($order); |
43 | $order = strtolower($order); |
35 | if (($order != 'asc') && ($order != 'desc')) { |
44 | if (($order != 'asc') && ($order != 'desc')) { |
36 | throw new OIDplusException(_L('Invalid order "%1" (needs to be "asc" or "desc")',$order)); |
45 | throw new OIDplusException(_L('Invalid order "%1" (needs to be "asc" or "desc")',$order)); |
37 | } |
46 | } |
Line 58... | Line 67... | ||
58 | 67 | ||
59 | return implode(', ', $out); |
68 | return implode(', ', $out); |
60 | 69 | ||
61 | } |
70 | } |
62 | 71 | ||
- | 72 | /** |
|
- | 73 | * @return string |
|
- | 74 | */ |
|
63 | public function sqlDate(): string { |
75 | public function sqlDate(): string { |
64 | return 'SYSDATE'; |
76 | return 'SYSDATE'; |
65 | } |
77 | } |
66 | 78 | ||
- | 79 | /** |
|
- | 80 | * @param OIDplusDatabaseConnection $db |
|
- | 81 | * @return bool |
|
- | 82 | */ |
|
67 | public function detect(OIDplusDatabaseConnection $db): bool { |
83 | public function detect(OIDplusDatabaseConnection $db): bool { |
68 | try { |
84 | try { |
69 | $vers = $db->query("SELECT banner FROM v\$version WHERE banner LIKE 'Oracle%'")->fetch_object()->banner; |
85 | $vers = $db->query("SELECT banner FROM v\$version WHERE banner LIKE 'Oracle%'")->fetch_object()->banner; |
70 | $vers = strtolower($vers); |
86 | $vers = strtolower($vers); |
71 | return (strpos($vers, 'oracle') !== false); |
87 | return (strpos($vers, 'oracle') !== false); |
72 | } catch (\Exception $e) { |
88 | } catch (\Exception $e) { |
73 | return false; |
89 | return false; |
74 | } |
90 | } |
75 | } |
91 | } |
76 | 92 | ||
- | 93 | /** |
|
- | 94 | * @var ?string |
|
- | 95 | */ |
|
77 | private $last_insert_table = null; |
96 | private $last_insert_table = null; |
78 | 97 | ||
- | 98 | /** |
|
- | 99 | * @param OIDplusDatabaseConnection $db |
|
- | 100 | * @return int |
|
- | 101 | * @throws OIDplusException |
|
- | 102 | */ |
|
79 | public function insert_id(OIDplusDatabaseConnection $db): int { |
103 | public function insert_id(OIDplusDatabaseConnection $db): int { |
80 | if (!$this->last_insert_table) return 0; |
104 | if (!$this->last_insert_table) return 0; |
81 | $res = $db->query("select sequence_name from user_tab_identity_cols where table_name = '".strtoupper($this->last_insert_table)."'"); |
105 | $res = $db->query("select sequence_name from user_tab_identity_cols where table_name = '".strtoupper($this->last_insert_table)."'"); |
82 | $row = $res->fetch_array(); |
106 | $row = $res->fetch_array(); |
83 | 107 | ||
Line 85... | Line 109... | ||
85 | $res = $db->query("select ".$row['sequence_name'].".currval from dual"); |
109 | $res = $db->query("select ".$row['sequence_name'].".currval from dual"); |
86 | $row = $res->fetch_array(); |
110 | $row = $res->fetch_array(); |
87 | return (int)$row['CURRVAL']; |
111 | return (int)$row['CURRVAL']; |
88 | } |
112 | } |
89 | 113 | ||
- | 114 | /** |
|
- | 115 | * @param string $cont |
|
- | 116 | * @param string $table |
|
- | 117 | * @param string $prefix |
|
- | 118 | * @return string |
|
90 | 119 | */ |
|
91 | public function setupSetTablePrefix($cont, $table, $prefix): string { |
120 | public function setupSetTablePrefix(string $cont, string $table, string $prefix): string { |
92 | $table = strtoupper($table); |
121 | $table = strtoupper($table); |
93 | $prefix = strtoupper($prefix); |
122 | $prefix = strtoupper($prefix); |
94 | $cont = str_replace('"'.$table.'"', '"'.$prefix.$table.'"', $cont); |
123 | $cont = str_replace('"'.$table.'"', '"'.$prefix.$table.'"', $cont); |
95 | return $cont; |
124 | return $cont; |
96 | } |
125 | } |
97 | 126 | ||
- | 127 | /** |
|
- | 128 | * @param string $database |
|
- | 129 | * @return string |
|
- | 130 | */ |
|
98 | public function setupCreateDbIfNotExists($database): string { |
131 | public function setupCreateDbIfNotExists(string $database): string { |
99 | // TODO! Implement |
132 | // TODO! Implement |
100 | return ""; |
133 | return ""; |
101 | } |
134 | } |
102 | 135 | ||
- | 136 | /** |
|
- | 137 | * @param string $database |
|
- | 138 | * @return string |
|
- | 139 | */ |
|
103 | public function setupUseDatabase($database): string { |
140 | public function setupUseDatabase(string $database): string { |
104 | // TODO! Implement |
141 | // TODO! Implement |
105 | return ""; |
142 | return ""; |
106 | } |
143 | } |
107 | 144 | ||
- | 145 | /** |
|
- | 146 | * @param string $expr1 |
|
- | 147 | * @param string $expr2 |
|
- | 148 | * @return string |
|
- | 149 | */ |
|
108 | public function isNullFunction($expr1, $expr2): string { |
150 | public function isNullFunction(string $expr1, string $expr2): string { |
109 | // Test via "SELECT NVL(null, 'foo') FROM DUAL;" |
151 | // Test via "SELECT NVL(null, 'foo') FROM DUAL;" |
110 | return "NVL($expr1, $expr2)"; |
152 | return "NVL($expr1, $expr2)"; |
111 | } |
153 | } |
112 | 154 | ||
- | 155 | /** |
|
- | 156 | * @param string $sql |
|
- | 157 | * @return string |
|
- | 158 | */ |
|
113 | public function filterQuery($sql): string { |
159 | public function filterQuery(string $sql): string { |
114 | 160 | ||
115 | // "select 1" is not valid. You need to add "from dual" |
161 | // "select 1" is not valid. You need to add "from dual" |
116 | if ((stripos($sql,'select') !== false) && (stripos($sql,'from') === false)) { |
162 | if ((stripos($sql,'select') !== false) && (stripos($sql,'from') === false)) { |
117 | $sql .= ' from dual'; |
163 | $sql .= ' from dual'; |
118 | } |
164 | } |
Line 130... | Line 176... | ||
130 | } else { |
176 | } else { |
131 | $this->last_insert_table = null; |
177 | $this->last_insert_table = null; |
132 | } |
178 | } |
133 | 179 | ||
134 | // Comment is a keyword and cannot be used as column name |
180 | // Comment is a keyword and cannot be used as column name |
135 | $sql = str_ireplace('comment', '"COMMENT"', $sql); |
181 | return str_ireplace('comment', '"COMMENT"', $sql); |
136 | - | ||
137 | return $sql; |
- | |
138 | } |
182 | } |
139 | 183 | ||
- | 184 | /** |
|
- | 185 | * @param bool $bool |
|
- | 186 | * @return string |
|
- | 187 | */ |
|
140 | public function getSQLBool($bool): string { |
188 | public function getSQLBool(bool $bool): string { |
141 | return $bool ? '1' : '0'; |
189 | return $bool ? '1' : '0'; |
142 | } |
190 | } |
143 | 191 | ||
- | 192 | /** |
|
- | 193 | * @param string $str |
|
- | 194 | * @return string |
|
- | 195 | */ |
|
144 | public function escapeString($str): string { |
196 | public function escapeString(string $str): string { |
145 | return str_replace("'", "''", $str); |
197 | return str_replace("'", "''", $str); |
146 | } |
198 | } |
147 | } |
199 | } |