From dcdabac04d5b2498ec7d50cceedf81cc7487b3e7 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 14 Jun 2013 12:06:29 +0200 Subject: oracle does not need sequence suffix, manually set database name to allow fetching db schema, don't shutdown db - we are using utf8 to connect --- lib/db.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/db.php b/lib/db.php index cd96bcf9d31..a6b81aaba69 100644 --- a/lib/db.php +++ b/lib/db.php @@ -460,7 +460,7 @@ class OC_DB { $row = $result->fetchRow(); self::raiseExceptionOnError($row, 'fetching row for insertid failed'); return $row['id']; - } else if( $type === 'mssql') { + } else if( $type === 'mssql' || $type === 'oci') { if($table !== null) { $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); $table = str_replace( '*PREFIX*', $prefix, $table ); @@ -594,6 +594,11 @@ class OC_DB { $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); self::connectScheme(); + + if(OC_Config::getValue('dbtype', 'sqlite')==='oci') { + //set dbname, it is unset because oci uses 'service' to connect + self::$schema->db->database_name=self::$schema->db->dsn['username']; + } // read file $content = file_get_contents( $file ); @@ -617,6 +622,12 @@ class OC_DB { $content = str_replace( '0000-00-00 00:00:00', 'CURRENT_TIMESTAMP', $content ); } + if(OC_Config::getValue('dbtype', 'sqlite')==='oci') { + unset($previousSchema['charset']); //or MDB2 tries SHUTDOWN IMMEDIATE + $oldname = $previousSchema['name']; + $previousSchema['name']=OC_Config::getValue( "dbuser", $oldname ); + //TODO check identifiers are at most 30 chars long + } file_put_contents( $file2, $content ); $op = self::$schema->updateDatabase($file2, $previousSchema, array(), false); -- cgit v1.2.3 From e5d3cd59acf5e9d9c7480797f30668103c00d1cb Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 14 Jun 2013 12:09:49 +0200 Subject: use USERS tablespace whn none is given, only needed when we need to create a user, does not need to be stored in config --- lib/setup.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index 71a2d13937e..5a513bccae6 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -133,12 +133,15 @@ class OC_Setup { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; - $dbtablespace = $options['dbtablespace']; + if (array_key_exists('dbtablespace', $options)) { + $dbtablespace = $options['dbtablespace']; + } else { + $dbtablespace = 'USERS'; + } $dbhost = isset($options['dbhost'])?$options['dbhost']:''; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_Config::setValue('dbname', $dbname); - OC_Config::setValue('dbtablespace', $dbtablespace); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbtableprefix', $dbtableprefix); @@ -439,8 +442,8 @@ class OC_Setup { } } - private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, - $username) { + private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, + $dbtablespace = 'USERS', $username) { $l = self::getTrans(); $e_host = addslashes($dbhost); $e_dbname = addslashes($dbname); @@ -552,7 +555,7 @@ class OC_Setup { * @param String $tablespace * @param resource $connection */ - private static function oci_createDBUser($name, $password, $tablespace, $connection) { + private static function oci_createDBUser($name, $password, $tablespace = 'USERS', $connection) { $l = self::getTrans(); $query = "SELECT * FROM all_users WHERE USERNAME = :un"; $stmt = oci_parse($connection, $query); -- cgit v1.2.3 From fc309caf163ae390e81a4473ed35d98b17a79d0a Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 14 Jun 2013 12:12:32 +0200 Subject: fix oci dbschema test --- tests/lib/dbschema.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 6631c929cf2..59f203993ef 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -94,13 +94,18 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { break; case 'pgsql': $sql = "SELECT tablename AS table_name, schemaname AS schema_name " - . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " + . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " . "AND schemaname != 'information_schema' " . "AND tablename = '".$table."'"; $query = OC_DB::prepare($sql); $result = $query->execute(array()); $exists = $result && $result->fetchOne(); break; + case 'oci': + $sql = 'SELECT table_name FROM user_tables WHERE table_name = ?'; + $result = \OC_DB::executeAudited($sql, array($table)); + $exists = (bool)$result->fetchOne(); //oracle uses MDB2 and returns null + break; case 'mssql': $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; $query = OC_DB::prepare($sql); -- cgit v1.2.3 From 961a001af3bc69eec8770ddc00ace3553e5c6ee0 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 14 Jun 2013 12:18:20 +0200 Subject: add missing backticks, use executeAudited in post_deleteGroup and post_removeFromGroup --- lib/public/share.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index 6a26101a1ce..122ab3fa030 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1586,10 +1586,10 @@ class Share { public static function post_removeFromGroup($arguments) { // TODO Don't call if user deleted? - $query = \OC_DB::prepare('SELECT `id`, `share_type` FROM `*PREFIX*share`' - .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)'); - $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'], self::$shareTypeGroupUserUnique, - $arguments['uid'])); + $sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`' + .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)'; + $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'], + self::$shareTypeGroupUserUnique, $arguments['uid'])); while ($item = $result->fetchRow()) { if ($item['share_type'] == self::SHARE_TYPE_GROUP) { // Delete all reshares by this user of the group share @@ -1601,8 +1601,8 @@ class Share { } public static function post_deleteGroup($arguments) { - $query = \OC_DB::prepare('SELECT id FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'); - $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'])); + $sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'; + $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'])); while ($item = $result->fetchRow()) { self::delete($item['id']); } -- cgit v1.2.3 From 471b9c055a16b3f7b8100870e40fffe4d6b2d646 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 14 Jun 2013 12:23:44 +0200 Subject: use executeAudited in sabredav lock --- lib/connector/sabre/locks.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/connector/sabre/locks.php b/lib/connector/sabre/locks.php index 745523c7a5b..1364aae0103 100644 --- a/lib/connector/sabre/locks.php +++ b/lib/connector/sabre/locks.php @@ -88,9 +88,8 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { } $query.=')'; - $stmt = OC_DB::prepare( $query ); - $result = $stmt->execute( $params ); - + $result = OC_DB::executeAudited( $query, $params ); + $lockList = array(); while( $row = $result->fetchRow()) { @@ -131,10 +130,10 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { } if ($exists) { - $query = OC_DB::prepare( 'UPDATE `*PREFIX*locks`' - .' SET `owner` = ?, `timeout` = ?, `scope` = ?, `depth` = ?, `uri` = ?, `created` = ?' - .' WHERE `userid` = ? AND `token` = ?' ); - $result = $query->execute( array( + $sql = 'UPDATE `*PREFIX*locks`' + .' SET `owner` = ?, `timeout` = ?, `scope` = ?, `depth` = ?, `uri` = ?, `created` = ?' + .' WHERE `userid` = ? AND `token` = ?'; + $result = OC_DB::executeAudited( $sql, array( $lockInfo->owner, $lockInfo->timeout, $lockInfo->scope, @@ -145,10 +144,10 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { $lockInfo->token) ); } else { - $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*locks`' - .' (`userid`,`owner`,`timeout`,`scope`,`depth`,`uri`,`created`,`token`)' - .' VALUES (?,?,?,?,?,?,?,?)' ); - $result = $query->execute( array( + $sql = 'INSERT INTO `*PREFIX*locks`' + .' (`userid`,`owner`,`timeout`,`scope`,`depth`,`uri`,`created`,`token`)' + .' VALUES (?,?,?,?,?,?,?,?)'; + $result = OC_DB::executeAudited( $sql, array( OC_User::getUser(), $lockInfo->owner, $lockInfo->timeout, @@ -173,8 +172,8 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { */ public function unlock($uri, Sabre_DAV_Locks_LockInfo $lockInfo) { - $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*locks` WHERE `userid` = ? AND `uri` = ? AND `token` = ?' ); - $result = $query->execute( array(OC_User::getUser(), $uri, $lockInfo->token)); + $sql = 'DELETE FROM `*PREFIX*locks` WHERE `userid` = ? AND `uri` = ? AND `token` = ?'; + $result = OC_DB::executeAudited( $sql, array(OC_User::getUser(), $uri, $lockInfo->token)); return $result->numRows() === 1; -- cgit v1.2.3 From 5c7d7549ea8803596307882f2ee9214808c82451 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 14 Jun 2013 13:54:41 +0200 Subject: coding style --- lib/connector/sabre/locks.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/connector/sabre/locks.php b/lib/connector/sabre/locks.php index 1364aae0103..cbc495dec19 100644 --- a/lib/connector/sabre/locks.php +++ b/lib/connector/sabre/locks.php @@ -126,7 +126,10 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { $locks = $this->getLocks($uri, false); $exists = false; foreach($locks as $lock) { - if ($lock->token == $lockInfo->token) $exists = true; + if ($lock->token == $lockInfo->token) { + $exists = true; + break; + } } if ($exists) { -- cgit v1.2.3 From 1ef66941a795fbd29a7532480dbe2d2e361cb5c7 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 14 Jun 2013 15:38:09 +0200 Subject: adding default to $hint within ctor of DatabaseSetupException --- lib/setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/setup.php b/lib/setup.php index 5a513bccae6..738a99fb7cc 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -4,7 +4,7 @@ class DatabaseSetupException extends Exception { private $hint; - public function __construct($message, $hint, $code = 0, Exception $previous = null) { + public function __construct($message, $hint = '', $code = 0, Exception $previous = null) { $this->hint = $hint; parent::__construct($message, $code, $previous); } -- cgit v1.2.3 From 9498cf959f0110182ac682d1784a6594a9f27936 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 14 Jun 2013 15:54:45 +0200 Subject: remove default tablespace in parameter --- lib/setup.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index 738a99fb7cc..85fba83ec63 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -442,8 +442,8 @@ class OC_Setup { } } - private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, - $dbtablespace = 'USERS', $username) { + private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, + $username) { $l = self::getTrans(); $e_host = addslashes($dbhost); $e_dbname = addslashes($dbname); @@ -555,7 +555,7 @@ class OC_Setup { * @param String $tablespace * @param resource $connection */ - private static function oci_createDBUser($name, $password, $tablespace = 'USERS', $connection) { + private static function oci_createDBUser($name, $password, $tablespace, $connection) { $l = self::getTrans(); $query = "SELECT * FROM all_users WHERE USERNAME = :un"; $stmt = oci_parse($connection, $query); -- cgit v1.2.3