Merge pull request #3721 from owncloud/oracle_setup_fixes

Oracle setup fixes
This commit is contained in:
Thomas Müller 2013-06-14 11:21:02 -07:00
commit 0ac7c5712a
5 changed files with 47 additions and 26 deletions

View File

@ -88,9 +88,8 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
} }
$query.=')'; $query.=')';
$stmt = OC_DB::prepare( $query ); $result = OC_DB::executeAudited( $query, $params );
$result = $stmt->execute( $params );
$lockList = array(); $lockList = array();
while( $row = $result->fetchRow()) { while( $row = $result->fetchRow()) {
@ -127,14 +126,17 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
$locks = $this->getLocks($uri, false); $locks = $this->getLocks($uri, false);
$exists = false; $exists = false;
foreach($locks as $lock) { foreach($locks as $lock) {
if ($lock->token == $lockInfo->token) $exists = true; if ($lock->token == $lockInfo->token) {
$exists = true;
break;
}
} }
if ($exists) { if ($exists) {
$query = OC_DB::prepare( 'UPDATE `*PREFIX*locks`' $sql = 'UPDATE `*PREFIX*locks`'
.' SET `owner` = ?, `timeout` = ?, `scope` = ?, `depth` = ?, `uri` = ?, `created` = ?' .' SET `owner` = ?, `timeout` = ?, `scope` = ?, `depth` = ?, `uri` = ?, `created` = ?'
.' WHERE `userid` = ? AND `token` = ?' ); .' WHERE `userid` = ? AND `token` = ?';
$result = $query->execute( array( $result = OC_DB::executeAudited( $sql, array(
$lockInfo->owner, $lockInfo->owner,
$lockInfo->timeout, $lockInfo->timeout,
$lockInfo->scope, $lockInfo->scope,
@ -145,10 +147,10 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
$lockInfo->token) $lockInfo->token)
); );
} else { } else {
$query = OC_DB::prepare( 'INSERT INTO `*PREFIX*locks`' $sql = 'INSERT INTO `*PREFIX*locks`'
.' (`userid`,`owner`,`timeout`,`scope`,`depth`,`uri`,`created`,`token`)' .' (`userid`,`owner`,`timeout`,`scope`,`depth`,`uri`,`created`,`token`)'
.' VALUES (?,?,?,?,?,?,?,?)' ); .' VALUES (?,?,?,?,?,?,?,?)';
$result = $query->execute( array( $result = OC_DB::executeAudited( $sql, array(
OC_User::getUser(), OC_User::getUser(),
$lockInfo->owner, $lockInfo->owner,
$lockInfo->timeout, $lockInfo->timeout,
@ -173,8 +175,8 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
*/ */
public function unlock($uri, Sabre_DAV_Locks_LockInfo $lockInfo) { public function unlock($uri, Sabre_DAV_Locks_LockInfo $lockInfo) {
$query = OC_DB::prepare( 'DELETE FROM `*PREFIX*locks` WHERE `userid` = ? AND `uri` = ? AND `token` = ?' ); $sql = 'DELETE FROM `*PREFIX*locks` WHERE `userid` = ? AND `uri` = ? AND `token` = ?';
$result = $query->execute( array(OC_User::getUser(), $uri, $lockInfo->token)); $result = OC_DB::executeAudited( $sql, array(OC_User::getUser(), $uri, $lockInfo->token));
return $result->numRows() === 1; return $result->numRows() === 1;

View File

@ -460,7 +460,7 @@ class OC_DB {
$row = $result->fetchRow(); $row = $result->fetchRow();
self::raiseExceptionOnError($row, 'fetching row for insertid failed'); self::raiseExceptionOnError($row, 'fetching row for insertid failed');
return $row['id']; return $row['id'];
} else if( $type === 'mssql') { } else if( $type === 'mssql' || $type === 'oci') {
if($table !== null) { if($table !== null) {
$prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); $prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
$table = str_replace( '*PREFIX*', $prefix, $table ); $table = str_replace( '*PREFIX*', $prefix, $table );
@ -594,6 +594,11 @@ class OC_DB {
$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
self::connectScheme(); 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 // read file
$content = file_get_contents( $file ); $content = file_get_contents( $file );
@ -617,6 +622,12 @@ class OC_DB {
$content = str_replace( '<default>0000-00-00 00:00:00</default>', $content = str_replace( '<default>0000-00-00 00:00:00</default>',
'<default>CURRENT_TIMESTAMP</default>', $content ); '<default>CURRENT_TIMESTAMP</default>', $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 ); file_put_contents( $file2, $content );
$op = self::$schema->updateDatabase($file2, $previousSchema, array(), false); $op = self::$schema->updateDatabase($file2, $previousSchema, array(), false);

View File

@ -1586,10 +1586,10 @@ class Share {
public static function post_removeFromGroup($arguments) { public static function post_removeFromGroup($arguments) {
// TODO Don't call if user deleted? // TODO Don't call if user deleted?
$query = \OC_DB::prepare('SELECT `id`, `share_type` FROM `*PREFIX*share`' $sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`'
.' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)'); .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)';
$result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'], self::$shareTypeGroupUserUnique, $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'],
$arguments['uid'])); self::$shareTypeGroupUserUnique, $arguments['uid']));
while ($item = $result->fetchRow()) { while ($item = $result->fetchRow()) {
if ($item['share_type'] == self::SHARE_TYPE_GROUP) { if ($item['share_type'] == self::SHARE_TYPE_GROUP) {
// Delete all reshares by this user of the group share // Delete all reshares by this user of the group share
@ -1601,8 +1601,8 @@ class Share {
} }
public static function post_deleteGroup($arguments) { public static function post_deleteGroup($arguments) {
$query = \OC_DB::prepare('SELECT id FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'); $sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?';
$result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'])); $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid']));
while ($item = $result->fetchRow()) { while ($item = $result->fetchRow()) {
self::delete($item['id']); self::delete($item['id']);
} }

View File

@ -4,7 +4,7 @@ class DatabaseSetupException extends Exception
{ {
private $hint; 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; $this->hint = $hint;
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }
@ -133,12 +133,15 @@ class OC_Setup {
$dbuser = $options['dbuser']; $dbuser = $options['dbuser'];
$dbpass = $options['dbpass']; $dbpass = $options['dbpass'];
$dbname = $options['dbname']; $dbname = $options['dbname'];
$dbtablespace = $options['dbtablespace']; if (array_key_exists('dbtablespace', $options)) {
$dbtablespace = $options['dbtablespace'];
} else {
$dbtablespace = 'USERS';
}
$dbhost = isset($options['dbhost'])?$options['dbhost']:''; $dbhost = isset($options['dbhost'])?$options['dbhost']:'';
$dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_';
OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbname', $dbname);
OC_Config::setValue('dbtablespace', $dbtablespace);
OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbhost', $dbhost);
OC_Config::setValue('dbtableprefix', $dbtableprefix); OC_Config::setValue('dbtableprefix', $dbtableprefix);
@ -446,7 +449,7 @@ class OC_Setup {
} }
private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace,
$username) { $username) {
$l = self::getTrans(); $l = self::getTrans();
$e_host = addslashes($dbhost); $e_host = addslashes($dbhost);
$e_dbname = addslashes($dbname); $e_dbname = addslashes($dbname);

View File

@ -94,13 +94,18 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase {
break; break;
case 'pgsql': case 'pgsql':
$sql = "SELECT tablename AS table_name, schemaname AS schema_name " $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 schemaname != 'information_schema' "
. "AND tablename = '".$table."'"; . "AND tablename = '".$table."'";
$query = OC_DB::prepare($sql); $query = OC_DB::prepare($sql);
$result = $query->execute(array()); $result = $query->execute(array());
$exists = $result && $result->fetchOne(); $exists = $result && $result->fetchOne();
break; 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': case 'mssql':
$sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'";
$query = OC_DB::prepare($sql); $query = OC_DB::prepare($sql);