From 1b68c0c0cdf1fb68149efd18e661be0a38bcfd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 8 May 2013 15:30:04 +0200 Subject: [PATCH 1/4] allow install when only oracle is available --- lib/util.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/util.php b/lib/util.php index 48c224a303..01e2df7bfc 100755 --- a/lib/util.php +++ b/lib/util.php @@ -173,7 +173,8 @@ class OC_Util { //check for database drivers if(!(is_callable('sqlite_open') or class_exists('SQLite3')) and !is_callable('mysql_connect') - and !is_callable('pg_connect')) { + and !is_callable('pg_connect') + and !is_callable('oci_connect')) { $errors[]=array('error'=>'No database drivers (sqlite, mysql, or postgresql) installed.', 'hint'=>'');//TODO: sane hint $web_server_restart= true; From eceb3c8ed5f3068808bc8fc5ceec5fda1ac50db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 29 Apr 2013 12:25:27 +0200 Subject: [PATCH 2/4] add debug output --- lib/app.php | 5 ++++- lib/db.php | 9 ++------- lib/files/cache/cache.php | 15 ++++++++++++--- lib/setup.php | 12 ++++++++++-- lib/user.php | 2 +- lib/user/database.php | 2 +- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/app.php b/lib/app.php index 55b4543ec9..0a7069ca60 100644 --- a/lib/app.php +++ b/lib/app.php @@ -173,8 +173,11 @@ class OC_App{ } $apps=array('files'); $query = OC_DB::prepare( 'SELECT `appid` FROM `*PREFIX*appconfig`' - .' WHERE `configkey` = \'enabled\' AND `configvalue`=\'yes\'' ); + .' WHERE `configkey` = \'enabled\' AND to_char(`configvalue`)=\'yes\'' ); $result=$query->execute(); + if( \OC_DB::isError($result)) { + throw new DatabaseException($result->getMessage(), $query); + } while($row=$result->fetchRow()) { if(array_search($row['appid'], $apps)===false) { $apps[]=$row['appid']; diff --git a/lib/db.php b/lib/db.php index 8f6f50bda6..5b45f81f99 100644 --- a/lib/db.php +++ b/lib/db.php @@ -276,15 +276,10 @@ class OC_DB { 'phptype' => 'oci8', 'username' => $user, 'password' => $pass, + 'service' => $name, + 'hostspec' => $host, 'charset' => 'AL32UTF8', ); - if ($host != '') { - $dsn['hostspec'] = $host; - $dsn['database'] = $name; - } else { // use dbname for hostspec - $dsn['hostspec'] = $name; - $dsn['database'] = $user; - } break; case 'mssql': $dsn = array( diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 0617471079..adffe766dd 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -145,8 +145,11 @@ class Cache { if ($fileId > -1) { $query = \OC_DB::prepare( 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, `encrypted`, `etag` - FROM `*PREFIX*filecache` WHERE parent = ? ORDER BY `name` ASC'); + FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC'); $result = $query->execute(array($fileId)); + if (\OC_DB::isError($result)) { + \OCP\Util::writeLog('cache', 'getFolderContents failed: '.$result->getMessage(), \OCP\Util::ERROR); + } $files = $result->fetchAll(); foreach ($files as &$file) { $file['mimetype'] = $this->getMimetype($file['mimetype']); @@ -201,7 +204,7 @@ class Cache { . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')'); $result = $query->execute($params); if (\OC_DB::isError($result)) { - \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result, \OCP\Util::ERROR); + \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result->getMessage(), \OCP\Util::ERROR); } return (int)\OC_DB::insertid('*PREFIX*filecache'); @@ -372,6 +375,9 @@ class Cache { $pathHash = md5($file); $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); $result = $query->execute(array($this->getNumericStorageId(), $pathHash)); + if( \OC_DB::isError($result)) { + \OCP\Util::writeLog('cache', 'get status failed: '.$result->getMessage(), \OCP\Util::ERROR); + } if ($row = $result->fetchRow()) { if ((int)$row['size'] === -1) { return self::SHALLOW; @@ -509,8 +515,11 @@ class Cache { */ public function getIncomplete() { $query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`' - . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1'); + . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC',1); $result = $query->execute(array($this->getNumericStorageId())); + if (\OC_DB::isError($result)) { + \OCP\Util::writeLog('cache', 'getIncomplete failed: '.$result->getMessage(), \OCP\Util::ERROR); + } if ($row = $result->fetchRow()) { return $row['path']; } else { diff --git a/lib/setup.php b/lib/setup.php index f1ac6b8b2b..6f608ec5fb 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -152,8 +152,12 @@ class OC_Setup { self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username); } catch (Exception $e) { $error[] = array( - 'error' => $l->t('Oracle username and/or password not valid'), - 'hint' => $l->t('You need to enter either an existing account or the administrator.') + 'error' => $l->t('Oracle connection could not be established'), + 'hint' => $e->getMessage().' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') + .' ORACLE_SID='.getenv('ORACLE_SID') + .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') + .' NLS_LANG='.getenv('NLS_LANG') + .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable' ); return $error; } @@ -452,9 +456,13 @@ class OC_Setup { } else { $easy_connect_string = '//'.$e_host.'/'.$e_dbname; } + \OC_Log::write('setup oracle', 'connect string: '.$easy_connect_string, \OC_Log::DEBUG); $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string); if(!$connection) { $e = oci_error(); + if (is_array ($e) && isset ($e['message'])) { + throw new Exception($e['message']); + } throw new Exception($l->t('Oracle username and/or password not valid')); } //check for roles creation rights in oracle diff --git a/lib/user.php b/lib/user.php index b607874afa..78f5edfb5f 100644 --- a/lib/user.php +++ b/lib/user.php @@ -609,7 +609,7 @@ class OC_User { */ public static function isEnabled($userid) { $sql = 'SELECT `userid` FROM `*PREFIX*preferences`' - .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?'; + .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND to_char(`configvalue`) = ?'; $stmt = OC_DB::prepare($sql); if ( ! OC_DB::isError($stmt) ) { $result = $stmt->execute(array($userid, 'core', 'enabled', 'false')); diff --git a/lib/user/database.php b/lib/user/database.php index 63c64ed43d..d70b620f2a 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -136,7 +136,7 @@ class OC_User_Database extends OC_User_Backend { */ public function getDisplayName($uid) { if( $this->userExists($uid) ) { - $query = OC_DB::prepare( 'SELECT displayname FROM `*PREFIX*users` WHERE `uid` = ?' ); + $query = OC_DB::prepare( 'SELECT `displayname` FROM `*PREFIX*users` WHERE `uid` = ?' ); $result = $query->execute( array( $uid ))->fetchAll(); $displayName = trim($result[0]['displayname'], ' '); if ( !empty($displayName) ) { From cbd5eb9a1a77a5bcbcb843be21e95bccec26dedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 8 May 2013 16:18:24 +0200 Subject: [PATCH 3/4] use to_char only for oracle, whitespace --- lib/app.php | 9 +++++++-- lib/db.php | 12 ++++++------ lib/user.php | 6 +++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/app.php b/lib/app.php index 0a7069ca60..c6f6e92e60 100644 --- a/lib/app.php +++ b/lib/app.php @@ -172,8 +172,13 @@ class OC_App{ return array(); } $apps=array('files'); - $query = OC_DB::prepare( 'SELECT `appid` FROM `*PREFIX*appconfig`' - .' WHERE `configkey` = \'enabled\' AND to_char(`configvalue`)=\'yes\'' ); + $sql = 'SELECT `appid` FROM `*PREFIX*appconfig`' + .' WHERE `configkey` = \'enabled\' AND `configvalue`=\'yes\''; + if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') { //FIXME oracle hack + $sql = 'SELECT `appid` FROM `*PREFIX*appconfig`' + .' WHERE `configkey` = \'enabled\' AND to_char(`configvalue`)=\'yes\''; + } + $query = OC_DB::prepare( $sql ); $result=$query->execute(); if( \OC_DB::isError($result)) { throw new DatabaseException($result->getMessage(), $query); diff --git a/lib/db.php b/lib/db.php index 5b45f81f99..6183655183 100644 --- a/lib/db.php +++ b/lib/db.php @@ -273,12 +273,12 @@ class OC_DB { break; case 'oci': $dsn = array( - 'phptype' => 'oci8', - 'username' => $user, - 'password' => $pass, - 'service' => $name, - 'hostspec' => $host, - 'charset' => 'AL32UTF8', + 'phptype' => 'oci8', + 'username' => $user, + 'password' => $pass, + 'service' => $name, + 'hostspec' => $host, + 'charset' => 'AL32UTF8', ); break; case 'mssql': diff --git a/lib/user.php b/lib/user.php index 78f5edfb5f..32b91c35ef 100644 --- a/lib/user.php +++ b/lib/user.php @@ -609,7 +609,11 @@ class OC_User { */ public static function isEnabled($userid) { $sql = 'SELECT `userid` FROM `*PREFIX*preferences`' - .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND to_char(`configvalue`) = ?'; + .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?'; + if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') { //FIXME oracle hack + $sql = 'SELECT `userid` FROM `*PREFIX*preferences`' + .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND to_char(`configvalue`) = ?'; + } $stmt = OC_DB::prepare($sql); if ( ! OC_DB::isError($stmt) ) { $result = $stmt->execute(array($userid, 'core', 'enabled', 'false')); From 1f1abe595d413883f060f5f2983bac654e0ec7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 8 May 2013 16:29:15 +0200 Subject: [PATCH 4/4] cleanup codestyle --- lib/files/cache/cache.php | 6 +++--- lib/setup.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index adffe766dd..3341fe5052 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -148,7 +148,7 @@ class Cache { FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC'); $result = $query->execute(array($fileId)); if (\OC_DB::isError($result)) { - \OCP\Util::writeLog('cache', 'getFolderContents failed: '.$result->getMessage(), \OCP\Util::ERROR); + \OCP\Util::writeLog('cache', 'getFolderContents failed: ' . $result->getMessage(), \OCP\Util::ERROR); } $files = $result->fetchAll(); foreach ($files as &$file) { @@ -376,7 +376,7 @@ class Cache { $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); $result = $query->execute(array($this->getNumericStorageId(), $pathHash)); if( \OC_DB::isError($result)) { - \OCP\Util::writeLog('cache', 'get status failed: '.$result->getMessage(), \OCP\Util::ERROR); + \OCP\Util::writeLog('cache', 'get status failed: ' . $result->getMessage(), \OCP\Util::ERROR); } if ($row = $result->fetchRow()) { if ((int)$row['size'] === -1) { @@ -518,7 +518,7 @@ class Cache { . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC',1); $result = $query->execute(array($this->getNumericStorageId())); if (\OC_DB::isError($result)) { - \OCP\Util::writeLog('cache', 'getIncomplete failed: '.$result->getMessage(), \OCP\Util::ERROR); + \OCP\Util::writeLog('cache', 'getIncomplete failed: ' . $result->getMessage(), \OCP\Util::ERROR); } if ($row = $result->fetchRow()) { return $row['path']; diff --git a/lib/setup.php b/lib/setup.php index 6f608ec5fb..a63cc664db 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -456,7 +456,7 @@ class OC_Setup { } else { $easy_connect_string = '//'.$e_host.'/'.$e_dbname; } - \OC_Log::write('setup oracle', 'connect string: '.$easy_connect_string, \OC_Log::DEBUG); + \OC_Log::write('setup oracle', 'connect string: ' . $easy_connect_string, \OC_Log::DEBUG); $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string); if(!$connection) { $e = oci_error();