1<?php
2/**
3 * @author Bart Visscher <bartv@thisnet.nl>
4 * @author Morris Jobke <hey@morrisjobke.de>
5 * @author Robin Appelman <icewind@owncloud.com>
6 * @author Thomas Müller <thomas.mueller@tmit.eu>
7 *
8 * @copyright Copyright (c) 2018, ownCloud GmbH
9 * @license AGPL-3.0
10 *
11 * This code is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License, version 3,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
19 *
20 * You should have received a copy of the GNU Affero General Public License, version 3,
21 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22 *
23 */
24
25namespace OC\DB;
26
27class AdapterOCI8 extends Adapter {
28	public function lastInsertId($table) {
29		if ($table === null) {
30			throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()');
31		}
32		if ($table !== null) {
33			$suffix = '_SEQ';
34			$table = '"' . $table . $suffix . '"';
35		}
36		return $this->conn->realLastInsertId($table);
37	}
38
39	public const UNIX_TIMESTAMP_REPLACEMENT = "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400";
40
41	public function fixupStatement($statement) {
42		$statement = \preg_replace('( LIKE \?)', '$0 ESCAPE \'\\\'', $statement);
43		$statement = \preg_replace('( LIKE :\w+)', '$0 ESCAPE \'\\\'', $statement);
44		$statement = \preg_replace('/`(\w+)` ILIKE \?/', "LOWER(`$1`) LIKE LOWER(?) ESCAPE '\\' -- \\'' \n", $statement);  // FIXME workaround for singletick matching with regexes in SQLParserUtils::getUnquotedStatementFragments
45		$statement = \preg_replace('/`(\w+)` ILIKE (:\w+)/', "LOWER(`$1`) LIKE LOWER(`$2`) ESCAPE '\\' -- \\'' \n", $statement);  // FIXME workaround for singletick matching with regexes in SQLParserUtils::getUnquotedStatementFragments
46		$statement = \str_replace('`', '"', $statement);
47		$statement = \str_ireplace('NOW()', 'CURRENT_TIMESTAMP', $statement);
48		$statement = \str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement);
49		return $statement;
50	}
51}
52